From acb03454bdd239182d17785ee508889dfee65559 Mon Sep 17 00:00:00 2001 From: Doron Kopit <83537683+doronkopit5@users.noreply.github.com> Date: Thu, 17 Mar 2022 16:17:58 +0200 Subject: [PATCH 1/2] fix(opentelemtry-core): fix header extraction (#2832) Co-authored-by: legendecas --- .../propagation/W3CBaggagePropagator.ts | 9 ++-- .../test/baggage/W3CBaggagePropagator.test.ts | 43 +++++++++++++++---- 2 files changed, 40 insertions(+), 12 deletions(-) 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); }); }); From 7268daa3db8e1a7158853cbbfeb07c1cea2baa76 Mon Sep 17 00:00:00 2001 From: WhiteSource Renovate Date: Fri, 18 Mar 2022 06:43:36 +0100 Subject: [PATCH 2/2] chore(deps): update actions/setup-node action to v3 (#2841) --- .github/workflows/docs.yaml | 2 +- .github/workflows/lint.yml | 2 +- .github/workflows/unit-test.yml | 4 ++-- 3 files changed, 4 insertions(+), 4 deletions(-) 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 }}