Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(propagator-aws-xray): correctly propagate over grpc #2604

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion propagators/propagator-aws-xray/src/AWSXRayPropagator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,10 @@ export class AWSXRayPropagator implements TextMapPropagator {
if (!relevantHeaderKey) {
return INVALID_SPAN_CONTEXT;
}
const traceHeader = getter.get(carrier, relevantHeaderKey);
const rawTraceHeader = getter.get(carrier, relevantHeaderKey);
const traceHeader = Array.isArray(rawTraceHeader)
? rawTraceHeader[0]
: rawTraceHeader;

if (!traceHeader || typeof traceHeader !== 'string') {
return INVALID_SPAN_CONTEXT;
Expand Down
28 changes: 28 additions & 0 deletions propagators/propagator-aws-xray/test/AWSXRayPropagator.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import {
SpanContext,
TraceFlags,
trace,
TextMapGetter,
} from '@opentelemetry/api';
import { TraceState } from '@opentelemetry/core';

Expand Down Expand Up @@ -317,6 +318,33 @@ describe('AWSXRayPropagator', () => {
});
});

it('should extract multi header using array getter', () => {
carrier[AWSXRAY_TRACE_ID_HEADER] =
'Root=1-8a3c60f7-d188f8fa79d48a391a778fa6;Parent=53995c3f42cd8ad8;Sampled=1';
const multiGetter: TextMapGetter = {
get(carrier, key) {
if (carrier == null || carrier[key] === undefined) {
return undefined;
}
return [carrier[key]];
},
keys: function (carrier: any): string[] {
return defaultTextMapGetter.keys(carrier);
},
};

const extractedSpanContext = trace
.getSpan(xrayPropagator.extract(ROOT_CONTEXT, carrier, multiGetter))
?.spanContext();

assert.deepStrictEqual(extractedSpanContext, {
traceId: TRACE_ID,
spanId: SPAN_ID,
isRemote: true,
traceFlags: TraceFlags.SAMPLED,
});
});

describe('.fields()', () => {
it('should return a field with AWS X-Ray Trace ID header', () => {
const expectedField = xrayPropagator.fields();
Expand Down
Loading