Skip to content

Add OpenTelemetry GenAI instrumentation to Copilot SDK#602

Open
stephentoub wants to merge 1 commit intogithub:mainfrom
stephentoub:otel-genai-convention-fixes
Open

Add OpenTelemetry GenAI instrumentation to Copilot SDK#602
stephentoub wants to merge 1 commit intogithub:mainfrom
stephentoub:otel-genai-convention-fixes

Conversation

@stephentoub
Copy link
Contributor

@stephentoub stephentoub commented Feb 27, 2026

Introduced built-in OpenTelemetry tracing and metrics for agent turns and tool executions, following GenAI semantic conventions (v1.40).

image image image image image

@stephentoub stephentoub marked this pull request as ready for review February 27, 2026 19:35
@stephentoub stephentoub requested a review from a team as a code owner February 27, 2026 19:35
Copilot AI review requested due to automatic review settings February 27, 2026 19:35
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Adds built-in, opt-in OpenTelemetry tracing + metrics across the SDKs (Node/TS, Python, Go, .NET), emitting spans/metrics that follow the GenAI semantic conventions (v1.40) for agent turns and tool executions.

Changes:

  • Introduces TelemetryConfig in each SDK and wires it into client/session creation (opt-in).
  • Instruments invoke_agent turns and execute_tool calls with spans + GenAI metrics (duration, token usage, streaming timing).
  • Updates docs and adds/updates tests demonstrating expected telemetry output and sensitive-data gating.

Reviewed changes

Copilot reviewed 35 out of 37 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
python/pyproject.toml Adds OpenTelemetry API/SDK deps (API runtime, SDK in dev extras).
python/copilot/types.py Adds TelemetryConfig + agent attribution fields to session configs.
python/copilot/session.py Starts/updates per-turn telemetry tracking and captures tool descriptions.
python/copilot/client.py Initializes telemetry (opt-in), passes context to sessions, instruments tool calls.
python/copilot/_copilot_telemetry.py Implements Python-side GenAI OTel spans/metrics + per-turn tracker.
python/copilot/init.py Exposes TelemetryConfig from the Python package API surface.
python/README.md Documents telemetry and agent attribution options for Python users.
nodejs/test/opentelemetry.test.ts Adds unit tests validating Node telemetry spans/metrics and gating behavior.
nodejs/src/types.ts Adds TelemetryConfig + agent attribution fields to TS public types.
nodejs/src/session.ts Adds per-turn telemetry tracking hooks and tool description registry.
nodejs/src/index.ts Re-exports TelemetryConfig type.
nodejs/src/copilot-telemetry.ts Implements Node-side GenAI OTel spans/metrics + per-turn tracker.
nodejs/src/client.ts Initializes telemetry (opt-in) and instruments tool execution with child spans + metrics.
nodejs/package.json Adds OTel JS API dependency and SDK devDependencies for tests.
nodejs/package-lock.json Locks new OTel dependencies.
nodejs/README.md Documents telemetry + agent attribution options for Node users.
go/types.go Adds telemetry + agent attribution fields to Go options/config types.
go/session.go Adds tool descriptions + per-turn telemetry hooks and session telemetry context setup.
go/go.sum Adds sums for new OpenTelemetry Go dependencies.
go/go.mod Adds OpenTelemetry Go modules and toolchain metadata.
go/copilot_telemetry_consts.go Defines GenAI semconv constants + metric bucket boundaries for Go.
go/copilot_telemetry.go Implements Go-side GenAI OTel spans/metrics + per-turn tracker.
go/client.go Wires telemetry into client/session creation and tool execution instrumentation.
go/README.md Documents telemetry + agent attribution options for Go users.
dotnet/test/OpenTelemetryTests.cs Adds E2E tests validating .NET telemetry spans/metrics and gating behavior.
dotnet/test/Harness/E2ETestContext.cs Allows creating clients with/without telemetry in the .NET harness.
dotnet/test/GitHub.Copilot.SDK.Test.csproj Adds in-memory OTel exporter dependency for tests.
dotnet/src/Types.cs Adds TelemetryConfig + agent attribution fields to .NET option/config types.
dotnet/src/Session.cs Integrates per-turn tracker and telemetry completion on send/wait failures.
dotnet/src/OpenTelemetryConsts.cs Adds GenAI semconv constants + metric boundaries for .NET.
dotnet/src/CopilotTelemetry.cs Implements .NET telemetry (ActivitySource + Meter) and per-turn tracker.
dotnet/src/Client.cs Creates telemetry instance (opt-in), instruments execute_tool, disposes telemetry on shutdown.
dotnet/README.md Documents telemetry + agent attribution options for .NET users.
docs/opentelemetry-instrumentation.md Rewrites OTel docs to describe built-in instrumentation and configuration.
README.md Adds top-level docs link to OpenTelemetry instrumentation guide.
Files not reviewed (1)
  • nodejs/package-lock.json: Language not supported

@stephentoub stephentoub force-pushed the otel-genai-convention-fixes branch 6 times, most recently from 7b567d1 to 5e4ddfa Compare February 27, 2026 20:04
Introduced built-in OpenTelemetry tracing and metrics for agent turns and tool executions, following GenAI semantic conventions (v1.40).

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@stephentoub stephentoub force-pushed the otel-genai-convention-fixes branch from 5e4ddfa to 4b1126f Compare February 27, 2026 21:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants