You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/getting-started.md
+114Lines changed: 114 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1395,6 +1395,119 @@ await using var session = await client.CreateSessionAsync(new()
1395
1395
1396
1396
---
1397
1397
1398
+
## Telemetry & Observability
1399
+
1400
+
The Copilot SDK supports [OpenTelemetry](https://opentelemetry.io/) for distributed tracing. Provide a `telemetry` configuration to the client to enable trace export from the CLI process and automatic [W3C Trace Context](https://www.w3.org/TR/trace-context/) propagation between the SDK and CLI.
1401
+
1402
+
### Enabling Telemetry
1403
+
1404
+
Pass a `telemetry` (or `Telemetry`) config when creating the client. This is the opt-in — no separate "enabled" flag is needed.
| Exporter type |`exporterType`|`exporter_type`|`ExporterType`|`ExporterType`|`"otlp-http"` or `"file"`|
1483
+
| Source name |`sourceName`|`source_name`|`SourceName`|`SourceName`| Instrumentation scope name |
1484
+
| Capture content |`captureContent`|`capture_content`|`CaptureContent`|`CaptureContent`| Whether to capture message content |
1485
+
1486
+
### File Export
1487
+
1488
+
To write traces to a local file instead of an OTLP endpoint:
1489
+
1490
+
<!-- docs-validate: skip -->
1491
+
```typescript
1492
+
const client =newCopilotClient({
1493
+
telemetry: {
1494
+
filePath: "./traces.jsonl",
1495
+
exporterType: "file",
1496
+
},
1497
+
});
1498
+
```
1499
+
1500
+
### Trace Context Propagation
1501
+
1502
+
Trace context is propagated automatically — no manual instrumentation is needed:
1503
+
1504
+
-**SDK → CLI**: `traceparent` and `tracestate` headers from the current span/activity are included in `session.create`, `session.resume`, and `session.send` RPC calls.
1505
+
-**CLI → SDK**: When the CLI invokes tool handlers, the trace context from the CLI's span is propagated so your tool code runs under the correct parent span.
Copy file name to clipboardExpand all lines: docs/observability/opentelemetry.md
+97-1Lines changed: 97 additions & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,6 +1,102 @@
1
1
# OpenTelemetry Instrumentation for Copilot SDK
2
2
3
-
This guide shows how to add OpenTelemetry tracing to your Copilot SDK applications using GenAI semantic conventions.
3
+
This guide shows how to add OpenTelemetry tracing to your Copilot SDK applications.
4
+
5
+
## Built-in Telemetry Support
6
+
7
+
The SDK has built-in support for configuring OpenTelemetry on the CLI process and propagating W3C Trace Context between the SDK and CLI. Provide a `TelemetryConfig` when creating the client to opt in:
| Exporter type |`exporterType`|`exporter_type`|`ExporterType`|`ExporterType`|`"otlp-http"` or `"file"`|
78
+
| Source name |`sourceName`|`source_name`|`SourceName`|`SourceName`| Instrumentation scope name |
79
+
| Capture content |`captureContent`|`capture_content`|`CaptureContent`|`CaptureContent`| Whether to capture message content |
80
+
81
+
### Trace Context Propagation
82
+
83
+
Trace context is propagated automatically — no manual instrumentation is needed:
84
+
85
+
-**SDK → CLI**: `traceparent` and `tracestate` headers from the current span/activity are included in `session.create`, `session.resume`, and `session.send` RPC calls.
86
+
-**CLI → SDK**: When the CLI invokes tool handlers, the trace context from the CLI's span is propagated so your tool code runs under the correct parent span.
The rest of this guide shows how to add your own OpenTelemetry spans around SDK operations using GenAI semantic conventions. This is complementary to the built-in `TelemetryConfig` above — you can use both together.
Copy file name to clipboardExpand all lines: dotnet/README.md
+27Lines changed: 27 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -78,6 +78,7 @@ new CopilotClient(CopilotClientOptions? options = null)
78
78
-`Logger` - `ILogger` instance for SDK logging
79
79
-`GitHubToken` - GitHub token for authentication. When provided, takes priority over other auth methods.
80
80
-`UseLoggedInUser` - Whether to use logged-in user for authentication (default: true, but false when `GitHubToken` is provided). Cannot be used with `CliUrl`.
81
+
-`Telemetry` - OpenTelemetry configuration for the CLI process. Providing this enables telemetry — no separate flag needed. See [Telemetry](#telemetry) below.
81
82
82
83
#### Methods
83
84
@@ -546,6 +547,32 @@ var session = await client.CreateSessionAsync(new SessionConfig
546
547
});
547
548
```
548
549
550
+
## Telemetry
551
+
552
+
The SDK supports OpenTelemetry for distributed tracing. Provide a `Telemetry` config to enable trace export and automatic W3C Trace Context propagation.
-`FilePath` - File path for JSON-lines trace output
568
+
-`ExporterType` - `"otlp-http"` or `"file"`
569
+
-`SourceName` - Instrumentation scope name
570
+
-`CaptureContent` - Whether to capture message content
571
+
572
+
Trace context (`traceparent`/`tracestate`) is automatically propagated between the SDK and CLI on `CreateSessionAsync`, `ResumeSessionAsync`, and `SendAsync` calls, and inbound when the CLI invokes tool handlers.
573
+
574
+
No extra dependencies — uses built-in `System.Diagnostics.Activity`.
575
+
549
576
## User Input Requests
550
577
551
578
Enable the agent to ask questions to the user using the `ask_user` tool by providing an `OnUserInputRequest` handler:
-`Env` ([]string): Environment variables for CLI process (default: inherits from current process)
142
142
-`GitHubToken` (string): GitHub token for authentication. When provided, takes priority over other auth methods.
143
143
-`UseLoggedInUser` (\*bool): Whether to use logged-in user for authentication (default: true, but false when `GitHubToken` is provided). Cannot be used with `CLIUrl`.
144
+
-`Telemetry` (\*TelemetryConfig): OpenTelemetry configuration for the CLI process. Providing this enables telemetry — no separate flag needed. See [Telemetry](#telemetry) below.
> - For Azure OpenAI endpoints (`*.openai.azure.com`), you **must** use `Type: "azure"`, not `Type: "openai"`.
473
474
> - The `BaseURL` should be just the host (e.g., `https://my-resource.openai.azure.com`). Do **not** include `/openai/v1` in the URL - the SDK handles path construction automatically.
474
475
476
+
## Telemetry
477
+
478
+
The SDK supports OpenTelemetry for distributed tracing. Provide a `Telemetry` config to enable trace export and automatic W3C Trace Context propagation.
-`FilePath` (string): File path for JSON-lines trace output
492
+
-`ExporterType` (string): `"otlp-http"` or `"file"`
493
+
-`SourceName` (string): Instrumentation scope name
494
+
-`CaptureContent` (bool): Whether to capture message content
495
+
496
+
Trace context (`traceparent`/`tracestate`) is automatically propagated between the SDK and CLI on `CreateSession`, `ResumeSession`, and `Send` calls, and inbound when the CLI invokes tool handlers.
497
+
498
+
Dependency: `go.opentelemetry.io/otel`
499
+
475
500
## User Input Requests
476
501
477
502
Enable the agent to ask questions to the user using the `ask_user` tool by providing an `OnUserInputRequest` handler:
Copy file name to clipboardExpand all lines: nodejs/README.md
+25Lines changed: 25 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -84,6 +84,7 @@ new CopilotClient(options?: CopilotClientOptions)
84
84
-`autoStart?: boolean` - Auto-start server (default: true)
85
85
-`githubToken?: string` - GitHub token for authentication. When provided, takes priority over other auth methods.
86
86
-`useLoggedInUser?: boolean` - Whether to use logged-in user for authentication (default: true, but false when `githubToken` is provided). Cannot be used with `cliUrl`.
87
+
-`telemetry?: TelemetryConfig` - OpenTelemetry configuration for the CLI process. Providing this object enables telemetry — no separate flag needed. See [Telemetry](#telemetry) below.
> - For Azure OpenAI endpoints (`*.openai.azure.com`), you **must** use `type: "azure"`, not `type: "openai"`.
602
603
> - The `baseUrl` should be just the host (e.g., `https://my-resource.openai.azure.com`). Do **not** include `/openai/v1` in the URL - the SDK handles path construction automatically.
603
604
605
+
## Telemetry
606
+
607
+
The SDK supports OpenTelemetry for distributed tracing. Provide a `telemetry` config to enable trace export and automatic W3C Trace Context propagation.
608
+
609
+
```typescript
610
+
const client =newCopilotClient({
611
+
telemetry: {
612
+
otlpEndpoint: "http://localhost:4318",
613
+
},
614
+
});
615
+
```
616
+
617
+
**TelemetryConfig options:**
618
+
619
+
-`otlpEndpoint?: string` - OTLP HTTP endpoint URL
620
+
-`filePath?: string` - File path for JSON-lines trace output
621
+
-`exporterType?: string` - `"otlp-http"` or `"file"`
622
+
-`sourceName?: string` - Instrumentation scope name
623
+
-`captureContent?: boolean` - Whether to capture message content
624
+
625
+
Trace context (`traceparent`/`tracestate`) is automatically propagated between the SDK and CLI on `session.create`, `session.resume`, and `session.send` calls, and inbound when the CLI invokes tool handlers.
626
+
627
+
Optional peer dependency: `@opentelemetry/api`
628
+
604
629
## User Input Requests
605
630
606
631
Enable the agent to ask questions to the user using the `ask_user` tool by providing an `onUserInputRequest` handler:
0 commit comments