Skip to content

Commit

Permalink
Merge branch 'main' into proposal-1.1
Browse files Browse the repository at this point in the history
  • Loading branch information
dyladan committed Mar 18, 2022
2 parents 0bc0418 + 7268daa commit 9dda63e
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 16 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/docs.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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'

Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ jobs:
runs-on: ubuntu-latest

steps:
- uses: actions/setup-node@v2
- uses: actions/setup-node@v3
with:
node-version: '14'

Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/unit-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }}

Expand Down Expand Up @@ -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 }}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<string, BaggageEntry> = {};
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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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);
});
});
Expand Down

0 comments on commit 9dda63e

Please sign in to comment.