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

chore: move baggage methods in propagation namespace #55

Merged
merged 2 commits into from
May 14, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@ Because the npm installer and node module resolution algorithm could potentially
- `HttpBaggage` renamed to `HttpBaggagePropagator`
- [#45](https://github.com/open-telemetry/opentelemetry-js-api/pull/45) `Span#context` renamed to `Span#spanContext`
- [#47](https://github.com/open-telemetry/opentelemetry-js-api/pull/47) `getSpan`/`setSpan`/`getSpanContext`/`setSpanContext` moved to `trace` namespace
- [#55](https://github.com/open-telemetry/opentelemetry-js-api/pull/55) `getBaggage`/`setBaggage`/`createBaggage` moved to `propagation` namespace

## Useful links

Expand Down
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