From f8870b5c04c25d6205a87e3056235524a9a245e0 Mon Sep 17 00:00:00 2001 From: katherine Date: Mon, 10 Jul 2023 16:47:14 -0400 Subject: [PATCH 1/2] fix(parseKeyPairsIntoRecord): allow equals in baggage value 3974 proposed fix for parseKeyPairsIntoRecord issue 3974 --- packages/opentelemetry-core/src/baggage/utils.ts | 12 ++++++++---- .../test/baggage/W3CBaggagePropagator.test.ts | 12 ++++-------- 2 files changed, 12 insertions(+), 12 deletions(-) diff --git a/packages/opentelemetry-core/src/baggage/utils.ts b/packages/opentelemetry-core/src/baggage/utils.ts index 991b8a89a6..bb8b4b0155 100644 --- a/packages/opentelemetry-core/src/baggage/utils.ts +++ b/packages/opentelemetry-core/src/baggage/utils.ts @@ -61,10 +61,14 @@ export function parsePairKeyValue( if (valueProps.length <= 0) return; const keyPairPart = valueProps.shift(); if (!keyPairPart) return; - const keyPair = keyPairPart.split(BAGGAGE_KEY_PAIR_SEPARATOR); - if (keyPair.length !== 2) return; - const key = decodeURIComponent(keyPair[0].trim()); - const value = decodeURIComponent(keyPair[1].trim()); + const separatorIndex = keyPairPart.indexOf(BAGGAGE_KEY_PAIR_SEPARATOR); + if (separatorIndex <= 0) return; + const key = decodeURIComponent( + keyPairPart.substring(0, separatorIndex).trim() + ); + const value = decodeURIComponent( + keyPairPart.substring(separatorIndex + 1).trim() + ); let metadata; if (valueProps.length > 0) { metadata = baggageEntryMetadataFromString( diff --git a/packages/opentelemetry-core/test/baggage/W3CBaggagePropagator.test.ts b/packages/opentelemetry-core/test/baggage/W3CBaggagePropagator.test.ts index c30bfb3014..801496513f 100644 --- a/packages/opentelemetry-core/test/baggage/W3CBaggagePropagator.test.ts +++ b/packages/opentelemetry-core/test/baggage/W3CBaggagePropagator.test.ts @@ -181,9 +181,9 @@ describe('W3CBaggagePropagator', () => { describe('.extract()', () => { const baggageValue = - 'key1=d4cda95b,key3=c88815a7, keyn = valn, keym =valm'; + 'key1=d4cda95b==,key3=c88815a7, keyn = valn, keym =valm'; const expected = propagation.createBaggage({ - key1: { value: 'd4cda95b' }, + key1: { value: 'd4cda95b==' }, key3: { value: 'c88815a7' }, keyn: { value: 'valn' }, keym: { value: 'valm' }, @@ -217,7 +217,7 @@ describe('W3CBaggagePropagator', () => { 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', + 'key1=d4cda95b==,key3=c88815a7, keyn = valn', 'keym =valm', ]; const extractedBaggage = propagation.getBaggage( @@ -282,10 +282,6 @@ describe('W3CBaggagePropagator', () => { header: '289371298nekjh2939299283jbk2b', baggage: undefined, }, - invalidDoubleEqual: { - header: 'key1==value;key2=value2', - baggage: undefined, - }, invalidWrongKeyValueFormat: { header: 'key1:value;key2=value2', baggage: undefined, @@ -295,7 +291,7 @@ describe('W3CBaggagePropagator', () => { baggage: undefined, }, mixInvalidAndValidKeys: { - header: 'key1==value,key2=value2', + header: 'key1:value,key2=value2', baggage: propagation.createBaggage({ key2: { value: 'value2', From e223fff98087bb12789f606ae77e0ef6d9817f1e Mon Sep 17 00:00:00 2001 From: katherine Date: Mon, 17 Jul 2023 07:21:30 -0400 Subject: [PATCH 2/2] fix(parseKeyPairsIntoRecord): allow equals in baggage value 3974 proposed fix for parseKeyPairsIntoRecord issue 3974 --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 6f72946061..794c8a2fa6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -25,6 +25,7 @@ For experimental package changes, see the [experimental CHANGELOG](experimental/ * fix(sdk-metrics): Update default Histogram's boundary to match OTEL's spec [#3893](https://github.com/open-telemetry/opentelemetry-js/pull/3893/) @chigia001 * fix(sdk-metrics): preserve startTime for cumulative ExponentialHistograms [#3934](https://github.com/open-telemetry/opentelemetry-js/pull/3934/) @aabmass * fix(sdk-trace-web): add secureConnectionStart to https only [#3879](https://github.com/open-telemetry/opentelemetry-js/pull/3879) @Abinet18 +* fix(core): add baggage support for values containing an equals sign [#3975](https://github.com/open-telemetry/opentelemetry-js/pull/3975) @krosenk729 ### :house: (Internal)