Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
microsoft
GitHub Repository: microsoft/vscode
Path: blob/main/extensions/copilot/src/platform/otel/common/agentOTelEnv.ts
13401 views
1
/*---------------------------------------------------------------------------------------------
2
* Copyright (c) Microsoft Corporation. All rights reserved.
3
* Licensed under the MIT License. See License.txt in the project root for license information.
4
*--------------------------------------------------------------------------------------------*/
5
6
import type { OTelConfig } from './otelConfig';
7
8
/**
9
* Derives environment variables for the Copilot CLI SDK from the extension's
10
* resolved OTel configuration. Only sets variables that are not already present
11
* in `process.env`, so explicit user env vars serve as per-agent overrides.
12
*
13
* Used for both the in-process `LocalSessionManager` (spread into `process.env`)
14
* and the terminal CLI session (spread into `TerminalOptions.env`).
15
*/
16
export function deriveCopilotCliOTelEnv(config: OTelConfig, env: Record<string, string | undefined> = process.env): Record<string, string> {
17
if (!config.enabled) {
18
return {};
19
}
20
21
const result: Record<string, string> = {};
22
23
if (!env['COPILOT_OTEL_ENABLED']) {
24
result['COPILOT_OTEL_ENABLED'] = 'true';
25
}
26
if (!env['OTEL_EXPORTER_OTLP_ENDPOINT'] && config.otlpEndpoint) {
27
result['OTEL_EXPORTER_OTLP_ENDPOINT'] = config.otlpEndpoint;
28
}
29
if (!env['OTEL_INSTRUMENTATION_GENAI_CAPTURE_MESSAGE_CONTENT'] && config.captureContent) {
30
result['OTEL_INSTRUMENTATION_GENAI_CAPTURE_MESSAGE_CONTENT'] = 'true';
31
}
32
if (!env['COPILOT_OTEL_FILE_EXPORTER_PATH'] && config.fileExporterPath) {
33
result['COPILOT_OTEL_FILE_EXPORTER_PATH'] = config.fileExporterPath;
34
}
35
if (!env['COPILOT_OTEL_EXPORTER_TYPE'] && config.exporterType === 'file') {
36
result['COPILOT_OTEL_EXPORTER_TYPE'] = 'file';
37
}
38
// Note: Copilot CLI runtime only supports otlp-http (not gRPC).
39
// The OTEL_EXPORTER_OTLP_ENDPOINT is used with the HTTP protocol regardless.
40
// Standard vars (OTEL_EXPORTER_OTLP_HEADERS, OTEL_RESOURCE_ATTRIBUTES, OTEL_SERVICE_NAME)
41
// flow via process.env inheritance — no explicit forwarding needed.
42
43
return result;
44
}
45
46
/**
47
* Derives environment variables for the Claude Code subprocess from the
48
* extension's resolved OTel configuration. Claude uses different env var names
49
* than the Copilot CLI SDK.
50
*
51
* Only sets variables not already present in `process.env`.
52
*/
53
export function deriveClaudeOTelEnv(config: OTelConfig, env: Record<string, string | undefined> = process.env): Record<string, string> {
54
if (!config.enabled) {
55
return {};
56
}
57
58
const result: Record<string, string> = {};
59
60
if (!env['CLAUDE_CODE_ENABLE_TELEMETRY']) {
61
result['CLAUDE_CODE_ENABLE_TELEMETRY'] = '1';
62
}
63
if (!env['OTEL_METRICS_EXPORTER']) {
64
result['OTEL_METRICS_EXPORTER'] = 'otlp';
65
}
66
if (!env['OTEL_LOGS_EXPORTER']) {
67
result['OTEL_LOGS_EXPORTER'] = 'otlp';
68
}
69
if (!env['OTEL_EXPORTER_OTLP_ENDPOINT'] && config.otlpEndpoint) {
70
result['OTEL_EXPORTER_OTLP_ENDPOINT'] = config.otlpEndpoint;
71
}
72
if (!env['OTEL_EXPORTER_OTLP_PROTOCOL']) {
73
result['OTEL_EXPORTER_OTLP_PROTOCOL'] = config.otlpProtocol === 'grpc' ? 'grpc' : 'http/json';
74
}
75
if (config.captureContent) {
76
if (!env['OTEL_LOG_USER_PROMPTS']) {
77
result['OTEL_LOG_USER_PROMPTS'] = '1';
78
}
79
if (!env['OTEL_LOG_TOOL_DETAILS']) {
80
result['OTEL_LOG_TOOL_DETAILS'] = '1';
81
}
82
}
83
// Claude SDK has no file exporter — skip fileExporterPath.
84
// Standard vars (OTEL_EXPORTER_OTLP_HEADERS, OTEL_RESOURCE_ATTRIBUTES) flow via inheritance.
85
86
return result;
87
}
88
89