What the telemetry is for
OpenTelemetry is the vendor-neutral standard for traces, metrics and logs. The receivables platform emits one trace per work item, such as a payment, an invoice check or a dispute, and links the steps of a case by a case identifier, so an operator can answer three questions: is it fast and available, is it correct and safe, and what does it cost. Telemetry carries identifiers, outcomes and measurements. It never carries documents, bank details or names (ADR-006).
Traces
Spans for each step of an item, parent and child, from intake to the ERP (Enterprise Resource Planning). One trace identifier follows the item across services and the gateway.
Metrics
Counters and histograms for item latency, applied value, tokens, cost and guardrail blocks. Cheap to store and good for alerts.
Events
Business events with a name and properties: cash received, cash applied, routed to a person, dispute opened, guardrail block.
Correlation
The W3C trace context header travels from intake through the AI (artificial intelligence) gateway and tool gateway, so their logs join the same trace.
The shape of a trace
| Span | Kind | Key attributes |
|---|---|---|
| cash.item | Server (root) | case.id (hashed), stage, region, outcome |
| airs.scan.input, airs.scan.output, airs.scan.tool_args | Client | airs.profile, airs.action, airs.detections (names only) |
| gateway.llm_call | Client | gen_ai.request.model (alias), gen_ai.usage.input_tokens, gen_ai.usage.output_tokens, gateway.cost_usd, gateway.fallback_used |
| retrieval.search | Client | knowledge.index, filter.customer (hashed), results.count, top.score |
| match.score | Internal | candidates.count, top.score, threshold |
| policy.check | Internal | policy.rule, policy.decision |
| tool.call | Client | tool.name, tool.outcome, tool.basis, amount band (not exact amount for restricted cases) |
What must never be in telemetry
| Data | Rule | How |
|---|---|---|
| Remittance and email text | Never | Not an attribute. Debugging uses the masked cases table in the lakehouse |
| Bank account numbers and payer names | Never in clear | Dropped or hashed by the collector before export |
| Case and customer identifiers | Hashed | Keyed hash, so queries can group by case without exposing it |
| Blocked content | Never | Record the detection names and the verdict only |
| Amounts, scores and bases | Allowed | Needed for applied-value and automation analysis |
Instrumenting the service
A sketch in Python with the OpenTelemetry SDK (Software Development Kit) and the Azure Monitor distribution, which sends to Application Insights. The root span is a server span so it appears as a request; child spans appear as dependencies; business events are logged with a custom event name. Check the current package and attribute names before you build.
import logging, os
from opentelemetry import trace, metrics
from opentelemetry.trace import SpanKind
from azure.monitor.opentelemetry import configure_azure_monitor
configure_azure_monitor(connection_string=os.environ["APPLICATIONINSIGHTS_CONNECTION_STRING"])
tracer = trace.get_tracer("receivables.platform")
meter = metrics.get_meter("receivables.platform")
item_ms = meter.create_histogram("ar.item.duration", unit="ms")
blocks = meter.create_counter("ar.guardrail.blocks")
log = logging.getLogger("ar.events")
def process_payment(payment, region):
with tracer.start_as_current_span("cash.item", kind=SpanKind.SERVER) as item:
item.set_attributes({"case.id": hash_id(payment["payment_id"]), "stage": "cash-application", "region": region})
with tracer.start_as_current_span("airs.scan.input") as sp:
verdict = scan(prompt=payment["remittance_text"], case=payment["payment_id"], model="ar-fast")
sp.set_attributes({"airs.profile": "ar-documents-prod", "airs.action": verdict["action"]})
if verdict["action"] != "allow":
blocks.add(1, {"detection": detection_name(verdict), "stage": "input"})
log.warning("guardrail block", extra={"microsoft.custom_event.name": "guardrail.block",
"case.id": hash_id(payment["payment_id"]), "airs.detection": detection_name(verdict)})
return route_to_person(payment, reason="blocked")
with tracer.start_as_current_span("gateway.llm_call") as llm:
lines, usage = extract_remittance_lines(payment)
llm.set_attributes({"gen_ai.request.model": "ar-fast", "gen_ai.usage.input_tokens": usage.input,
"gen_ai.usage.output_tokens": usage.output, "gateway.cost_usd": usage.cost})
...
log.info("cash applied", extra={"microsoft.custom_event.name": "cash.applied", "case.id": hash_id(payment["payment_id"]),
"basis": decision.basis, "value_usd": decision.value})
item_ms.record(elapsed_ms(item), {"stage": "cash-application"})A collector in the middle
An OpenTelemetry Collector receives telemetry from the service and the gateway, removes or hashes sensitive attributes, keeps every error and every block, samples the rest, and sends it to Azure Monitor for operations and to the lakehouse for long-term analysis.
receivers:
otlp:
protocols: { grpc: {}, http: {} }
processors:
attributes/privacy:
actions:
- { key: remittance.text, action: delete }
- { key: bank.account, action: hash }
- { key: customer.email, action: delete }
tail_sampling:
decision_wait: 10s
policies:
- { name: keep-errors, type: status_code, status_code: { status_codes: [ERROR] } }
- { name: keep-blocks, type: string_attribute, string_attribute: { key: airs.action, values: [block] } }
- { name: sample-rest, type: probabilistic, probabilistic: { sampling_percentage: 10 } }
batch: {}
exporters:
azuremonitor:
connection_string: ${env:APPLICATIONINSIGHTS_CONNECTION_STRING}
otlphttp/lakehouse:
endpoint: ${env:LAKEHOUSE_OTLP_ENDPOINT}
service:
pipelines:
traces: { receivers: [otlp], processors: [attributes/privacy, tail_sampling, batch], exporters: [azuremonitor, otlphttp/lakehouse] }
metrics: { receivers: [otlp], processors: [batch], exporters: [azuremonitor] }
logs: { receivers: [otlp], processors: [attributes/privacy, batch], exporters: [azuremonitor, otlphttp/lakehouse] }KQL queries operators use
These queries use the workspace-based Application Insights tables in Log Analytics: AppRequests for the root span, AppDependencies for child spans, AppEvents for business events and AppMetrics for metrics. Custom attributes appear in the Properties column. Table and column names can differ with your setup, so adjust them to your workspace. The same Kusto Query Language also runs in Azure Data Explorer if you export telemetry there.
Item latency by stage
Median and 95th percentile processing time per stage, hourly, for the last day.
AppRequests
| where TimeGenerated > ago(1d) and Name == "cash.item"
| extend stage = tostring(Properties["stage"])
| summarize items = count(), p50 = percentile(DurationMs, 50), p95 = percentile(DurationMs, 95)
by stage, bin(TimeGenerated, 1h)
| order by TimeGenerated desc, stage ascWhere the time goes
Average and slowest duration for each step of a payment, to find the step to optimise.
AppDependencies
| where TimeGenerated > ago(1d)
| where Name in ("airs.scan.input", "gateway.llm_call", "retrieval.search", "match.score", "policy.check", "tool.call", "airs.scan.output")
| summarize calls = count(), avg_ms = avg(DurationMs), p95_ms = percentile(DurationMs, 95),
failures = countif(Success == false)
by Name
| order by p95_ms descValue applied without a person
Share of payment value applied by basis, by day. The headline measure of automation.
AppEvents
| where TimeGenerated > ago(14d) and Name == "cash.applied"
| extend basis = tostring(Properties["basis"]), value = todouble(Properties["value_usd"])
| summarize value_usd = sum(value) by basis, day = bin(TimeGenerated, 1d)
| evaluate pivot(basis, sum(value_usd))
| extend total = exact_rule + scored_above_threshold + approved_by_person
| extend auto_pct = round(100.0 * (exact_rule + scored_above_threshold) / total, 1)
| order by day descApplications without a valid basis (must be zero)
Finds any application whose basis is missing or not allowed. Any row is an incident.
AppEvents
| where Name == "cash.applied"
| extend basis = tostring(Properties["basis"])
| where isempty(basis) or basis !in ("exact_rule", "scored_above_threshold", "approved_by_person")
| project TimeGenerated, case = tostring(Properties["case.id"]), basis, OperationIdGuardrail blocks by detection
How often each Prisma AIRS detection fired, by hour, to spot an attack or a noisy rule.
AppEvents
| where TimeGenerated > ago(7d) and Name == "guardrail.block"
| extend detection = tostring(Properties["airs.detection"])
| summarize blocks = count(), cases = dcount(tostring(Properties["case.id"]))
by detection, bin(TimeGenerated, 1h)
| order by TimeGenerated desc, blocks descTokens and cost by model alias
Spend and token use per alias and per day, from gateway metadata.
AppDependencies
| where TimeGenerated > ago(14d) and Name == "gateway.llm_call"
| extend model = tostring(Properties["gen_ai.request.model"]),
tin = toint(Properties["gen_ai.usage.input_tokens"]),
tout = toint(Properties["gen_ai.usage.output_tokens"]),
cost = todouble(Properties["gateway.cost_usd"])
| summarize calls = count(), input_tokens = sum(tin), output_tokens = sum(tout), cost_usd = round(sum(cost), 2)
by model, day = bin(TimeGenerated, 1d)
| order by day desc, cost_usd descUnapplied cash by age
How much cash is waiting and for how long, to catch items stuck in review.
AppEvents
| where Name in ("cash.received", "cash.applied")
| extend payment = tostring(Properties["case.id"]), value = todouble(Properties["value_usd"])
| summarize received = minif(TimeGenerated, Name == "cash.received"), applied = maxif(TimeGenerated, Name == "cash.applied"),
value_usd = maxif(value, Name == "cash.received") by payment
| where isnull(applied)
| extend age_days = datetime_diff("day", now(), received)
| summarize payments = count(), value_usd = sum(value_usd) by age_bucket = case(age_days < 1, "under 1 day", age_days < 3, "1 to 3 days", "over 3 days")Why items go to a person or become disputes
Reasons ranked with a daily trend, to decide what to automate or fix at the source.
AppEvents
| where TimeGenerated > ago(30d) and Name in ("review.routed", "dispute.opened")
| extend reason = tostring(Properties["reason"])
| summarize items = count() by reason, bin(TimeGenerated, 1d)
| summarize total = sum(items), per_day = make_list(items) by reason
| order by total descTool errors and slow tools
Failure rate and slowest calls for each tool, to find a failing backend.
AppDependencies
| where TimeGenerated > ago(1d) and Name == "tool.call"
| extend tool = tostring(Properties["tool.name"]), outcome = tostring(Properties["tool.outcome"])
| summarize calls = count(), failed = countif(Success == false or outcome == "error"), p95_ms = percentile(DurationMs, 95)
by tool
| extend failure_pct = round(100.0 * failed / calls, 2)
| order by failure_pct desc, p95_ms descAlert: block rate spike
Compares the hourly block rate with its normal pattern and returns hours that are anomalously high. Use it as an alert query.
let items = AppRequests | where Name == "cash.item"
| make-series items = count() default = 0 on TimeGenerated from ago(14d) to now() step 1h;
let blocked = AppEvents | where Name == "guardrail.block"
| make-series blocked = count() default = 0 on TimeGenerated from ago(14d) to now() step 1h;
items
| join kind=inner (blocked) on $left.TimeGenerated == $right.TimeGenerated
| project TimeGenerated, rate = series_divide(blocked, items)
| extend (flag, score, baseline) = series_decompose_anomalies(rate, 2.5)
| mv-expand TimeGenerated to typeof(datetime), rate to typeof(double), flag to typeof(int), score to typeof(double)
| where flag == 1 and TimeGenerated > ago(3h)Service-level objectives and alerts
| Objective | Signal | Target | Alert |
|---|---|---|---|
| Fast processing | cash.item p95 | Under 60 seconds | p95 over target for 15 minutes |
| Available | Share of items not ending in error | At least 99.5% | Below target for 10 minutes |
| Safe postings | Applications without a valid basis | Zero | Any occurrence, page the on-call |
| Scans on all traffic | Model calls with a scan span | 100% | Any unscanned model call |
| Attacks visible | Block rate versus baseline | Within normal range | Anomaly flagged for 1 hour |
| Cash not stuck | Unapplied cash older than 3 days | Under 1% of cash | Over target for a day |
| Cost under control | Cost per payment, daily | Within budget | Over 120% of the 7-day average |
Dashboards
Operations
Item latency and errors by stage, step breakdown, tool health and gateway fallbacks.
Security
Blocks by detection, anomalies, repeat sources, scan coverage and applications without a basis.
Finance
Applied value by basis, unapplied cash by age, dispute reasons and days sales outstanding.
Cost
Tokens and cost by model and stage, cost per payment, invoice and dispute, and budget burn.
Build this for your business
This example is a receivables platform for a distributor, but the same pattern, deterministic financial rules, a governed gateway, runtime security, grounded evidence and measured quality, fits any back-office process that moves money. We can scope a pilot on your own systems.
Book a discovery call