diff --git a/.github/workflows/docs.yaml b/.github/workflows/docs.yaml index c17e6b7674..79cd35691c 100644 --- a/.github/workflows/docs.yaml +++ b/.github/workflows/docs.yaml @@ -11,7 +11,7 @@ jobs: - name: Checkout uses: actions/checkout@v2 - - uses: actions/setup-node@v2 + - uses: actions/setup-node@v3 with: node-version: '14' diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml index 9b96d1a633..bc1d0d366a 100644 --- a/.github/workflows/lint.yml +++ b/.github/workflows/lint.yml @@ -15,7 +15,7 @@ jobs: runs-on: ubuntu-latest steps: - - uses: actions/setup-node@v2 + - uses: actions/setup-node@v3 with: node-version: '14' diff --git a/.github/workflows/unit-test.yml b/.github/workflows/unit-test.yml index 53d3d47385..afc6006983 100644 --- a/.github/workflows/unit-test.yml +++ b/.github/workflows/unit-test.yml @@ -18,7 +18,7 @@ jobs: - name: Checkout uses: actions/checkout@v2 - - uses: actions/setup-node@v2 + - uses: actions/setup-node@v3 with: node-version: ${{ matrix.node_version }} @@ -128,7 +128,7 @@ jobs: - name: Checkout uses: actions/checkout@v2 - - uses: actions/setup-node@v2 + - uses: actions/setup-node@v3 with: node-version: ${{ matrix.node_version }} diff --git a/packages/opentelemetry-core/src/baggage/propagation/W3CBaggagePropagator.ts b/packages/opentelemetry-core/src/baggage/propagation/W3CBaggagePropagator.ts index 652cc14c3a..3283a105a7 100644 --- a/packages/opentelemetry-core/src/baggage/propagation/W3CBaggagePropagator.ts +++ b/packages/opentelemetry-core/src/baggage/propagation/W3CBaggagePropagator.ts @@ -58,13 +58,14 @@ export class W3CBaggagePropagator implements TextMapPropagator { } extract(context: Context, carrier: unknown, getter: TextMapGetter): Context { - const headerValue: string = getter.get(carrier, BAGGAGE_HEADER) as string; - if (!headerValue) return context; + const headerValue = getter.get(carrier, BAGGAGE_HEADER); + const baggageString = Array.isArray(headerValue) ? headerValue.join(BAGGAGE_ITEMS_SEPARATOR) : headerValue; + if (!baggageString) return context; const baggage: Record = {}; - if (headerValue.length === 0) { + if (baggageString.length === 0) { return context; } - const pairs = headerValue.split(BAGGAGE_ITEMS_SEPARATOR); + const pairs = baggageString.split(BAGGAGE_ITEMS_SEPARATOR); pairs.forEach(entry => { const keyPair = parsePairKeyValue(entry); if (keyPair) { diff --git a/packages/opentelemetry-core/test/baggage/W3CBaggagePropagator.test.ts b/packages/opentelemetry-core/test/baggage/W3CBaggagePropagator.test.ts index 38de668087..a6fcd267ea 100644 --- a/packages/opentelemetry-core/test/baggage/W3CBaggagePropagator.test.ts +++ b/packages/opentelemetry-core/test/baggage/W3CBaggagePropagator.test.ts @@ -175,9 +175,42 @@ describe('W3CBaggagePropagator', () => { }); describe('.extract()', () => { + const baggageValue = 'key1=d4cda95b,key3=c88815a7, keyn = valn, keym =valm'; + const expected = propagation.createBaggage({ + key1: { value: 'd4cda95b' }, + key3: { value: 'c88815a7' }, + keyn: { value: 'valn' }, + keym: { value: 'valm' }, + }); + it('should extract context of a sampled span from carrier', () => { - carrier[BAGGAGE_HEADER] = - 'key1=d4cda95b,key3=c88815a7, keyn = valn, keym =valm'; + carrier[BAGGAGE_HEADER] = baggageValue; + const extractedBaggage = propagation.getBaggage( + httpBaggagePropagator.extract( + ROOT_CONTEXT, + carrier, + defaultTextMapGetter + ) + ); + + assert.deepStrictEqual(extractedBaggage, expected); + }); + + it('should extract context of a sampled span when the headerValue comes as array', () => { + carrier[BAGGAGE_HEADER] = [baggageValue]; + const extractedBaggage = propagation.getBaggage( + httpBaggagePropagator.extract( + ROOT_CONTEXT, + carrier, + defaultTextMapGetter + ) + ); + + assert.deepStrictEqual(extractedBaggage, expected); + }); + + it('should extract context of a sampled span when the headerValue comes as array with multiple items', () => { + carrier[BAGGAGE_HEADER] = ['key1=d4cda95b,key3=c88815a7, keyn = valn', 'keym =valm']; const extractedBaggage = propagation.getBaggage( httpBaggagePropagator.extract( ROOT_CONTEXT, @@ -186,12 +219,6 @@ describe('W3CBaggagePropagator', () => { ) ); - const expected = propagation.createBaggage({ - key1: { value: 'd4cda95b' }, - key3: { value: 'c88815a7' }, - keyn: { value: 'valn' }, - keym: { value: 'valm' }, - }); assert.deepStrictEqual(extractedBaggage, expected); }); });