Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit b5ce1c8

Browse files
loganrosenCopilot
andauthored
Add OTLP protocol telemetry options (#1648)
* Add OTLP protocol telemetry options Expose OTLP HTTP protocol selection through each SDK telemetry config and map the values to the standard OpenTelemetry protocol environment variables when spawning the Copilot CLI. Co-authored-by: Copilot <[email protected]> * Remove signal-specific OTLP protocol options Keep the SDK telemetry API focused on the global OTLP HTTP protocol option and rely on direct environment variables for uncommon signal-specific overrides. Co-authored-by: Copilot <[email protected]> * Address telemetry protocol review feedback Narrow the Python OTLP protocol type, avoid hardcoding the CLI default in docs, and add Rust serde coverage tying protocol wire values to env values. Co-authored-by: Copilot <[email protected]> * Fix Python telemetry protocol docstring lint Wrap the OTLP protocol TypedDict docstring so Python CI lint passes. Co-authored-by: Copilot <[email protected]> --------- Co-authored-by: Copilot <[email protected]>
1 parent f8b2eee commit b5ce1c8

28 files changed

Lines changed: 181 additions & 6 deletions

docs/getting-started.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2227,11 +2227,14 @@ Dependency: `io.opentelemetry:opentelemetry-api`
22272227
| Option | Node.js | Python | Go | Rust | Java | .NET | Description |
22282228
|---|---|---|---|---|---|---|---|
22292229
| OTLP endpoint | `otlpEndpoint` | `otlp_endpoint` | `OTLPEndpoint` | `otlp_endpoint` | `otlpEndpoint` | `OtlpEndpoint` | OTLP HTTP endpoint URL |
2230+
| OTLP protocol | `otlpProtocol` | `otlp_protocol` | `OTLPProtocol` | `otlp_protocol` | `otlpProtocol` | `OtlpProtocol` | OTLP HTTP protocol for all signals: `"http/json"` or `"http/protobuf"` |
22302231
| File path | `filePath` | `file_path` | `FilePath` | `file_path` | `filePath` | `FilePath` | File path for JSON-lines trace output |
22312232
| Exporter type | `exporterType` | `exporter_type` | `ExporterType` | `exporter_type` | `exporterType` | `ExporterType` | `"otlp-http"` or `"file"` |
22322233
| Source name | `sourceName` | `source_name` | `SourceName` | `source_name` | `sourceName` | `SourceName` | Instrumentation scope name |
22332234
| Capture content | `captureContent` | `capture_content` | `CaptureContent` | `capture_content` | `captureContent` | `CaptureContent` | Whether to capture message content |
22342235

2236+
The OTLP protocol field configures the CLI's `"otlp-http"` exporter for all signals. Leave it unset to use the CLI default, or set it to `"http/protobuf"` to export protobuf over HTTP.
2237+
22352238
### File export
22362239

22372240
To write traces to a local file instead of an OTLP endpoint:

docs/observability/opentelemetry.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,11 +104,14 @@ let client = Client::start(ClientOptions::new()
104104
| Option | Node.js | Python | Go | .NET | Java | Rust | Description |
105105
|---|---|---|---|---|---|---|---|
106106
| OTLP endpoint | `otlpEndpoint` | `otlp_endpoint` | `OTLPEndpoint` | `OtlpEndpoint` | `otlpEndpoint` | `otlp_endpoint` | OTLP HTTP endpoint URL |
107+
| OTLP protocol | `otlpProtocol` | `otlp_protocol` | `OTLPProtocol` | `OtlpProtocol` | `otlpProtocol` | `otlp_protocol` | OTLP HTTP protocol for all signals: `"http/json"` or `"http/protobuf"` |
107108
| File path | `filePath` | `file_path` | `FilePath` | `FilePath` | `filePath` | `file_path` | File path for JSON-lines trace output |
108109
| Exporter type | `exporterType` | `exporter_type` | `ExporterType` | `ExporterType` | `exporterType` | `exporter_type` | `"otlp-http"` or `"file"` |
109110
| Source name | `sourceName` | `source_name` | `SourceName` | `SourceName` | `sourceName` | `source_name` | Instrumentation scope name |
110111
| Capture content | `captureContent` | `capture_content` | `CaptureContent` | `CaptureContent` | `captureContent` | `capture_content` | Whether to capture message content |
111112

113+
The OTLP protocol field configures the CLI's `"otlp-http"` exporter for all signals. Leave it unset to use the CLI default, or set it to `"http/protobuf"` to export protobuf over HTTP.
114+
112115
### Trace context propagation
113116

114117
> **Most users don't need this.** The `TelemetryConfig` above is all you need to collect traces from the CLI. The trace context propagation described in this section is an **advanced feature** for applications that create their own OpenTelemetry spans and want them to appear in the **same distributed trace** as the CLI's spans.

dotnet/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -752,6 +752,7 @@ var client = new CopilotClient(new CopilotClientOptions
752752
**TelemetryConfig properties:**
753753

754754
- `OtlpEndpoint` - OTLP HTTP endpoint URL
755+
- `OtlpProtocol` - OTLP HTTP protocol for all signals (`"http/json"` or `"http/protobuf"`)
755756
- `FilePath` - File path for JSON-lines trace output
756757
- `ExporterType` - `"otlp-http"` or `"file"`
757758
- `SourceName` - Instrumentation scope name

dotnet/src/Client.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1875,6 +1875,7 @@ private static bool IsUnsupportedConnectMethod(RemoteRpcException ex)
18751875
{
18761876
startInfo.Environment["COPILOT_OTEL_ENABLED"] = "true";
18771877
if (telemetry.OtlpEndpoint is not null) startInfo.Environment["OTEL_EXPORTER_OTLP_ENDPOINT"] = telemetry.OtlpEndpoint;
1878+
if (telemetry.OtlpProtocol is not null) startInfo.Environment["OTEL_EXPORTER_OTLP_PROTOCOL"] = telemetry.OtlpProtocol;
18781879
if (telemetry.FilePath is not null) startInfo.Environment["COPILOT_OTEL_FILE_EXPORTER_PATH"] = telemetry.FilePath;
18791880
if (telemetry.ExporterType is not null) startInfo.Environment["COPILOT_OTEL_EXPORTER_TYPE"] = telemetry.ExporterType;
18801881
if (telemetry.SourceName is not null) startInfo.Environment["COPILOT_OTEL_SOURCE_NAME"] = telemetry.SourceName;

dotnet/src/Types.cs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -413,6 +413,14 @@ public sealed class TelemetryConfig
413413
/// </remarks>
414414
public string? OtlpEndpoint { get; set; }
415415

416+
/// <summary>
417+
/// OTLP HTTP protocol for all signals (<c>"http/json"</c> or <c>"http/protobuf"</c>).
418+
/// </summary>
419+
/// <remarks>
420+
/// Maps to the <c>OTEL_EXPORTER_OTLP_PROTOCOL</c> environment variable.
421+
/// </remarks>
422+
public string? OtlpProtocol { get; set; }
423+
416424
/// <summary>
417425
/// File path for the file exporter.
418426
/// </summary>

dotnet/test/E2E/ClientOptionsE2ETests.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@ public async Task Should_Propagate_Process_Options_To_Spawned_Cli()
7878
Telemetry = new TelemetryConfig
7979
{
8080
OtlpEndpoint = "http://127.0.0.1:4318",
81+
OtlpProtocol = "http/protobuf",
8182
FilePath = telemetryPath,
8283
ExporterType = "file",
8384
SourceName = "dotnet-sdk-e2e",
@@ -104,6 +105,7 @@ public async Task Should_Propagate_Process_Options_To_Spawned_Cli()
104105
Assert.Equal("process-option-token", capturedEnv.GetProperty("COPILOT_SDK_AUTH_TOKEN").GetString());
105106
Assert.Equal("true", capturedEnv.GetProperty("COPILOT_OTEL_ENABLED").GetString());
106107
Assert.Equal("http://127.0.0.1:4318", capturedEnv.GetProperty("OTEL_EXPORTER_OTLP_ENDPOINT").GetString());
108+
Assert.Equal("http/protobuf", capturedEnv.GetProperty("OTEL_EXPORTER_OTLP_PROTOCOL").GetString());
107109
Assert.Equal(telemetryPath, capturedEnv.GetProperty("COPILOT_OTEL_FILE_EXPORTER_PATH").GetString());
108110
Assert.Equal("file", capturedEnv.GetProperty("COPILOT_OTEL_EXPORTER_TYPE").GetString());
109111
Assert.Equal("dotnet-sdk-e2e", capturedEnv.GetProperty("COPILOT_OTEL_SOURCE_NAME").GetString());
@@ -642,6 +644,7 @@ function saveCapture() {
642644
COPILOT_SDK_AUTH_TOKEN: process.env.COPILOT_SDK_AUTH_TOKEN,
643645
COPILOT_OTEL_ENABLED: process.env.COPILOT_OTEL_ENABLED,
644646
OTEL_EXPORTER_OTLP_ENDPOINT: process.env.OTEL_EXPORTER_OTLP_ENDPOINT,
647+
OTEL_EXPORTER_OTLP_PROTOCOL: process.env.OTEL_EXPORTER_OTLP_PROTOCOL,
645648
COPILOT_OTEL_FILE_EXPORTER_PATH: process.env.COPILOT_OTEL_FILE_EXPORTER_PATH,
646649
COPILOT_OTEL_EXPORTER_TYPE: process.env.COPILOT_OTEL_EXPORTER_TYPE,
647650
COPILOT_OTEL_SOURCE_NAME: process.env.COPILOT_OTEL_SOURCE_NAME,

dotnet/test/Unit/TelemetryTests.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ public void TelemetryConfig_DefaultValues_AreNull()
1616
var config = new TelemetryConfig();
1717

1818
Assert.Null(config.OtlpEndpoint);
19+
Assert.Null(config.OtlpProtocol);
1920
Assert.Null(config.FilePath);
2021
Assert.Null(config.ExporterType);
2122
Assert.Null(config.SourceName);
@@ -28,13 +29,15 @@ public void TelemetryConfig_CanSetAllProperties()
2829
var config = new TelemetryConfig
2930
{
3031
OtlpEndpoint = "http://localhost:4318",
32+
OtlpProtocol = "http/protobuf",
3133
FilePath = "/tmp/traces.json",
3234
ExporterType = "otlp-http",
3335
SourceName = "my-app",
3436
CaptureContent = true
3537
};
3638

3739
Assert.Equal("http://localhost:4318", config.OtlpEndpoint);
40+
Assert.Equal("http/protobuf", config.OtlpProtocol);
3841
Assert.Equal("/tmp/traces.json", config.FilePath);
3942
Assert.Equal("otlp-http", config.ExporterType);
4043
Assert.Equal("my-app", config.SourceName);

go/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -599,6 +599,7 @@ client, err := copilot.NewClient(copilot.ClientOptions{
599599
**TelemetryConfig fields:**
600600

601601
- `OTLPEndpoint` (string): OTLP HTTP endpoint URL
602+
- `OTLPProtocol` (string): OTLP HTTP protocol for all signals (`"http/json"` or `"http/protobuf"`)
602603
- `FilePath` (string): File path for JSON-lines trace output
603604
- `ExporterType` (string): `"otlp-http"` or `"file"`
604605
- `SourceName` (string): Instrumentation scope name

go/client.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1752,6 +1752,9 @@ func (c *Client) startCLIServer(ctx context.Context) error {
17521752
if t.OTLPEndpoint != "" {
17531753
c.process.Env = setEnvValue(c.process.Env, "OTEL_EXPORTER_OTLP_ENDPOINT", t.OTLPEndpoint)
17541754
}
1755+
if t.OTLPProtocol != "" {
1756+
c.process.Env = setEnvValue(c.process.Env, "OTEL_EXPORTER_OTLP_PROTOCOL", t.OTLPProtocol)
1757+
}
17551758
if t.FilePath != "" {
17561759
c.process.Env = setEnvValue(c.process.Env, "COPILOT_OTEL_FILE_EXPORTER_PATH", t.FilePath)
17571760
}

go/internal/e2e/client_options_e2e_test.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,7 @@ func TestClientOptionsE2E(t *testing.T) {
110110
opts.SessionIdleTimeoutSeconds = 17
111111
opts.Telemetry = &copilot.TelemetryConfig{
112112
OTLPEndpoint: "http://127.0.0.1:4318",
113+
OTLPProtocol: "http/protobuf",
113114
FilePath: telemetryPath,
114115
ExporterType: "file",
115116
SourceName: "go-sdk-e2e",
@@ -147,6 +148,7 @@ func TestClientOptionsE2E(t *testing.T) {
147148
"COPILOT_SDK_AUTH_TOKEN": "process-option-token",
148149
"COPILOT_OTEL_ENABLED": "true",
149150
"OTEL_EXPORTER_OTLP_ENDPOINT": "http://127.0.0.1:4318",
151+
"OTEL_EXPORTER_OTLP_PROTOCOL": "http/protobuf",
150152
"COPILOT_OTEL_FILE_EXPORTER_PATH": telemetryPath,
151153
"COPILOT_OTEL_EXPORTER_TYPE": "file",
152154
"COPILOT_OTEL_SOURCE_NAME": "go-sdk-e2e",
@@ -195,6 +197,7 @@ func TestClientOptionsE2E(t *testing.T) {
195197
t.Errorf("Expected session.create.params.includeSubAgentStreamingEvents=false, got %v", params["includeSubAgentStreamingEvents"])
196198
}
197199
})
200+
198201
}
199202

200203
// ---------------------------------------------------------------------------
@@ -372,6 +375,7 @@ function saveCapture() {
372375
COPILOT_SDK_AUTH_TOKEN: process.env.COPILOT_SDK_AUTH_TOKEN,
373376
COPILOT_OTEL_ENABLED: process.env.COPILOT_OTEL_ENABLED,
374377
OTEL_EXPORTER_OTLP_ENDPOINT: process.env.OTEL_EXPORTER_OTLP_ENDPOINT,
378+
OTEL_EXPORTER_OTLP_PROTOCOL: process.env.OTEL_EXPORTER_OTLP_PROTOCOL,
375379
COPILOT_OTEL_FILE_EXPORTER_PATH: process.env.COPILOT_OTEL_FILE_EXPORTER_PATH,
376380
COPILOT_OTEL_EXPORTER_TYPE: process.env.COPILOT_OTEL_EXPORTER_TYPE,
377381
COPILOT_OTEL_SOURCE_NAME: process.env.COPILOT_OTEL_SOURCE_NAME,

0 commit comments

Comments
 (0)