Skip to content

Commit 9dda63e

Browse files
authored
Merge branch 'main' into proposal-1.1
2 parents 0bc0418 + 7268daa commit 9dda63e

File tree

5 files changed

+44
-16
lines changed

5 files changed

+44
-16
lines changed

.github/workflows/docs.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ jobs:
1111
- name: Checkout
1212
uses: actions/checkout@v2
1313

14-
- uses: actions/setup-node@v2
14+
- uses: actions/setup-node@v3
1515
with:
1616
node-version: '14'
1717

.github/workflows/lint.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ jobs:
1515
runs-on: ubuntu-latest
1616

1717
steps:
18-
- uses: actions/setup-node@v2
18+
- uses: actions/setup-node@v3
1919
with:
2020
node-version: '14'
2121

.github/workflows/unit-test.yml

+2-2
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ jobs:
1818
- name: Checkout
1919
uses: actions/checkout@v2
2020

21-
- uses: actions/setup-node@v2
21+
- uses: actions/setup-node@v3
2222
with:
2323
node-version: ${{ matrix.node_version }}
2424

@@ -128,7 +128,7 @@ jobs:
128128
- name: Checkout
129129
uses: actions/checkout@v2
130130

131-
- uses: actions/setup-node@v2
131+
- uses: actions/setup-node@v3
132132
with:
133133
node-version: ${{ matrix.node_version }}
134134

packages/opentelemetry-core/src/baggage/propagation/W3CBaggagePropagator.ts

+5-4
Original file line numberDiff line numberDiff line change
@@ -58,13 +58,14 @@ export class W3CBaggagePropagator implements TextMapPropagator {
5858
}
5959

6060
extract(context: Context, carrier: unknown, getter: TextMapGetter): Context {
61-
const headerValue: string = getter.get(carrier, BAGGAGE_HEADER) as string;
62-
if (!headerValue) return context;
61+
const headerValue = getter.get(carrier, BAGGAGE_HEADER);
62+
const baggageString = Array.isArray(headerValue) ? headerValue.join(BAGGAGE_ITEMS_SEPARATOR) : headerValue;
63+
if (!baggageString) return context;
6364
const baggage: Record<string, BaggageEntry> = {};
64-
if (headerValue.length === 0) {
65+
if (baggageString.length === 0) {
6566
return context;
6667
}
67-
const pairs = headerValue.split(BAGGAGE_ITEMS_SEPARATOR);
68+
const pairs = baggageString.split(BAGGAGE_ITEMS_SEPARATOR);
6869
pairs.forEach(entry => {
6970
const keyPair = parsePairKeyValue(entry);
7071
if (keyPair) {

packages/opentelemetry-core/test/baggage/W3CBaggagePropagator.test.ts

+35-8
Original file line numberDiff line numberDiff line change
@@ -175,9 +175,42 @@ describe('W3CBaggagePropagator', () => {
175175
});
176176

177177
describe('.extract()', () => {
178+
const baggageValue = 'key1=d4cda95b,key3=c88815a7, keyn = valn, keym =valm';
179+
const expected = propagation.createBaggage({
180+
key1: { value: 'd4cda95b' },
181+
key3: { value: 'c88815a7' },
182+
keyn: { value: 'valn' },
183+
keym: { value: 'valm' },
184+
});
185+
178186
it('should extract context of a sampled span from carrier', () => {
179-
carrier[BAGGAGE_HEADER] =
180-
'key1=d4cda95b,key3=c88815a7, keyn = valn, keym =valm';
187+
carrier[BAGGAGE_HEADER] = baggageValue;
188+
const extractedBaggage = propagation.getBaggage(
189+
httpBaggagePropagator.extract(
190+
ROOT_CONTEXT,
191+
carrier,
192+
defaultTextMapGetter
193+
)
194+
);
195+
196+
assert.deepStrictEqual(extractedBaggage, expected);
197+
});
198+
199+
it('should extract context of a sampled span when the headerValue comes as array', () => {
200+
carrier[BAGGAGE_HEADER] = [baggageValue];
201+
const extractedBaggage = propagation.getBaggage(
202+
httpBaggagePropagator.extract(
203+
ROOT_CONTEXT,
204+
carrier,
205+
defaultTextMapGetter
206+
)
207+
);
208+
209+
assert.deepStrictEqual(extractedBaggage, expected);
210+
});
211+
212+
it('should extract context of a sampled span when the headerValue comes as array with multiple items', () => {
213+
carrier[BAGGAGE_HEADER] = ['key1=d4cda95b,key3=c88815a7, keyn = valn', 'keym =valm'];
181214
const extractedBaggage = propagation.getBaggage(
182215
httpBaggagePropagator.extract(
183216
ROOT_CONTEXT,
@@ -186,12 +219,6 @@ describe('W3CBaggagePropagator', () => {
186219
)
187220
);
188221

189-
const expected = propagation.createBaggage({
190-
key1: { value: 'd4cda95b' },
191-
key3: { value: 'c88815a7' },
192-
keyn: { value: 'valn' },
193-
keym: { value: 'valm' },
194-
});
195222
assert.deepStrictEqual(extractedBaggage, expected);
196223
});
197224
});

0 commit comments

Comments
 (0)