Skip to content

Commit

Permalink
fix(parseKeyPairsIntoRecord): allow equals in baggage value 3974
Browse files Browse the repository at this point in the history
proposed fix for parseKeyPairsIntoRecord issue 3974
  • Loading branch information
krosenk729 committed Jul 11, 2023
1 parent cab31aa commit f8870b5
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 12 deletions.
12 changes: 8 additions & 4 deletions packages/opentelemetry-core/src/baggage/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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' },
Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -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,
Expand All @@ -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',
Expand Down

0 comments on commit f8870b5

Please sign in to comment.