AI

AgentOps: validate trace sampling before losing incident evidence

A production runbook for qualifying AI agent trace sampling, preserving critical action chains, and controlling telemetry volume without making incidents invisible.

11 Oct 2026 azureaiagentopsagentsmicrosoft-foundryapplication-insightsopentelemetryobservabilitysamplingkqlguardrailsrunbookrollbackproduction

After an Application Insights volume increase, a team lowers the sampling rate for its operations agent. Dashboards stay green and cost returns within budget. During the next incident, however, the trace that connected a policy denial, a tool call, and an expired approval cannot be found.

The problem is not only a rate set too low. A decision can be made in the SDK, propagated differently across services, then combined with collector filtering or ingestion sampling. A retained trace can also lose its related logs. Raising volume arbitrarily therefore does not prove that the action chain is operable again.

The running case is a Microsoft Foundry agent that reads runbooks, queries Azure state, and prepares bounded actions. This runbook ends with an explicit decision: promote the new sampling policy, keep it in canary, or restore the previous configuration while retaining an independent audit record.

Freeze evidence loss, not only a cost spike

Keep a UTC window before and after the change. Record the agent release, instrumentation version, sampling configuration, collectors, exporters, ingestion rules, and destinations. Add one known execution identifier that should have produced a complete trace.

yaml trace-sampling-incident.yml
window:
start_utc: 2026-10-11T05:30:00Z
end_utc: 2026-10-11T07:00:00Z

release:
agent: ops-agent-2026-10-11.2
instrumentation: otel-bundle-14
sampling_policy: rate-limited-v3

missing_evidence:
logical_run_id: run-7f2a
expected_spans: [agent.invoke, policy.evaluate, tool.call, approval.check]
observed_spans: [agent.invoke]
production_write: false

containment:
write_tools: read_only
diagnostic_canary: enabled
sampling_change: frozen

Do not treat an empty trace view as proof that nothing ran. Reconcile the run identifier with the application log, tool backend, approval service, and audit events. If a write result is unknown, keep the path read-only until the actual state is proven.

Map every sampling decision

A modern chain can contain several decisions: runtime sampler, agent framework instrumentation, OpenTelemetry Collector, Azure Monitor exporter, and ingestion sampling. Two consecutive percentages do not cancel each other; they reduce retention again. A downstream filter can also remove one span without respecting the trace decision.

text sampling-boundaries.txt
Boundary 1 - agent runtime
Sampler, ratio or rate, release, resource attributes

Boundary 2 - trace propagation
traceparent forwarded across model, tool and approval calls

Boundary 3 - collector or processor
Filters, batching, queue pressure, dropped spans, exporter retries

Boundary 4 - Azure Monitor ingestion
Ingestion sampling, transformations, daily cap, destination routing

Boundary 5 - query and retention
Workspace, table, retention, RBAC, query window and ingestion delay

Give one boundary ownership of the primary decision. Source sampling preserves consistency better than late ingestion reduction. A collector is still useful for routing and pipeline protection, but every rule must be versioned and observable.

Verify trace continuity

A correct rate is insufficient when traceparent disappears between the agent, tool API, and approval service. Compare one end-to-end retained run with one incomplete run. Verify the same TraceId, parent-child relationships, resource attributes, and logical action identity.

The policy must be consistent across components. Mixing incompatible strategies or rates can leave a root without its dependency, or a tool call without its policy decision. Do not repair this symptom by inventing links after ingestion: causality must propagate while the action runs.

text trace-completeness-contract.txt
One logical run
One trace ID across orchestration, policy, tool and approval
One immutable agent release and tool-contract version
One runtime identity recorded without secret material

Required terminal evidence
final status
policy decision
approval state
tool result class
backend reconciliation state

Negative controls
denied tool remains denied
expired approval cannot be reused
unknown backend result cannot trigger an automatic retry

Measure retained volume with KQL

Measure by telemetry type and hour before drawing a conclusion. In an Application Insights workspace, ItemCount can estimate the volume represented by stored rows. Adapt the table names when the pipeline normalizes spans into custom tables.

kusto 01-measure-retained-telemetry.kql
let Start = datetime(2026-10-11T05:30:00Z);
let End = datetime(2026-10-11T07:00:00Z);
union withsource=TableName AppRequests, AppDependencies, AppTraces
| where TimeGenerated between (Start .. End)
| extend Represented = toreal(coalesce(ItemCount, 1))
| summarize
  StoredRows = count(),
  EstimatedEvents = sum(Represented),
  RetainedPercent = round(100.0 * count() / sum(Represented), 2)
by TableName, bin(TimeGenerated, 15m)
| order by TimeGenerated asc, TableName asc

This ratio does not prove that the useful journeys were retained. Segment next by release, operation, tool, status, and policy decision using the properties actually exported. Focus on rare-case coverage: denials, timeouts, exceptions, expired approvals, and unknown backend results.

Health metrics should remain the stable sentinel: throughput, errors, latency, denied actions, and exporter queues. They signal that a journey needs investigation even when its trace was sampled out.

Separate diagnostic traces from the audit record

A trace is excellent for explaining causality, but a probabilistic sample must not be the only evidence for a sensitive action. Emit one minimal, deterministic audit event for every policy decision, approval consumption, and write attempt.

yaml agent-action-audit-contract.yml
event: agent.action.decision
required:
- logical_run_id
- timestamp_utc
- agent_release
- action_type
- target_scope_hash
- runtime_identity_id
- policy_decision
- approval_id_hash
- backend_state
- trace_id
forbidden:
- raw_prompt
- tool_payload
- access_token
- retrieved_document_content
delivery:
sampled: false
append_only: true
failure_alert: required

This record does not replace security controls or target-system logs. It provides a stable index for locating the trace, proving that an approval was consumed, and blocking a retry while downstream state remains ambiguous.

Canary the policy with discriminating journeys

A useful canary is more than one successful conversation. Replay at least one allowed read, denied call, tool error, expired approval, and deliberately ambiguous backend response. Use synthetic identifiers without sensitive content.

For each journey, verify the root, expected spans, terminal status, and audit event. Also measure ingestion delay, exporter queue, and estimated volume. Repeat under low load and during a controlled burst: a per-second limit can look correct at rest and hide a concentrated incident.

Promote, hold, or restore

Promote the policy when the volume budget holds, propagation remains complete, critical journeys are discoverable from audit, and negative controls remain denied. Hold the canary when one component still makes a different decision or coverage changes with load.

Restore the previous configuration when the new policy breaks correlation, removes required logs, or makes sensitive actions impossible to reconcile. Roll back a versioned bundle: sampler, instrumentation, collector, exporter, and ingestion rules. Do not reopen writes automatically after rollback; replay the canaries first and reconcile every action with an unknown result.

Conclusion

AI agent trace sampling is an operability decision, not only a cost optimization. It must preserve a coherent chain across orchestration, policy, tool, and approval while leaving a minimal independent audit record for sensitive decisions.

The runbook outcome is clear: promote a measured and canary-tested policy, keep it under observation, or restore the previous bundle. The right configuration is not the one that stores the most spans. It is the one that still lets the team decide, validate, and roll back when a real incident occurs.