Skip to content
This repository was archived by the owner on Nov 10, 2022. It is now read-only.

Commit 0d5668d

Browse files
committed
chore: move baggage methods in propagation namespace
1 parent c595a59 commit 0d5668d

File tree

3 files changed

+22
-15
lines changed

3 files changed

+22
-15
lines changed

src/api/propagation.ts

+7
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ import {
2828
registerGlobal,
2929
unregisterGlobal,
3030
} from '../internal/global-utils';
31+
import { getBaggage, createBaggage, setBaggage } from '../baggage/index';
3132

3233
const API_NAME = 'propagation';
3334

@@ -100,6 +101,12 @@ export class PropagationAPI {
100101
unregisterGlobal(API_NAME);
101102
}
102103

104+
public createBaggage = createBaggage;
105+
106+
public getBaggage = getBaggage;
107+
108+
public setBaggage = setBaggage;
109+
103110
private _getGlobalPropagator(): TextMapPropagator {
104111
return getGlobal(API_NAME) || NOOP_TEXT_MAP_PROPAGATOR;
105112
}

src/index.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
* limitations under the License.
1515
*/
1616

17-
export * from './baggage';
17+
export { baggageEntryMetadataFromString } from './baggage';
1818
export * from './common/Exception';
1919
export * from './common/Time';
2020
export * from './diag';

test/baggage/Baggage.test.ts

+14-14
Original file line numberDiff line numberDiff line change
@@ -16,24 +16,22 @@
1616

1717
import * as assert from 'assert';
1818
import {
19-
createBaggage,
20-
setBaggage,
21-
getBaggage,
2219
ROOT_CONTEXT,
20+
propagation,
2321
baggageEntryMetadataFromString,
2422
} from '../../src';
2523

2624
describe('Baggage', () => {
2725
describe('create', () => {
2826
it('should create an empty bag', () => {
29-
const bag = createBaggage();
27+
const bag = propagation.createBaggage();
3028

3129
assert.deepStrictEqual(bag.getAllEntries(), []);
3230
});
3331

3432
it('should create a bag with entries', () => {
3533
const meta = baggageEntryMetadataFromString('opaque string');
36-
const bag = createBaggage({
34+
const bag = propagation.createBaggage({
3735
key1: { value: 'value1' },
3836
key2: { value: 'value2', metadata: meta },
3937
});
@@ -47,7 +45,9 @@ describe('Baggage', () => {
4745

4846
describe('get', () => {
4947
it('should not allow modification of returned entries', () => {
50-
const bag = createBaggage().setEntry('key', { value: 'value' });
48+
const bag = propagation
49+
.createBaggage()
50+
.setEntry('key', { value: 'value' });
5151

5252
const entry = bag.getEntry('key');
5353
assert.ok(entry);
@@ -59,7 +59,7 @@ describe('Baggage', () => {
5959

6060
describe('set', () => {
6161
it('should create a new bag when an entry is added', () => {
62-
const bag = createBaggage();
62+
const bag = propagation.createBaggage();
6363

6464
const bag2 = bag.setEntry('key', { value: 'value' });
6565

@@ -73,7 +73,7 @@ describe('Baggage', () => {
7373

7474
describe('remove', () => {
7575
it('should create a new bag when an entry is removed', () => {
76-
const bag = createBaggage({
76+
const bag = propagation.createBaggage({
7777
key: { value: 'value' },
7878
});
7979

@@ -87,7 +87,7 @@ describe('Baggage', () => {
8787
});
8888

8989
it('should create an empty bag multiple keys are removed', () => {
90-
const bag = createBaggage({
90+
const bag = propagation.createBaggage({
9191
key: { value: 'value' },
9292
key1: { value: 'value1' },
9393
key2: { value: 'value2' },
@@ -107,7 +107,7 @@ describe('Baggage', () => {
107107
});
108108

109109
it('should create an empty bag when it cleared', () => {
110-
const bag = createBaggage({
110+
const bag = propagation.createBaggage({
111111
key: { value: 'value' },
112112
key1: { value: 'value1' },
113113
});
@@ -125,11 +125,11 @@ describe('Baggage', () => {
125125

126126
describe('context', () => {
127127
it('should set and get a baggage from a context', () => {
128-
const bag = createBaggage();
128+
const bag = propagation.createBaggage();
129129

130-
const ctx = setBaggage(ROOT_CONTEXT, bag);
130+
const ctx = propagation.setBaggage(ROOT_CONTEXT, bag);
131131

132-
assert.strictEqual(bag, getBaggage(ctx));
132+
assert.strictEqual(bag, propagation.getBaggage(ctx));
133133
});
134134
});
135135

@@ -148,7 +148,7 @@ describe('Baggage', () => {
148148
});
149149

150150
it('should retain metadata', () => {
151-
const bag = createBaggage({
151+
const bag = propagation.createBaggage({
152152
key: {
153153
value: 'value',
154154
metadata: baggageEntryMetadataFromString('meta'),

0 commit comments

Comments
 (0)