Items marked (preview) in this article are currently in public preview. This preview is provided without a service-level agreement, and we don’t recommend it for production workloads. Certain features might not be supported or might have constrained capabilities. For more information, see Supplemental Terms of Use for Microsoft Azure Previews.
- Instrument an external agent to emit OpenTelemetry spans to Application Insights.
- Register the agent in Foundry as an
externalagent. - Verify traces in the Foundry portal.
- Run a trace-based evaluation over the agent’s collected telemetry.
gen_ai.agent.id attribute to an Application Insights resource connected to your Foundry project. A separate registration call creates the agent record in Foundry. The Foundry portal then matches traces by agent ID and displays them in the agent trace view.
External agents are in preview. Create and update requests require the
Foundry-Features: ExternalAgents=V1Preview header. SDK callers enable this by constructing AIProjectClient with allow_preview=True.Prerequisites
- A Foundry project with an Application Insights resource connected.
- An agent running outside Foundry that can emit OpenTelemetry spans to that Application Insights resource.
- Python 3.11 or later.
- Foundry User role on the project.
- Reader role or Monitoring Reader role on the connected Application Insights resource to view traces.
The Foundry RBAC roles were recently renamed. Foundry User, Foundry Owner, Foundry Account Owner, and Foundry Project Manager were previously named Azure AI User, Azure AI Owner, Azure AI Account Owner, and Azure AI Project Manager. You might still see the previous names in some places while the rename rolls out. The role IDs and core permissions are unchanged by the rename.
DefaultAzureCredentialconfigured. Sign in withaz loginor set up a managed identity or service principal.- (For evaluation only) An Azure OpenAI deployment with a GPT model that supports chat completion (for example,
gpt-5-mini).
Instrument the external agent with OpenTelemetry
Before you register the agent in Foundry, configure it to export OpenTelemetry spans to the Application Insights resource connected to your Foundry project. Each span must carry thegen_ai.agent.id attribute so Foundry can attribute the span to the correct agent registration.
Install the Microsoft OpenTelemetry package
Configure the exporter
Run this code once during agent startup, before any framework imports that should be instrumented:APPLICATIONINSIGHTS_CONNECTION_STRING environment variable on the host where the agent runs. Use the connection string from the Application Insights resource linked to your Foundry project. To find the connection string, open the Foundry portal, navigate to your project, and select Management > Connected resources. Select the Application Insights resource to view its connection string. Alternatively, open the Application Insights resource directly in the Azure portal and copy the connection string from the Overview page.
After configuration, subsequent OpenTelemetry spans from your agent framework automatically flow to Application Insights. Each span must set the gen_ai.agent.id attribute to the value you choose as otel_agent_id during registration.
If your agent framework doesn’t set this attribute automatically, add it manually:
Register the external agent in Foundry
After the agent emits spans to Application Insights, register it in Foundry so those spans appear in the Foundry trace view scoped to the agent. Registering creates a named record in Foundry that links incoming traces (matched bygen_ai.agent.id) to the Foundry agent experience. Without this registration, traces still flow into Application Insights but don’t appear in the Foundry agent trace view, and you can’t run trace-based evaluations scoped to the agent.
Install the SDK
Create the registration
- Foundry portal
- Python SDK
You can create a registration in the Foundry portal by:
- Opening your project and selecting Build > Agents > New agent.
- Selecting Link external agent.
- In the window that appears, entering the agent name, description, and the OpenTelemetry ID.

Verify traces in the Foundry portal
After the agent sends traffic and spans ingest into Application Insights (typically 2–5 minutes), verify that traces appear in the Foundry portal:- Open the Foundry portal.
- Navigate to your project.
- Select Agents from the left pane.
- Select the external agent name (for example, travel-planner-agent).
- Select the Traces tab to view spans attributed to this agent.
gen_ai.agent.id = <otel_agent_id> from the Application Insights resource connected to the project. You can view inputs, outputs, tool calls, and latency for each span.
Run a trace-based evaluation
After traces flow into Application Insights, you can run evaluations directly over those traces. No separate dataset construction is required. Foundry resolves traces by matching(project, agent_id) over a lookback window.
Trace-based evaluations use the OpenAI-compatible
evals API (project.get_openai_client().evals). The native project.evaluations surface doesn’t yet support trace-based evaluation.Resolve the agent’s otel_agent_id
To get the agent’s ID for traces, use the following:Create and run the evaluation
Use theotel_agent_id to run a trace evaluation over the agent’s collected telemetry. For the full walkthrough, including how to create an eval group, configure testing criteria, and interpret results, see Trace evaluation (preview).
Manage external agents
Use the same SDK methods to list, retrieve, and delete external agents.List external agents
Delete an external agent
Troubleshooting
Troubleshoot missing traces
If you don’t see traces, check the following items:- The Application Insights resource is connected to the Foundry project where you registered the agent.
- The
otel_agent_idon the registration matches thegen_ai.agent.idattribute on the spans. - The agent process has
APPLICATIONINSIGHTS_CONNECTION_STRINGset to the correct Application Insights resource. - Spans comply with OpenTelemetry semantic conventions for generative AI. For more troubleshooting guidance, see Troubleshoot evaluation and observability issues.
Troubleshoot registration errors
Ifcreate_version() fails, check the following items:
- You constructed
AIProjectClientwithallow_preview=True. Without this flag, external agent requests are rejected. - Your identity has the Foundry User role (or higher) on the project.
- The
agent_namevalue uses only alphanumeric characters, hyphens, and underscores. - No existing agent with the same name and a different kind already exists. Use
project.agents.get()to check.