豆豆友情提示:这是一个非官方 GitHub 代理镜像,主要用于网络测试或访问加速。请勿在此进行登录、注册或处理任何敏感信息。进行这些操作请务必访问官方网站 github.com。 Raw 内容也通过此代理提供。
Skip to content

Commit 27e0fe8

Browse files
committed
build break and bad span export shape in src/platform/otel/node/fileExporters.ts:20-35.
serializeSpan() is using old OTel v1 ReadableSpan fields: span.instrumentationLibrary and span.parentSpanId. This repo resolves ReadableSpan from OTel v2, where those are instrumentationScope and parentSpanContext (node_modules/@opentelemetry/sdk-trace-node/node_modules/@opentelemetry/sdk-trace-base/build/src/export/ReadableSpan.d.ts:5-23).
1 parent e9819e2 commit 27e0fe8

File tree

2 files changed

+8
-5
lines changed

2 files changed

+8
-5
lines changed

src/platform/otel/node/fileExporters.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,12 +26,12 @@ function serializeSpan(span: ReadableSpan): Record<string, unknown> {
2626
resource: {
2727
attributes: span.resource.attributes,
2828
},
29-
instrumentationScope: span.instrumentationLibrary,
29+
instrumentationScope: span.instrumentationScope,
3030
traceId: spanContext.traceId,
3131
spanId: spanContext.spanId,
3232
traceFlags: spanContext.traceFlags,
3333
traceState: spanContext.traceState?.serialize(),
34-
parentSpanId: span.parentSpanId,
34+
parentSpanId: span.parentSpanContext?.spanId,
3535
name: span.name,
3636
kind: span.kind,
3737
startTime: span.startTime,

src/platform/otel/node/test/fileExporters.spec.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -58,17 +58,18 @@ describe('FileSpanExporter', () => {
5858
class FakeReadableSpan {
5959
readonly #ctx = { traceId: 'trace-id', spanId: 'span-id', traceFlags: 1, traceState: undefined };
6060
readonly #resource = { attributes: { 'service.name': 'copilot-chat' } };
61-
readonly #instrumentationLibrary = { name: 'copilot-chat', version: '0.44.0' };
61+
readonly #instrumentationScope = { name: 'copilot-chat', version: '0.44.0' };
6262
readonly #status = { code: 1 };
6363
readonly #attributes = { a: 1 };
6464
readonly #links: unknown[] = [];
6565
readonly #events: unknown[] = [];
6666
readonly #time: [number, number] = [1, 2];
67+
readonly #parentSpanContext = { traceId: 'trace-id', spanId: 'parent-span-id', traceFlags: 1, traceState: undefined };
6768

6869
spanContext() { return this.#ctx; }
6970
get resource() { return this.#resource; }
70-
get instrumentationLibrary() { return this.#instrumentationLibrary; }
71-
get parentSpanId() { return undefined; }
71+
get instrumentationScope() { return this.#instrumentationScope; }
72+
get parentSpanContext() { return this.#parentSpanContext; }
7273
get name() { return 'hidden-span'; }
7374
get kind() { return 0; }
7475
get startTime() { return this.#time; }
@@ -96,6 +97,8 @@ describe('FileSpanExporter', () => {
9697
const parsed = JSON.parse(content.trim());
9798
expect(parsed.name).toBe('hidden-span');
9899
expect(parsed.traceId).toBe('trace-id');
100+
expect(parsed.parentSpanId).toBe('parent-span-id');
101+
expect(parsed.instrumentationScope).toEqual({ name: 'copilot-chat', version: '0.44.0' });
99102
expect(parsed.resource.attributes).toEqual({ 'service.name': 'copilot-chat' });
100103
expect(parsed.attributes).toEqual({ a: 1 });
101104
});

0 commit comments

Comments
 (0)