From 80b92867fb539bc5e6446f68f29a9c9e718f8d92 Mon Sep 17 00:00:00 2001 From: nikhilmantri0902 Date: Fri, 5 Sep 2025 09:38:25 +0530 Subject: [PATCH 1/6] fixed the isremote exporter flag passing --- .../src/trace/internal-types.ts | 6 ++ .../otlp-transformer/src/trace/internal.ts | 20 ++++- .../otlp-transformer/test/trace.test.ts | 74 +++++++++++++++++++ 3 files changed, 99 insertions(+), 1 deletion(-) diff --git a/experimental/packages/otlp-transformer/src/trace/internal-types.ts b/experimental/packages/otlp-transformer/src/trace/internal-types.ts index 75b9c21e260..cafd2ba820d 100644 --- a/experimental/packages/otlp-transformer/src/trace/internal-types.ts +++ b/experimental/packages/otlp-transformer/src/trace/internal-types.ts @@ -97,6 +97,9 @@ export interface ISpan { /** Span status */ status: IStatus; + + /** Span flags */ + flags?: number; } /** @@ -185,4 +188,7 @@ export interface ILink { /** Link droppedAttributesCount */ droppedAttributesCount: number; + + /** Link flags */ + flags?: number; } diff --git a/experimental/packages/otlp-transformer/src/trace/internal.ts b/experimental/packages/otlp-transformer/src/trace/internal.ts index d9a517401d6..4547db8f14d 100644 --- a/experimental/packages/otlp-transformer/src/trace/internal.ts +++ b/experimental/packages/otlp-transformer/src/trace/internal.ts @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -import type { Link } from '@opentelemetry/api'; +import type { Link, SpanContext } from '@opentelemetry/api'; import { Resource } from '@opentelemetry/resources'; import type { ReadableSpan, TimedEvent } from '@opentelemetry/sdk-trace-base'; import type { Encoder } from '../common/utils'; @@ -34,6 +34,22 @@ import { import { OtlpEncodingOptions } from '../common/internal-types'; import { getOtlpEncoder } from '../common/utils'; +// Span flags constants matching the OTLP specification +const SPAN_FLAGS_CONTEXT_HAS_IS_REMOTE_MASK = 0x100; +const SPAN_FLAGS_CONTEXT_IS_REMOTE_MASK = 0x200; + +/** + * Builds span flags based on the parent span context's isRemote property. + * This follows the OTLP specification for span flags. + */ +function buildSpanFlags(parentSpanContext?: SpanContext): number { + let flags = SPAN_FLAGS_CONTEXT_HAS_IS_REMOTE_MASK; + if (parentSpanContext?.isRemote) { + flags |= SPAN_FLAGS_CONTEXT_IS_REMOTE_MASK; + } + return flags; +} + export function sdkSpanToOtlpSpan(span: ReadableSpan, encoder: Encoder): ISpan { const ctx = span.spanContext(); const status = span.status; @@ -61,6 +77,7 @@ export function sdkSpanToOtlpSpan(span: ReadableSpan, encoder: Encoder): ISpan { }, links: span.links.map(link => toOtlpLink(link, encoder)), droppedLinksCount: span.droppedLinksCount, + flags: buildSpanFlags(span.parentSpanContext), }; } @@ -71,6 +88,7 @@ export function toOtlpLink(link: Link, encoder: Encoder): ILink { traceId: encoder.encodeSpanContext(link.context.traceId), traceState: link.context.traceState?.serialize(), droppedAttributesCount: link.droppedAttributesCount || 0, + flags: buildSpanFlags(link.context), }; } diff --git a/experimental/packages/otlp-transformer/test/trace.test.ts b/experimental/packages/otlp-transformer/test/trace.test.ts index f76ea753f24..bacadaaf0c0 100644 --- a/experimental/packages/otlp-transformer/test/trace.test.ts +++ b/experimental/packages/otlp-transformer/test/trace.test.ts @@ -97,6 +97,7 @@ function createExpectedSpanJson(options: OtlpEncodingOptions) { }, }, ], + flags: 0x100, // SPAN_FLAGS_CONTEXT_HAS_IS_REMOTE_MASK }, ], startTimeUnixNano: startTime, @@ -129,6 +130,7 @@ function createExpectedSpanJson(options: OtlpEncodingOptions) { code: EStatusCode.STATUS_CODE_OK, message: undefined, }, + flags: 0x100, // SPAN_FLAGS_CONTEXT_HAS_IS_REMOTE_MASK }, ], schemaUrl: 'http://url.to.schema', @@ -187,6 +189,7 @@ function createExpectedSpanProtobuf() { }, }, ], + flags: 0x100, // SPAN_FLAGS_CONTEXT_HAS_IS_REMOTE_MASK }, ], startTimeUnixNano: startTime, @@ -218,6 +221,7 @@ function createExpectedSpanProtobuf() { status: { code: EStatusCode.STATUS_CODE_OK, }, + flags: 0x100, // SPAN_FLAGS_CONTEXT_HAS_IS_REMOTE_MASK }, ], schemaUrl: 'http://url.to.schema', @@ -574,4 +578,74 @@ describe('Trace', () => { ); }); }); + + describe('span flags', () => { + it('sets flags to 0x100 for local parent span context', () => { + const exportRequest = createExportTraceServiceRequest([span], { + useHex: true, + }); + assert.ok(exportRequest); + const spanFlags = exportRequest.resourceSpans?.[0].scopeSpans[0].spans?.[0].flags; + assert.strictEqual(spanFlags, 0x100); // SPAN_FLAGS_CONTEXT_HAS_IS_REMOTE_MASK + }); + + it('sets flags to 0x300 for remote parent span context', () => { + // Create a span with a remote parent context + const remoteParentSpanContext = { + spanId: '0000000000000001', + traceId: '00000000000000000000000000000001', + traceFlags: TraceFlags.SAMPLED, + isRemote: true, // This is the key difference + }; + + const spanWithRemoteParent = { + ...span, + parentSpanContext: remoteParentSpanContext, + }; + + const exportRequest = createExportTraceServiceRequest([spanWithRemoteParent], { + useHex: true, + }); + assert.ok(exportRequest); + const spanFlags = exportRequest.resourceSpans?.[0].scopeSpans[0].spans?.[0].flags; + assert.strictEqual(spanFlags, 0x300); // SPAN_FLAGS_CONTEXT_HAS_IS_REMOTE_MASK | SPAN_FLAGS_CONTEXT_IS_REMOTE_MASK + }); + + it('sets flags to 0x100 for links with local context', () => { + const exportRequest = createExportTraceServiceRequest([span], { + useHex: true, + }); + assert.ok(exportRequest); + const linkFlags = exportRequest.resourceSpans?.[0].scopeSpans[0].spans?.[0].links?.[0].flags; + assert.strictEqual(linkFlags, 0x100); // SPAN_FLAGS_CONTEXT_HAS_IS_REMOTE_MASK + }); + + it('sets flags to 0x300 for links with remote context', () => { + // Create a span with a remote link context + const remoteLinkContext = { + spanId: '0000000000000003', + traceId: '00000000000000000000000000000002', + traceFlags: TraceFlags.SAMPLED, + isRemote: true, // This is the key difference + }; + + const remoteLink = { + context: remoteLinkContext, + attributes: { 'link-attribute': 'string value' }, + droppedAttributesCount: 0, + }; + + const spanWithRemoteLink = { + ...span, + links: [remoteLink], + }; + + const exportRequest = createExportTraceServiceRequest([spanWithRemoteLink], { + useHex: true, + }); + assert.ok(exportRequest); + const linkFlags = exportRequest.resourceSpans?.[0].scopeSpans[0].spans?.[0].links?.[0].flags; + assert.strictEqual(linkFlags, 0x300); // SPAN_FLAGS_CONTEXT_HAS_IS_REMOTE_MASK | SPAN_FLAGS_CONTEXT_IS_REMOTE_MASK + }); + }); }); From 93f9f2ff4d672fc3d103eff2944e966e02969249 Mon Sep 17 00:00:00 2001 From: nikhilmantri0902 Date: Fri, 5 Sep 2025 12:36:50 +0530 Subject: [PATCH 2/6] chore(changelog): added feature entry --- CHANGELOG.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 8827c622551..fd8aa540f9c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -14,6 +14,8 @@ For notes on migrating to 2.x / 0.200.x see [the upgrade guide](doc/upgrade-to-2 ### :rocket: Features +* feat(otlp-transformer): add span flags support for isRemote property [#5910](https://github.com/open-telemetry/opentelemetry-js/pull/5910) @nikhilmantri0902 + ### :bug: Bug Fixes ### :books: Documentation From ebf64bcb90712906937b1fe81a2663fbff8b2fba Mon Sep 17 00:00:00 2001 From: nikhilmantri0902 Date: Thu, 18 Sep 2025 21:05:19 +0530 Subject: [PATCH 3/6] chore: added functionality for constructing full trace flags with lower bits as well --- .../otlp-transformer/src/trace/internal.ts | 17 ++++++------- .../otlp-transformer/test/trace.test.ts | 24 +++++++++---------- 2 files changed, 21 insertions(+), 20 deletions(-) diff --git a/experimental/packages/otlp-transformer/src/trace/internal.ts b/experimental/packages/otlp-transformer/src/trace/internal.ts index 4547db8f14d..cbfef6f28d1 100644 --- a/experimental/packages/otlp-transformer/src/trace/internal.ts +++ b/experimental/packages/otlp-transformer/src/trace/internal.ts @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -import type { Link, SpanContext } from '@opentelemetry/api'; +import type { Link } from '@opentelemetry/api'; import { Resource } from '@opentelemetry/resources'; import type { ReadableSpan, TimedEvent } from '@opentelemetry/sdk-trace-base'; import type { Encoder } from '../common/utils'; @@ -39,12 +39,13 @@ const SPAN_FLAGS_CONTEXT_HAS_IS_REMOTE_MASK = 0x100; const SPAN_FLAGS_CONTEXT_IS_REMOTE_MASK = 0x200; /** - * Builds span flags based on the parent span context's isRemote property. - * This follows the OTLP specification for span flags. + * Builds the 32-bit span flags value combining the low 8-bit W3C TraceFlags + * with the HAS_IS_REMOTE and IS_REMOTE bits according to the OTLP spec. */ -function buildSpanFlags(parentSpanContext?: SpanContext): number { - let flags = SPAN_FLAGS_CONTEXT_HAS_IS_REMOTE_MASK; - if (parentSpanContext?.isRemote) { +function buildSpanFlagsFrom(traceFlags: number, isRemote?: boolean): number { + // low 8 bits are W3C TraceFlags (e.g., sampled) + let flags = (traceFlags & 0xff) | SPAN_FLAGS_CONTEXT_HAS_IS_REMOTE_MASK; + if (isRemote) { flags |= SPAN_FLAGS_CONTEXT_IS_REMOTE_MASK; } return flags; @@ -77,7 +78,7 @@ export function sdkSpanToOtlpSpan(span: ReadableSpan, encoder: Encoder): ISpan { }, links: span.links.map(link => toOtlpLink(link, encoder)), droppedLinksCount: span.droppedLinksCount, - flags: buildSpanFlags(span.parentSpanContext), + flags: buildSpanFlagsFrom(ctx.traceFlags, span.parentSpanContext?.isRemote), }; } @@ -88,7 +89,7 @@ export function toOtlpLink(link: Link, encoder: Encoder): ILink { traceId: encoder.encodeSpanContext(link.context.traceId), traceState: link.context.traceState?.serialize(), droppedAttributesCount: link.droppedAttributesCount || 0, - flags: buildSpanFlags(link.context), + flags: buildSpanFlagsFrom(link.context.traceFlags, link.context.isRemote), }; } diff --git a/experimental/packages/otlp-transformer/test/trace.test.ts b/experimental/packages/otlp-transformer/test/trace.test.ts index bacadaaf0c0..dc237425b09 100644 --- a/experimental/packages/otlp-transformer/test/trace.test.ts +++ b/experimental/packages/otlp-transformer/test/trace.test.ts @@ -97,7 +97,7 @@ function createExpectedSpanJson(options: OtlpEncodingOptions) { }, }, ], - flags: 0x100, // SPAN_FLAGS_CONTEXT_HAS_IS_REMOTE_MASK + flags: 0x101, // TraceFlags (0x01) | HAS_IS_REMOTE }, ], startTimeUnixNano: startTime, @@ -130,7 +130,7 @@ function createExpectedSpanJson(options: OtlpEncodingOptions) { code: EStatusCode.STATUS_CODE_OK, message: undefined, }, - flags: 0x100, // SPAN_FLAGS_CONTEXT_HAS_IS_REMOTE_MASK + flags: 0x101, // TraceFlags (0x01) | HAS_IS_REMOTE }, ], schemaUrl: 'http://url.to.schema', @@ -189,7 +189,7 @@ function createExpectedSpanProtobuf() { }, }, ], - flags: 0x100, // SPAN_FLAGS_CONTEXT_HAS_IS_REMOTE_MASK + flags: 0x101, // TraceFlags (0x01) | HAS_IS_REMOTE }, ], startTimeUnixNano: startTime, @@ -221,7 +221,7 @@ function createExpectedSpanProtobuf() { status: { code: EStatusCode.STATUS_CODE_OK, }, - flags: 0x100, // SPAN_FLAGS_CONTEXT_HAS_IS_REMOTE_MASK + flags: 0x101, // TraceFlags (0x01) | HAS_IS_REMOTE }, ], schemaUrl: 'http://url.to.schema', @@ -580,16 +580,16 @@ describe('Trace', () => { }); describe('span flags', () => { - it('sets flags to 0x100 for local parent span context', () => { + it('sets flags to 0x101 for local parent span context', () => { const exportRequest = createExportTraceServiceRequest([span], { useHex: true, }); assert.ok(exportRequest); const spanFlags = exportRequest.resourceSpans?.[0].scopeSpans[0].spans?.[0].flags; - assert.strictEqual(spanFlags, 0x100); // SPAN_FLAGS_CONTEXT_HAS_IS_REMOTE_MASK + assert.strictEqual(spanFlags, 0x101); // TraceFlags (0x01) | HAS_IS_REMOTE }); - it('sets flags to 0x300 for remote parent span context', () => { + it('sets flags to 0x301 for remote parent span context', () => { // Create a span with a remote parent context const remoteParentSpanContext = { spanId: '0000000000000001', @@ -608,19 +608,19 @@ describe('Trace', () => { }); assert.ok(exportRequest); const spanFlags = exportRequest.resourceSpans?.[0].scopeSpans[0].spans?.[0].flags; - assert.strictEqual(spanFlags, 0x300); // SPAN_FLAGS_CONTEXT_HAS_IS_REMOTE_MASK | SPAN_FLAGS_CONTEXT_IS_REMOTE_MASK + assert.strictEqual(spanFlags, 0x301); // TraceFlags (0x01) | HAS_IS_REMOTE | IS_REMOTE }); - it('sets flags to 0x100 for links with local context', () => { + it('sets flags to 0x101 for links with local context', () => { const exportRequest = createExportTraceServiceRequest([span], { useHex: true, }); assert.ok(exportRequest); const linkFlags = exportRequest.resourceSpans?.[0].scopeSpans[0].spans?.[0].links?.[0].flags; - assert.strictEqual(linkFlags, 0x100); // SPAN_FLAGS_CONTEXT_HAS_IS_REMOTE_MASK + assert.strictEqual(linkFlags, 0x101); // TraceFlags (0x01) | HAS_IS_REMOTE }); - it('sets flags to 0x300 for links with remote context', () => { + it('sets flags to 0x301 for links with remote context', () => { // Create a span with a remote link context const remoteLinkContext = { spanId: '0000000000000003', @@ -645,7 +645,7 @@ describe('Trace', () => { }); assert.ok(exportRequest); const linkFlags = exportRequest.resourceSpans?.[0].scopeSpans[0].spans?.[0].links?.[0].flags; - assert.strictEqual(linkFlags, 0x300); // SPAN_FLAGS_CONTEXT_HAS_IS_REMOTE_MASK | SPAN_FLAGS_CONTEXT_IS_REMOTE_MASK + assert.strictEqual(linkFlags, 0x301); // TraceFlags (0x01) | HAS_IS_REMOTE | IS_REMOTE }); }); }); From 7f9668520e1ad69aafd762328fadec83620cd99d Mon Sep 17 00:00:00 2001 From: nikhilmantri0902 Date: Thu, 18 Sep 2025 21:16:42 +0530 Subject: [PATCH 4/6] chore: added test cases to conver all flag combinations --- .../otlp-transformer/test/trace.test.ts | 100 ++++++++++++++++++ 1 file changed, 100 insertions(+) diff --git a/experimental/packages/otlp-transformer/test/trace.test.ts b/experimental/packages/otlp-transformer/test/trace.test.ts index dc237425b09..8f42ee2d3e3 100644 --- a/experimental/packages/otlp-transformer/test/trace.test.ts +++ b/experimental/packages/otlp-transformer/test/trace.test.ts @@ -648,4 +648,104 @@ describe('Trace', () => { assert.strictEqual(linkFlags, 0x301); // TraceFlags (0x01) | HAS_IS_REMOTE | IS_REMOTE }); }); + + describe('span/link flags matrix', () => { + const cases = [ + { tf: 0x00, local: 0x100, remote: 0x300 }, + { tf: 0x01, local: 0x101, remote: 0x301 }, + { tf: 0x05, local: 0x105, remote: 0x305 }, + { tf: 0xff, local: 0x1ff, remote: 0x3ff }, + ]; + + it('composes span flags with local and remote parent across traceFlags', () => { + const baseCtx = span.spanContext(); + for (const c of cases) { + // Local parent + const spanLocal = { + ...span, + spanContext: () => ({ + spanId: baseCtx.spanId, + traceId: baseCtx.traceId, + traceFlags: c.tf, + isRemote: false, + traceState: baseCtx.traceState, + }), + parentSpanContext: { + ...span.parentSpanContext, + isRemote: false, + }, + } as unknown as ReadableSpan; + const reqLocal = createExportTraceServiceRequest([spanLocal], { useHex: true }); + const spanFlagsLocal = reqLocal.resourceSpans?.[0].scopeSpans[0].spans?.[0].flags; + assert.strictEqual(spanFlagsLocal, c.local); + + // Remote parent + const spanRemote = { + ...spanLocal, + parentSpanContext: { + ...span.parentSpanContext, + isRemote: true, + }, + } as unknown as ReadableSpan; + const reqRemote = createExportTraceServiceRequest([spanRemote], { useHex: true }); + const spanFlagsRemote = reqRemote.resourceSpans?.[0].scopeSpans[0].spans?.[0].flags; + assert.strictEqual(spanFlagsRemote, c.remote); + } + }); + + it('composes link flags with local and remote context across traceFlags', () => { + for (const c of cases) { + const linkLocal = { + context: { + spanId: '0000000000000003', + traceId: '00000000000000000000000000000002', + traceFlags: c.tf, + isRemote: false, + traceState: new TraceState('link=foo'), + }, + attributes: { 'link-attribute': 'string value' }, + droppedAttributesCount: 0, + }; + const spanWithLocalLink = { + ...span, + links: [linkLocal], + } as unknown as ReadableSpan; + const reqLocal = createExportTraceServiceRequest([spanWithLocalLink], { useHex: true }); + const linkFlagsLocal = reqLocal.resourceSpans?.[0].scopeSpans[0].spans?.[0].links?.[0].flags; + assert.strictEqual(linkFlagsLocal, c.local); + + const linkRemote = { + ...linkLocal, + context: { ...linkLocal.context, isRemote: true }, + }; + const spanWithRemoteLink = { + ...span, + links: [linkRemote], + } as unknown as ReadableSpan; + const reqRemote = createExportTraceServiceRequest([spanWithRemoteLink], { useHex: true }); + const linkFlagsRemote = reqRemote.resourceSpans?.[0].scopeSpans[0].spans?.[0].links?.[0].flags; + assert.strictEqual(linkFlagsRemote, c.remote); + } + }); + + it('composes root span flags across traceFlags (no parent)', () => { + const baseCtx = span.spanContext(); + for (const c of cases) { + const rootSpan = { + ...span, + spanContext: () => ({ + spanId: baseCtx.spanId, + traceId: baseCtx.traceId, + traceFlags: c.tf, + isRemote: false, + traceState: baseCtx.traceState, + }), + parentSpanContext: undefined, + } as unknown as ReadableSpan; + const req = createExportTraceServiceRequest([rootSpan], { useHex: true }); + const flags = req.resourceSpans?.[0].scopeSpans[0].spans?.[0].flags; + assert.strictEqual(flags, c.local); + } + }); + }); }); From 625c37cfd0bd3e12f928ac5898877a7b77ebcaf3 Mon Sep 17 00:00:00 2001 From: nikhilmantri0902 Date: Mon, 22 Sep 2025 15:31:43 +0530 Subject: [PATCH 5/6] chore: moved entry of changelog to experimental/changelog.md --- CHANGELOG.md | 2 -- experimental/CHANGELOG.md | 2 ++ 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index fd8aa540f9c..8827c622551 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -14,8 +14,6 @@ For notes on migrating to 2.x / 0.200.x see [the upgrade guide](doc/upgrade-to-2 ### :rocket: Features -* feat(otlp-transformer): add span flags support for isRemote property [#5910](https://github.com/open-telemetry/opentelemetry-js/pull/5910) @nikhilmantri0902 - ### :bug: Bug Fixes ### :books: Documentation diff --git a/experimental/CHANGELOG.md b/experimental/CHANGELOG.md index 978ca31b371..5e591764ea5 100644 --- a/experimental/CHANGELOG.md +++ b/experimental/CHANGELOG.md @@ -10,6 +10,8 @@ For notes on migrating to 2.x / 0.200.x see [the upgrade guide](doc/upgrade-to-2 ### :rocket: Features +* feat(otlp-transformer): add span flags support for isRemote property [#5910](https://github.com/open-telemetry/opentelemetry-js/pull/5910) @nikhilmantri0902 + ### :bug: Bug Fixes * fix(instrumentation-http): respect requireParent flag when INVALID_SPAN_CONTEXT is used [#4788](https://github.com/open-telemetry/opentelemetry-js/pull/4788) @reberhardt7 From 4ebbb0fba4b9b139129dbe30646137ae88d62b7d Mon Sep 17 00:00:00 2001 From: nikhilmantri0902 Date: Mon, 22 Sep 2025 15:36:59 +0530 Subject: [PATCH 6/6] fix: lint issues --- .../otlp-transformer/test/trace.test.ts | 66 +++++++++++++------ 1 file changed, 47 insertions(+), 19 deletions(-) diff --git a/experimental/packages/otlp-transformer/test/trace.test.ts b/experimental/packages/otlp-transformer/test/trace.test.ts index d3cd34f303d..5a1aaf13a23 100644 --- a/experimental/packages/otlp-transformer/test/trace.test.ts +++ b/experimental/packages/otlp-transformer/test/trace.test.ts @@ -591,7 +591,8 @@ describe('Trace', () => { useHex: true, }); assert.ok(exportRequest); - const spanFlags = exportRequest.resourceSpans?.[0].scopeSpans[0].spans?.[0].flags; + const spanFlags = + exportRequest.resourceSpans?.[0].scopeSpans[0].spans?.[0].flags; assert.strictEqual(spanFlags, 0x101); // TraceFlags (0x01) | HAS_IS_REMOTE }); @@ -609,11 +610,15 @@ describe('Trace', () => { parentSpanContext: remoteParentSpanContext, }; - const exportRequest = createExportTraceServiceRequest([spanWithRemoteParent], { - useHex: true, - }); + const exportRequest = createExportTraceServiceRequest( + [spanWithRemoteParent], + { + useHex: true, + } + ); assert.ok(exportRequest); - const spanFlags = exportRequest.resourceSpans?.[0].scopeSpans[0].spans?.[0].flags; + const spanFlags = + exportRequest.resourceSpans?.[0].scopeSpans[0].spans?.[0].flags; assert.strictEqual(spanFlags, 0x301); // TraceFlags (0x01) | HAS_IS_REMOTE | IS_REMOTE }); @@ -622,7 +627,9 @@ describe('Trace', () => { useHex: true, }); assert.ok(exportRequest); - const linkFlags = exportRequest.resourceSpans?.[0].scopeSpans[0].spans?.[0].links?.[0].flags; + const linkFlags = + exportRequest.resourceSpans?.[0].scopeSpans[0].spans?.[0].links?.[0] + .flags; assert.strictEqual(linkFlags, 0x101); // TraceFlags (0x01) | HAS_IS_REMOTE }); @@ -646,11 +653,16 @@ describe('Trace', () => { links: [remoteLink], }; - const exportRequest = createExportTraceServiceRequest([spanWithRemoteLink], { - useHex: true, - }); + const exportRequest = createExportTraceServiceRequest( + [spanWithRemoteLink], + { + useHex: true, + } + ); assert.ok(exportRequest); - const linkFlags = exportRequest.resourceSpans?.[0].scopeSpans[0].spans?.[0].links?.[0].flags; + const linkFlags = + exportRequest.resourceSpans?.[0].scopeSpans[0].spans?.[0].links?.[0] + .flags; assert.strictEqual(linkFlags, 0x301); // TraceFlags (0x01) | HAS_IS_REMOTE | IS_REMOTE }); }); @@ -681,8 +693,11 @@ describe('Trace', () => { isRemote: false, }, } as unknown as ReadableSpan; - const reqLocal = createExportTraceServiceRequest([spanLocal], { useHex: true }); - const spanFlagsLocal = reqLocal.resourceSpans?.[0].scopeSpans[0].spans?.[0].flags; + const reqLocal = createExportTraceServiceRequest([spanLocal], { + useHex: true, + }); + const spanFlagsLocal = + reqLocal.resourceSpans?.[0].scopeSpans[0].spans?.[0].flags; assert.strictEqual(spanFlagsLocal, c.local); // Remote parent @@ -693,8 +708,11 @@ describe('Trace', () => { isRemote: true, }, } as unknown as ReadableSpan; - const reqRemote = createExportTraceServiceRequest([spanRemote], { useHex: true }); - const spanFlagsRemote = reqRemote.resourceSpans?.[0].scopeSpans[0].spans?.[0].flags; + const reqRemote = createExportTraceServiceRequest([spanRemote], { + useHex: true, + }); + const spanFlagsRemote = + reqRemote.resourceSpans?.[0].scopeSpans[0].spans?.[0].flags; assert.strictEqual(spanFlagsRemote, c.remote); } }); @@ -716,8 +734,11 @@ describe('Trace', () => { ...span, links: [linkLocal], } as unknown as ReadableSpan; - const reqLocal = createExportTraceServiceRequest([spanWithLocalLink], { useHex: true }); - const linkFlagsLocal = reqLocal.resourceSpans?.[0].scopeSpans[0].spans?.[0].links?.[0].flags; + const reqLocal = createExportTraceServiceRequest([spanWithLocalLink], { + useHex: true, + }); + const linkFlagsLocal = + reqLocal.resourceSpans?.[0].scopeSpans[0].spans?.[0].links?.[0].flags; assert.strictEqual(linkFlagsLocal, c.local); const linkRemote = { @@ -728,8 +749,13 @@ describe('Trace', () => { ...span, links: [linkRemote], } as unknown as ReadableSpan; - const reqRemote = createExportTraceServiceRequest([spanWithRemoteLink], { useHex: true }); - const linkFlagsRemote = reqRemote.resourceSpans?.[0].scopeSpans[0].spans?.[0].links?.[0].flags; + const reqRemote = createExportTraceServiceRequest( + [spanWithRemoteLink], + { useHex: true } + ); + const linkFlagsRemote = + reqRemote.resourceSpans?.[0].scopeSpans[0].spans?.[0].links?.[0] + .flags; assert.strictEqual(linkFlagsRemote, c.remote); } }); @@ -748,7 +774,9 @@ describe('Trace', () => { }), parentSpanContext: undefined, } as unknown as ReadableSpan; - const req = createExportTraceServiceRequest([rootSpan], { useHex: true }); + const req = createExportTraceServiceRequest([rootSpan], { + useHex: true, + }); const flags = req.resourceSpans?.[0].scopeSpans[0].spans?.[0].flags; assert.strictEqual(flags, c.local); }