Skip to content

Add an agent OpenTelemetry tracing example - #1168

Open
PratikDhanave (PratikDhanave) wants to merge 1 commit into
microsoft:mainfrom
PratikDhanaveFork:feat/example-otel
Open

PratikDhanave (PratikDhanave) wants to merge 1 commit into
microsoft:mainfrom
PratikDhanaveFork:feat/example-otel

Conversation

@PratikDhanave

Copy link
Copy Markdown
Contributor

Go has otelprovider (an OpenTelemetry tracing middleware) but examples/ has no sample, unlike the .NET AgentOpenTelemetry sample.

Change

  • New examples/02-agents/observability/step01_agent_tracing that installs a stdout OpenTelemetry tracer (stdouttrace, already a dependency) as the global provider and wraps a Foundry agent with otelprovider.NewMiddleware, so the run emits a gen_ai invoke_agent span (model, usage, finish reason) printed to stdout.
  • Registered in cmd/verifyexamples (env-gated on FOUNDRY_PROJECT_ENDPOINT).

Builds, go vet, gofumpt clean; no go.mod changes; the verifyexamples test passes.

Go has otelprovider but no sample. Add an example that installs a stdout
OpenTelemetry tracer and wraps a Foundry agent with the otel middleware, so
the agent run emits a gen_ai invoke_agent span (model, usage, finish reason)
printed to stdout. Registered with cmd/verifyexamples (env-gated).
Copilot AI lite review requested due to automatic review settings September 23, 2026 04:52
@github-actions github-actions Bot added area:examples Changes files in the examples area area:tooling Changes files in the tooling area size:medium At most 100 changed lines across at most 5 files labels Sep 23, 2026

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot review overview

🟡 Changes recommended

The example description claims a model attribute that the middleware does not emit.

Get a fresh assessment by requesting another Copilot review.

Review effort: Lite
Findings: 1 Low severity

Open (1)
What changed in this PR

Adds an OpenTelemetry tracing example for Foundry agents and registers it with verifyexamples.

Changes:

  • Exports agent spans to stdout.
  • Registers environment-gated example verification.
File Description
examples/​02-agents/​observability/​step01_agent_tracing/​main.go New agent tracing sample
cmd/​verifyexamples/​examples.go Registers the sample for verification

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment on lines +19 to +21
"This sample shows how to trace an agent run with OpenTelemetry. The otelprovider "+
"middleware emits a gen_ai invoke_agent span (model, usage, finish reason) that "+
"is exported here to stdout.",
@github-actions

Copy link
Copy Markdown
Contributor

Scope: examples, tooling (internal-only)

Changed Go contract: None. This PR only adds a new example (examples/02-agents/observability/step01_agent_tracing/main.go) and registers it in cmd/verifyexamples/examples.go. No exported types, functions, or runtime defaults in library packages (agent, provider/otelprovider, etc.) are added or modified.

Upstream evidence reviewed:

  • .NET: dotnet/samples/02-agents/AgentOpenTelemetry/Program.cs — configures an OTel TracerProvider/MeterProvider and runs a Foundry-backed agent, demonstrating gen_ai span emission for agent invocation.
  • Python: python/samples/02-agents/observability/configure_otel_providers_with_env_var.py and sibling files in python/samples/02-agents/observability/ — show OTel provider configuration (env-var or parameter based) wrapping Foundry chat client / agent calls.

Result: Aligned. The new Go example fills a real coverage gap (Go had no observability sample even though otelprovider.NewMiddleware already exists) and is conceptually consistent with the upstream .NET/Python samples: it configures an OTel tracer provider (here, a stdouttrace exporter for simplicity, versus OTLP/Azure Monitor in .NET), sets it as the global provider, and wraps a Foundry agent so the run emits a gen_ai invoke_agent span. Using a stdout exporter instead of OTLP/Application Insights is an intentional simplification appropriate for a minimal, dependency-free sample and doesn't diverge from upstream semantics (span attributes, model/usage/finish-reason) which are produced by the existing, unchanged otelprovider middleware. The example follows existing Go example conventions (examples/internal/demo helper package, env-gated registration in verifyexamples). No public API surface changed, so the public-api-change label is not applicable.

Generated by Go API Consistency Review Agent · copilot · auto · 33.3 AIC · ⌖ 6.38 AIC · ⊞ 9.2K ·

@github-actions github-actions Bot added the kind:examples Changes examples or example-support metadata label Sep 23, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:examples Changes files in the examples area area:tooling Changes files in the tooling area kind:examples Changes examples or example-support metadata size:medium At most 100 changed lines across at most 5 files

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants