feat: add OpenTelemetry support across all SDKs#785
feat: add OpenTelemetry support across all SDKs#785stephentoub wants to merge 2 commits intomainfrom
Conversation
… documentation Add telemetry documentation across all SDK docs: - getting-started.md: New 'Telemetry & Observability' section with per-language examples, TelemetryConfig options table, file export example, and trace context propagation explanation - Per-SDK READMEs (Node.js, Python, Go, .NET): Add telemetry option to constructor/options lists and new Telemetry sections with language-specific examples and dependency notes - observability/opentelemetry.md: Add 'Built-in Telemetry Support' section at top with multi-language examples, options table, propagation details, and dependency matrix - docs/index.md: Update Observability description Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Add TelemetryConfig to all four SDKs (Node, Python, Go, .NET) to configure OpenTelemetry instrumentation on the Copilot CLI process. This includes: - TelemetryConfig type with OTLP endpoint, file exporter, source name, and capture-content options, mapped to CLI environment variables - W3C Trace Context propagation (traceparent/tracestate) on session.create, session.resume, and session.send RPC calls - Trace context restoration in tool call handlers (v2 RPC and v3 broadcast) so user tool code executes within the correct distributed trace - Telemetry helper modules (telemetry.ts, telemetry.py, telemetry.go, Telemetry.cs) with unit tests - Updated generated types from latest schema Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Cross-SDK Consistency Review: OpenTelemetry SupportI've reviewed this PR for cross-SDK consistency across all four language implementations (Node.js, Python, Go, .NET). Overall, the implementation is very well done with excellent feature parity! 🎉 ✅ Consistent Across All SDKsThe following features are implemented consistently across all languages:
|
There was a problem hiding this comment.
Generated by SDK Consistency Review Agent for issue #785
| Arguments: req.Arguments, | ||
| } | ||
|
|
||
| result, err := handler(invocation) |
There was a problem hiding this comment.
Consistency suggestion: For consistency with the other SDK implementations, consider restoring the trace context before calling the handler here:
// Restore trace context (even though ToolHandler can't receive it)
ctx := contextWithTraceParent(context.Background(), req.Traceparent, req.Tracestate)
// Note: ToolHandler signature doesn't accept context.Context, so any spans created
// by the handler won't be automatically parented unless the handler manually propagates context.
result, err := handler(invocation)The other SDKs all restore trace context in their v2 handlers:
- Node.js uses
withTraceContext(traceparent, tracestate, () => handler(...)) - Python uses
with trace_context(tp, ts): result = handler(...) - .NET uses
using var _ = RestoreTraceContext(traceparent, tracestate);
While Go's limitation is well-documented in the README, adding the context restoration (even if unused) would make the intent clearer and align with the other implementations.
Summary
Adds OpenTelemetry integration to all four language SDKs (Node.js, Python, Go, .NET), enabling distributed tracing between SDK consumers and the Copilot CLI.
What's included
TelemetryConfigtype (all SDKs)New configuration object on
CopilotClientOptionsthat maps to CLI environment variables:otlpEndpoint→OTEL_EXPORTER_OTLP_ENDPOINTfilePath→COPILOT_OTEL_FILE_EXPORTER_PATHexporterType→COPILOT_OTEL_EXPORTER_TYPEsourceName→COPILOT_OTEL_SOURCE_NAMEcaptureContent→OTEL_INSTRUMENTATION_GENAI_CAPTURE_MESSAGE_CONTENTWhen provided,
COPILOT_OTEL_ENABLED=trueis set on the spawned CLI process.W3C Trace Context propagation
traceparent/tracestatefields are now sent on:session.createsession.resumesession.sendTrace context restoration in tool handlers
Both v2 RPC (
tool.call) and v3 broadcast (tool.call.requested) tool call paths restore the inbound trace context before invoking user tool handlers, so tool execution is linked to the originating trace.Telemetry helper modules
Each SDK has a new telemetry module (
telemetry.ts,telemetry.py,telemetry.go,Telemetry.cs) with unit tests.Updated generated types
Regenerated RPC and session-event types from the latest schema to include
traceparent/tracestatefields.Documentation
Added OpenTelemetry configuration docs and per-language README sections.
This PR depends on the Copilot CLI supporting the
traceparent/tracestatefields in the RPC protocol. It will need to update to the next version of the CLI before this can move forward.Known limitation
The Go
ToolHandlertype does not accept acontext.Contextparameter, so while trace context is restored around the handler call (for theHandlePendingToolCallRPC), it cannot be passed directly into user tool code. A comment has been added noting this; a future breaking change to the handler signature would fully resolve it.