Skip to content

Commit

Permalink
Merge branch 'main' of github.com:open-telemetry/opentelemetry-js-con…
Browse files Browse the repository at this point in the history
…trib
  • Loading branch information
sudarshan12s committed Jan 10, 2025
2 parents 440db83 + 3350583 commit 6faff54
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ export class EventLoopUtilizationCollector extends BaseCollector {
`${this.namePrefix}.${ATTR_NODEJS_EVENT_LOOP_UTILIZATION}`,
{
description: 'Event loop utilization',
unit: 's',
unit: '1',
}
)
.addCallback(async observableResult => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ describe(`${ConventionalNamePrefix.NodeJs}.${ATTR_NODEJS_EVENT_LOOP_UTILIZATION}

assert.strictEqual(
utilizationMetric!.descriptor.unit,
's',
'1',
'expected default unit'
);

Expand Down
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

0 comments on commit 6faff54

Please sign in to comment.