Add --otel distributed tracing support#126
Merged
Merged
Conversation
Emit a sampled W3C traceparent on Cosmos DB requests so external tracing systems (e.g. the emulator) can correlate shell activity. - New --otel [endpoint] option (optional value, like --mcp): bare --otel enables tracing; an endpoint (or OTEL_EXPORTER_OTLP_ENDPOINT) also exports spans via OTLP - TracingBootstrap: sets the Azure.Experimental.EnableActivitySource switch and registers an AlwaysOn TracerProvider listening to Azure.Cosmos.Operation and CosmosDBShell sources so activities are recorded (traceparent flag -01) - Each command runs inside a CosmosDBShell root activity - CreateClientOptions sets DisableDistributedTracing=false explicitly - Add OpenTelemetry + OTLP exporter packages (1.15.3) - Help text, README, docs/navigation.md, and unit tests
Contributor
There was a problem hiding this comment.
Pull request overview
Adds optional OpenTelemetry-based distributed tracing to CosmosDBShell via a new --otel [endpoint] startup option, enabling sampled W3C traceparent propagation on Cosmos SDK requests and (optionally) OTLP span export.
Changes:
- Adds
--otel [endpoint]CLI option, wiring initialization/disposal of tracing inProgram.csand help text inen.ftl. - Introduces
TracingBootstrapto configure an OpenTelemetryTracerProviderand create per-command root activities. - Updates docs/README and adds unit tests covering tracing bootstrap behavior.
Reviewed changes
Copilot reviewed 9 out of 9 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
| README.md | Documents the new --otel option in the feature list and options table. |
| docs/navigation.md | Adds --otel and OTEL_EXPORTER_OTLP_ENDPOINT to navigation docs + examples. |
| Directory.Packages.props | Pins OpenTelemetry + OTLP exporter package versions. |
| CosmosDBShell/Program.cs | Parses --otel [endpoint], initializes/disposes tracing, and adds the option to help output. |
| CosmosDBShell/lang/en.ftl | Adds localized help text for --otel. |
| CosmosDBShell/CosmosDBShell.csproj | Adds package references for OpenTelemetry and the OTLP exporter. |
| CosmosDBShell/Azure.Data.Cosmos.Shell.Core/TracingBootstrap.cs | New tracing bootstrapper (provider lifecycle + ActivitySource root activities). |
| CosmosDBShell/Azure.Data.Cosmos.Shell.Core/ShellInterpreter.cs | Wraps each executed command in a tracing activity; enables Cosmos SDK distributed tracing option. |
| CosmosDBShell.Tests/Runtime/TracingBootstrapTests.cs | Adds tests verifying activity creation/recording and the Azure SDK switch. |
sevoku
approved these changes
Jun 12, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Adds distributed tracing to CosmosShell so requests carry a sampled W3C
traceparentthat external tracing systems (for example, the Cosmos DB emulator) can use to correlate shell activity. Optionally exports spans over OTLP.This addresses the distributed-tracing request. File-based diagnostic logging (issue #122) is intentionally out of scope and will follow in a separate PR.
How it works
The Cosmos SDK only emits a
traceparentwith the sampled flag set (-01) when two things are true: the Azure SDKAzure.Experimental.EnableActivitySourceswitch is on, and a recorded (sampled)Activityis in scope. This PR wires both up:AppContextswitchAzure.Experimental.EnableActivitySourcebefore anyCosmosClientis created.TracerProviderwithAlwaysOnSampler, listening to theAzure.Cosmos.OperationandCosmosDBShellactivity sources, so activities are recorded.CosmosDBShellroot activity, so every command is one trace.CosmosClientTelemetryOptions.DisableDistributedTracing = falseexplicitly.CLI
New
--otel [endpoint]option (optional value, mirroring--mcp):--otel— enable tracing (always emits a sampledtraceparent). Spans are exported only if an OTLP endpoint is configured (see below); otherwise tracing is local-only with no export.--otel <endpoint>— also export spans to that explicit OTLP endpoint.--otelis given without an endpoint, the endpoint falls back to the standardOTEL_EXPORTER_OTLP_ENDPOINTenvironment variable; if that is also unset, no spans are exported.A malformed endpoint (from
--otel <endpoint>orOTEL_EXPORTER_OTLP_ENDPOINT) now produces a clean error and a non-zero exit code instead of an unhandled exception.Changes
--oteloption + plumbing inProgram.cs;help-Otelandotel-error-invalid-endpointinen.ftl.Core/TracingBootstrap.cs(provider lifecycle + per-command activity source).ShellInterpreter: enable SDK tracing, per-command root activity.1.15.3, the patched version clearing advisory NU1902).docs/navigation.md, andRuntime/TracingBootstrapTests.cs.Validation
Out of scope
File logging / issue #122, OTEL metrics & logs signals, Azure Monitor / App Insights exporters, Direct-mode
traceparentspecifics.