참고
코필로트 SDK가 현재 기술 미리 보기에 있습니다. 기능 및 가용성은 변경될 수 있습니다.
GitHub Copilot SDK 는 CLI 프로세스에서 OpenTelemetry를 구성하고 SDK와 CLI 간에 W3C 추적 컨텍스트를 전파하기 위한 기본 제공 지원을 제공합니다.
Python, Go 및 .NET의 예제는 github/copilot-sdk를 참조하세요.
기본 제공 원격 분석 지원
원격 분석에 참여하려면 클라이언트를 만들 때 TelemetryConfig를 제공하세요.
import { CopilotClient } from "@github/copilot-sdk";
const client = new CopilotClient({
telemetry: {
otlpEndpoint: "http://localhost:4318",
},
});
import { CopilotClient } from "@github/copilot-sdk";
const client = new CopilotClient({
telemetry: {
otlpEndpoint: "http://localhost:4318",
},
});
'TelemetryConfig' 설정 옵션
| Option | Node.JS | 설명 |
|---|---|---|
| OTLP 엔드포인트 | otlpEndpoint | OTLP HTTP 엔드포인트 URL |
| 파일 경로 | filePath | JSON 줄 추적 출력에 대한 파일 경로 |
| 내보내기 형식 | exporterType |
`"otlp-http"` 또는 `"file"` |
| 원본 이름 | sourceName | 계측 범위 이름 |
| 콘텐츠 캡처 | captureContent | 메시지 콘텐츠를 캡처할지 여부 |
추적 컨텍스트 전파
참고
대부분의 사용자는 이 작업을 필요로 하지 않습니다. 위의 TelemetryConfig이 CLI에서 추적을 수집하는 데 필요한 전부입니다. 추적 컨텍스트 전파는 자체 OpenTelemetry 범위를 만들고 CLI의 범위와 동일한 분산 추적에 표시하려는 애플리케이션에 대한 고급 기능입니다.
SDK는 JSON-RPC 페이로드에서 W3C 추적 컨텍스트(traceparent/tracestate)를 전파하여 애플리케이션의 범위와 CLI 범위가 하나의 분산 추적에 연결되도록 할 수 있습니다. 예를 들어 SDK 호출을 요청 처리 범위의 자식으로 표시하려는 경우에 유용합니다.
세션 흐름의 자세한 시퀀스 다이어그램은 github/copilot-sdk를 참조하세요.
SDK에서 CLI로(아웃바운드)
클라이언트 옵션에 대한 onGetTraceContext 콜백을 제공합니다. 이는 애플리케이션이 이미 사용 @opentelemetry/api 중이고 범위를 CLI의 범위와 연결하려는 경우에만 필요합니다. SDK는 이 콜백을 session.create, session.resume, session.send RPC 전에 호출합니다.
import { CopilotClient } from "@github/copilot-sdk";
import { propagation, context } from "@opentelemetry/api";
const client = new CopilotClient({
telemetry: { otlpEndpoint: "http://localhost:4318" },
onGetTraceContext: () => {
const carrier: Record<string, string> = {};
propagation.inject(context.active(), carrier);
return carrier; // { traceparent: "00-...", tracestate: "..." }
},
});
import { CopilotClient } from "@github/copilot-sdk";
import { propagation, context } from "@opentelemetry/api";
const client = new CopilotClient({
telemetry: { otlpEndpoint: "http://localhost:4318" },
onGetTraceContext: () => {
const carrier: Record<string, string> = {};
propagation.inject(context.active(), carrier);
return carrier; // { traceparent: "00-...", tracestate: "..." }
},
});
CLI에서 SDK로(인바운드)
CLI가 도구 처리기를 호출할 때, CLI의 범위에 있는 traceparent 및 tracestate을 사용할 수 있습니다. SDK에는 OpenTelemetry 종속성이 없으므로 개체에 ToolInvocation 원시 문자열로 전달됩니다. 필요한 경우 컨텍스트를 수동으로 복원합니다.
import { propagation, context, trace } from "@opentelemetry/api";
session.registerTool(myTool, async (args, invocation) => {
// Restore the CLI's trace context as the active context
const carrier = {
traceparent: invocation.traceparent,
tracestate: invocation.tracestate,
};
const parentCtx = propagation.extract(context.active(), carrier);
// Create a child span under the CLI's span
const tracer = trace.getTracer("my-app");
return context.with(parentCtx, () =>
tracer.startActiveSpan("my-tool", async (span) => {
try {
const result = await doWork(args);
return result;
} finally {
span.end();
}
})
);
});
import { propagation, context, trace } from "@opentelemetry/api";
session.registerTool(myTool, async (args, invocation) => {
// Restore the CLI's trace context as the active context
const carrier = {
traceparent: invocation.traceparent,
tracestate: invocation.tracestate,
};
const parentCtx = propagation.extract(context.active(), carrier);
// Create a child span under the CLI's span
const tracer = trace.getTracer("my-app");
return context.with(parentCtx, () =>
tracer.startActiveSpan("my-tool", async (span) => {
try {
const result = await doWork(args);
return result;
} finally {
span.end();
}
})
);
});
추가 읽기
-
[OpenTelemetry 설명서의 OpenTelemetry GenAI 의미 체계 규칙](https://opentelemetry.io/docs/specs/semconv/gen-ai/) -
[OpenTelemetry 설명서의 OpenTelemetry MCP 의미 체계 규칙](https://opentelemetry.io/docs/specs/semconv/gen-ai/mcp/) -
[OpenTelemetry 설명서의 OpenTelemetry Python SDK](https://opentelemetry.io/docs/instrumentation/python/)