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

Commit

Permalink
chore: move baggage methods in propagation namespace
Browse files Browse the repository at this point in the history
  • Loading branch information
vmarchaud committed May 2, 2021
1 parent c595a59 commit 0d5668d
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 15 deletions.
7 changes: 7 additions & 0 deletions src/api/propagation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import {
registerGlobal,
unregisterGlobal,
} from '../internal/global-utils';
import { getBaggage, createBaggage, setBaggage } from '../baggage/index';

const API_NAME = 'propagation';

Expand Down Expand Up @@ -100,6 +101,12 @@ export class PropagationAPI {
unregisterGlobal(API_NAME);
}

public createBaggage = createBaggage;

public getBaggage = getBaggage;

public setBaggage = setBaggage;

private _getGlobalPropagator(): TextMapPropagator {
return getGlobal(API_NAME) || NOOP_TEXT_MAP_PROPAGATOR;
}
Expand Down
2 changes: 1 addition & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
* limitations under the License.
*/

export * from './baggage';
export { baggageEntryMetadataFromString } from './baggage';
export * from './common/Exception';
export * from './common/Time';
export * from './diag';
Expand Down
28 changes: 14 additions & 14 deletions test/baggage/Baggage.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,24 +16,22 @@

import * as assert from 'assert';
import {
createBaggage,
setBaggage,
getBaggage,
ROOT_CONTEXT,
propagation,
baggageEntryMetadataFromString,
} from '../../src';

describe('Baggage', () => {
describe('create', () => {
it('should create an empty bag', () => {
const bag = createBaggage();
const bag = propagation.createBaggage();

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

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

describe('get', () => {
it('should not allow modification of returned entries', () => {
const bag = createBaggage().setEntry('key', { value: 'value' });
const bag = propagation
.createBaggage()
.setEntry('key', { value: 'value' });

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

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

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

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

describe('remove', () => {
it('should create a new bag when an entry is removed', () => {
const bag = createBaggage({
const bag = propagation.createBaggage({
key: { value: 'value' },
});

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

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

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

describe('context', () => {
it('should set and get a baggage from a context', () => {
const bag = createBaggage();
const bag = propagation.createBaggage();

const ctx = setBaggage(ROOT_CONTEXT, bag);
const ctx = propagation.setBaggage(ROOT_CONTEXT, bag);

assert.strictEqual(bag, getBaggage(ctx));
assert.strictEqual(bag, propagation.getBaggage(ctx));
});
});

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

it('should retain metadata', () => {
const bag = createBaggage({
const bag = propagation.createBaggage({
key: {
value: 'value',
metadata: baggageEntryMetadataFromString('meta'),
Expand Down

0 comments on commit 0d5668d

Please sign in to comment.