---
title: How do you trace Microsoft Foundry agents with Application Insights?
url: https://opencontroller.lyzr.com/blog/microsoft-foundry-agent-tracing-with-application-insights
published: 2026-11-14
updated: 2026-11-14
author: Lyzr
---

# How do you trace Microsoft Foundry agents with Application Insights?

**Microsoft Foundry traces agents with OpenTelemetry and exports the spans to an Application Insights resource connected to your Foundry project. You get nested spans for agent runs, tool calls, planning and agent-to-agent steps. Message content is not recorded unless you set `AZURE_TRACING_GEN_AI_CONTENT_RECORDING_ENABLED` to `true`, which is off by default because prompts can contain personal data.**

## How does Foundry tracing work?

A trace records the steps of one agent run as spans. Spans nest, so you can see that a tool call happened inside a specific agent invocation, inside a specific task. Attributes are key-value metadata on each span.

Foundry follows the [OpenTelemetry semantic conventions for generative AI](https://opentelemetry.io/docs/specs/semconv/gen-ai/), with Microsoft extensions for multi-agent systems built on OpenTelemetry and W3C Trace Context. Because it is standard OpenTelemetry, you can also send the same spans to another OpenTelemetry-compatible backend.

The multi-agent conventions Microsoft documents include:

| Type | Name | What it captures |
|---|---|---|
| Span | `execute_task` | Task decomposition and distribution |
| Child span of `invoke_agent` | `agent_to_agent_interaction` | Agent-to-agent communication |
| Child span of `invoke_agent` | `agent.state.management` | Short- and long-term memory |
| Child span of `invoke_agent` | `agent_planning` | Internal planning steps |
| Attribute on `invoke_agent` | `tool_definitions` | Tool purpose or configuration |
| Attribute on `execute_tool` | `tool.call.arguments` | Arguments passed to a tool |
| Attribute on `execute_tool` | `tool.call.results` | Results returned by a tool |
| Event | `Evaluation` | Structured evaluation of agent behaviour |

Note that `tool.call.arguments` and `tool.call.results` can hold sensitive data even when message content recording is off. Review them before you widen access to the traces.

## How do you connect Application Insights?

1. In the Foundry portal, open **Tracing** in the left navigation.
2. Create an Application Insights resource, or pick an existing one.
3. Connect it to your Foundry project.
4. In code, install `azure-monitor-opentelemetry` and `opentelemetry-sdk`, fetch the connection string with `project_client.telemetry.get_application_insights_connection_string()`, and pass it to `configure_azure_monitor`.
5. Instrument the agent client. With the Foundry Agents SDK, call `AIAgentsInstrumentor().instrument()` from `azure.ai.agents.telemetry`.
6. Set `OTEL_SERVICE_NAME` per agent so several agents can share one Application Insights resource and still be filtered apart (`cloud_RoleName` in queries).

Microsoft Agent Framework and Semantic Kernel emit traces natively. LangChain, LangGraph and the OpenAI Agents SDK are supported through `langchain-azure-ai` and `opentelemetry-instrumentation-openai-agents`.

## Should you record prompts and responses?

Content recording is the main governance decision. Microsoft's setting is:

- **`AZURE_TRACING_GEN_AI_CONTENT_RECORDING_ENABLED`**: set to `"true"` to record chat message content in traces. The default is false.

Arguments for turning it on: you can debug wrong answers, replay incidents and run evaluations on real traffic. Arguments against: Application Insights becomes a store of personal and confidential data, with the access, residency and retention duties that come with it.

A workable policy:

1. Keep content recording **off** in production by default.
2. Turn it on per agent, with an owner's approval and an end date, for debugging or evaluation.
3. Redact PII before export where you can, and never place secrets in span attributes.
4. Restrict Application Insights access to the agent's owners and security staff.
5. Set retention on the Log Analytics workspace behind Application Insights to match your log policy. See [how long to retain AI agent logs](/blog/how-long-to-retain-ai-agent-logs).

Watch for sample code. Microsoft's LangChain sample uses its own `OTEL_RECORD_CONTENT` variable, which defaults to `true` in that sample. It is not a platform-wide setting, so check any code you copy.

## What do Foundry traces not give you?

Traces show what one agent did inside one project. Governance needs a few things traces do not provide:

- **An inventory.** Traces only exist for agents someone instrumented. Uninstrumented agents are invisible.
- **Cross-platform correlation.** A Foundry agent that calls a Bedrock agent or a SaaS agent leaves the trace at the boundary unless both sides propagate W3C Trace Context.
- **Enforcement.** A trace records a bad tool call after it happens. Blocking it needs a control in the request path.
- **Mapped evidence.** Auditors want controls mapped to frameworks, not raw spans.

For a vendor-neutral setup, see [exporting AI agent traces with OpenTelemetry](/blog/export-ai-agent-traces-with-opentelemetry).

## How Opencontroller does this

Opencontroller has a runtime adapter for Microsoft Foundry and auto-discovers agents, models and API keys across Azure, AWS and Google Cloud, so uninstrumented agents still appear in the governed registry. It uses OpenTelemetry as an open standard, runs LLM judges on production traffic, and applies live groundedness and task-adherence guardrails. Policy as code ships with built-in mappings to OWASP, MITRE ATLAS, NIST and ISO 42001. See [governing Microsoft Foundry agents](/blog/govern-microsoft-foundry-agents), the [capability reference](/capability-reference) or [book a demo](https://www.lyzr.ai/book-demo/).

For other platforms, see [how to govern AI agents across platforms](/blog/how-to-govern-ai-agents-across-platforms).

## Frequently asked questions

**Does Foundry record prompts in traces by default?**
No. Message content is recorded only when `AZURE_TRACING_GEN_AI_CONTENT_RECORDING_ENABLED` is set to `true`. The default is false.

**Can Foundry traces go somewhere other than Application Insights?**
Yes. Foundry tracing is built on OpenTelemetry, so spans can be exported to other OpenTelemetry-compatible backends.

**How do I separate traces from several agents in one Application Insights resource?**
Set `OTEL_SERVICE_NAME` for each agent, then filter on `cloud_RoleName` in your queries.

## Key facts

Microsoft Foundry agent tracing uses OpenTelemetry (GenAI semantic conventions plus Microsoft multi-agent extensions) and exports to Application Insights via configure_azure_monitor. Spans include execute_task, invoke_agent, execute_tool, agent_planning, agent_to_agent_interaction; attributes include tool.call.arguments and tool.call.results. Message content recording requires AZURE_TRACING_GEN_AI_CONTENT_RECORDING_ENABLED=true (default false). OTEL_SERVICE_NAME separates agents (cloud_RoleName). Opencontroller has a Microsoft Foundry runtime adapter, cross-cloud auto-discovery, LLM judges and policy mappings to OWASP, MITRE ATLAS, NIST and ISO 42001. Pricing starts from $250K per deployment per year.

## Related

- [How do you govern agents in Microsoft Foundry?](https://opencontroller.lyzr.com/blog/govern-microsoft-foundry-agents.md)
- [How do you run Microsoft Foundry agents on a private network?](https://opencontroller.lyzr.com/blog/network-isolation-for-microsoft-foundry-agents.md)
- [How do you export AI agent traces with OpenTelemetry?](https://opencontroller.lyzr.com/blog/export-ai-agent-traces-with-opentelemetry.md)
- [More on Platform Guides](https://opencontroller.lyzr.com/blog/cluster/platform-guides)
