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 (#55)
Browse files Browse the repository at this point in the history
* chore: move baggage methods in propagation namespace

* chore: add upgrade guidelines
  • Loading branch information
vmarchaud committed May 14, 2021
1 parent 0a3bee4 commit 8435e0a
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 15 deletions.
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' },