Skip to content

Commit b744f30

Browse files
authored
chore: rename CorrelationContext to Baggage (#1687)
* chore: rename CorrelationContext to Baggage * chore: lint
1 parent e032feb commit b744f30

File tree

16 files changed

+124
-177
lines changed

16 files changed

+124
-177
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ Last updated March 2020
108108
| Metrics | Beta | v0.3 | Beta |
109109
| Context | Beta | v0.3 | Beta |
110110
| Propagation | Beta | v0.3 | Beta |
111-
| Correlation Context | Alpha | v0.3 | Development |
111+
| Baggage | Alpha | v0.3 | Development |
112112
| OpenTracing Bridge | N/A | v0.3 | Beta |
113113
| Resources | N/A | v0.3 | Beta |
114114

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,13 @@
1717
import { EntryValue } from './EntryValue';
1818

1919
/**
20-
* CorrelationContext represents collection of entries. Each key of
21-
* CorrelationContext is associated with exactly one value. CorrelationContext
20+
* Baggage represents collection of entries. Each key of
21+
* Baggage is associated with exactly one value. Baggage
2222
* is serializable, to facilitate propagating it not only inside the process
23-
* but also across process boundaries. CorrelationContext is used to annotate
23+
* but also across process boundaries. Baggage is used to annotate
2424
* telemetry with the name:value pair Entry. Those values can be used to add
2525
* dimension to the metric or additional contest properties to logs and traces.
2626
*/
27-
export interface CorrelationContext {
27+
export interface Baggage {
2828
[entryKey: string]: EntryValue;
2929
}

packages/opentelemetry-api/src/context/context.ts

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@
1414
* limitations under the License.
1515
*/
1616

17-
import { NoopSpan, Span, SpanContext } from '../';
1817
import { Context, createContextKey } from '@opentelemetry/context-base';
18+
import { Baggage, NoopSpan, Span, SpanContext } from '../';
1919

2020
/**
2121
* Active span key
@@ -32,6 +32,11 @@ const SUPPRESS_INSTRUMENTATION_KEY = createContextKey(
3232
'OpenTelemetry Context Key SUPPRESS_INSTRUMENTATION'
3333
);
3434

35+
/**
36+
* Baggage key
37+
*/
38+
const BAGGAGE_KEY = createContextKey('OpenTelemetry Baggage Key');
39+
3540
/**
3641
* Return the active span if one exists
3742
*
@@ -107,3 +112,19 @@ export function unsuppressInstrumentation(context: Context): Context {
107112
export function isInstrumentationSuppressed(context: Context): boolean {
108113
return Boolean(context.getValue(SUPPRESS_INSTRUMENTATION_KEY));
109114
}
115+
116+
/**
117+
* @param {Context} Context that manage all context values
118+
* @returns {Baggage} Extracted baggage from the context
119+
*/
120+
export function getBaggage(context: Context): Baggage | undefined {
121+
return (context.getValue(BAGGAGE_KEY) as Baggage) || undefined;
122+
}
123+
124+
/**
125+
* @param {Context} Context that manage all context values
126+
* @param {Baggage} baggage that will be set in the actual context
127+
*/
128+
export function setBaggage(context: Context, baggage: Baggage): Context {
129+
return context.setValue(BAGGAGE_KEY, baggage);
130+
}

packages/opentelemetry-api/src/index.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,8 @@ export * from './common/Time';
2020
export * from './context/context';
2121
export * from './context/propagation/TextMapPropagator';
2222
export * from './context/propagation/NoopTextMapPropagator';
23-
export * from './correlation_context/CorrelationContext';
24-
export * from './correlation_context/EntryValue';
23+
export * from './baggage/Baggage';
24+
export * from './baggage/EntryValue';
2525
export * from './metrics/BatchObserverResult';
2626
export * from './metrics/BoundInstrument';
2727
export * from './metrics/Meter';

packages/opentelemetry-api/src/metrics/NoopMeter.ts

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ import {
3333
BoundCounter,
3434
BoundBaseObserver,
3535
} from './BoundInstrument';
36-
import { CorrelationContext } from '../correlation_context/CorrelationContext';
36+
import { Baggage } from '../baggage/Baggage';
3737
import { SpanContext } from '../trace/span_context';
3838
import { ObserverResult } from './ObserverResult';
3939

@@ -198,11 +198,7 @@ export class NoopBoundCounter implements BoundCounter {
198198
}
199199

200200
export class NoopBoundValueRecorder implements BoundValueRecorder {
201-
record(
202-
_value: number,
203-
_correlationContext?: CorrelationContext,
204-
_spanContext?: SpanContext
205-
): void {
201+
record(_value: number, _baggage?: Baggage, _spanContext?: SpanContext): void {
206202
return;
207203
}
208204
}

packages/opentelemetry-api/src/trace/span_context.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ import { TraceState } from './trace_state';
1818

1919
/**
2020
* A SpanContext represents the portion of a {@link Span} which must be
21-
* serialized and propagated along side of a {@link CorrelationContext}.
21+
* serialized and propagated along side of a {@link Baggage}.
2222
*/
2323
export interface SpanContext {
2424
/**

packages/opentelemetry-core/README.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ This package provides default implementations of the OpenTelemetry API for trace
1515
- [Built-in Propagators](#built-in-propagators)
1616
- [HttpTraceContext Propagator](#httptracecontext-propagator)
1717
- [Composite Propagator](#composite-propagator)
18-
- [Correlation Context Propagator](#correlation-context-propagator)
18+
- [Baggage Propagator](#baggage-propagator)
1919
- [Built-in Sampler](#built-in-sampler)
2020
- [Always Sampler](#always-sampler)
2121
- [Never Sampler](#never-sampler)
@@ -51,16 +51,16 @@ const { CompositePropagator } = require("@opentelemetry/core");
5151
api.propagation.setGlobalPropagator(new CompositePropagator());
5252
```
5353

54-
#### Correlation Context Propagator
54+
#### Baggage Propagator
5555

56-
Provides a text-based approach to propagate [correlation context](https://w3c.github.io/correlation-context/) to remote services using the [OpenTelemetry CorrelationContext Propagation](https://github.com/open-telemetry/opentelemetry-specification/blob/master/specification/correlationcontext/api.md#header-name) HTTP headers.
56+
Provides a text-based approach to propagate [baggage](https://w3c.github.io/baggage/) to remote services using the [OpenTelemetry Baggage Propagation](https://github.com/open-telemetry/opentelemetry-specification/blob/master/specification/baggage/api.md#baggage-propagation) HTTP headers.
5757

5858
```js
5959
const api = require("@opentelemetry/api");
60-
const { HttpCorrelationContext } = require("@opentelemetry/core");
60+
const { HttpBaggage } = require("@opentelemetry/core");
6161

6262
/* Set Global Propagator */
63-
api.propagation.setGlobalPropagator(new HttpCorrelationContext());
63+
api.propagation.setGlobalPropagator(new HttpBaggage());
6464
```
6565

6666
### Built-in Sampler
Lines changed: 22 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -15,23 +15,21 @@
1515
*/
1616

1717
import {
18+
Baggage,
1819
Context,
19-
CorrelationContext,
20+
getBaggage,
21+
setBaggage,
2022
TextMapGetter,
2123
TextMapPropagator,
2224
TextMapSetter,
2325
} from '@opentelemetry/api';
24-
import {
25-
getCorrelationContext,
26-
setCorrelationContext,
27-
} from '../correlation-context';
2826

2927
const KEY_PAIR_SEPARATOR = '=';
3028
const PROPERTIES_SEPARATOR = ';';
3129
const ITEMS_SEPARATOR = ',';
3230

33-
// Name of the http header used to propagate the correlation context
34-
export const CORRELATION_CONTEXT_HEADER = 'baggage';
31+
// Name of the http header used to propagate the baggage
32+
export const BAGGAGE_HEADER = 'baggage';
3533
// Maximum number of name-value pairs allowed by w3c spec
3634
export const MAX_NAME_VALUE_PAIRS = 180;
3735
// Maximum number of bytes per a single name-value pair allowed by w3c spec
@@ -44,23 +42,23 @@ type KeyPair = {
4442
};
4543

4644
/**
47-
* Propagates {@link CorrelationContext} through Context format propagation.
45+
* Propagates {@link Baggage} through Context format propagation.
4846
*
49-
* Based on the Correlation Context specification:
50-
* https://w3c.github.io/correlation-context/
47+
* Based on the Baggage specification:
48+
* https://w3c.github.io/baggage/
5149
*/
52-
export class HttpCorrelationContext implements TextMapPropagator {
50+
export class HttpBaggage implements TextMapPropagator {
5351
inject(context: Context, carrier: unknown, setter: TextMapSetter) {
54-
const correlationContext = getCorrelationContext(context);
55-
if (!correlationContext) return;
56-
const keyPairs = this._getKeyPairs(correlationContext)
52+
const baggage = getBaggage(context);
53+
if (!baggage) return;
54+
const keyPairs = this._getKeyPairs(baggage)
5755
.filter((pair: string) => {
5856
return pair.length <= MAX_PER_NAME_VALUE_PAIRS;
5957
})
6058
.slice(0, MAX_NAME_VALUE_PAIRS);
6159
const headerValue = this._serializeKeyPairs(keyPairs);
6260
if (headerValue.length > 0) {
63-
setter.set(carrier, CORRELATION_CONTEXT_HEADER, headerValue);
61+
setter.set(carrier, BAGGAGE_HEADER, headerValue);
6462
}
6563
}
6664

@@ -71,36 +69,31 @@ export class HttpCorrelationContext implements TextMapPropagator {
7169
}, '');
7270
}
7371

74-
private _getKeyPairs(correlationContext: CorrelationContext): string[] {
75-
return Object.keys(correlationContext).map(
72+
private _getKeyPairs(baggage: Baggage): string[] {
73+
return Object.keys(baggage).map(
7674
(key: string) =>
77-
`${encodeURIComponent(key)}=${encodeURIComponent(
78-
correlationContext[key].value
79-
)}`
75+
`${encodeURIComponent(key)}=${encodeURIComponent(baggage[key].value)}`
8076
);
8177
}
8278

8379
extract(context: Context, carrier: unknown, getter: TextMapGetter): Context {
84-
const headerValue: string = getter.get(
85-
carrier,
86-
CORRELATION_CONTEXT_HEADER
87-
) as string;
80+
const headerValue: string = getter.get(carrier, BAGGAGE_HEADER) as string;
8881
if (!headerValue) return context;
89-
const correlationContext: CorrelationContext = {};
82+
const baggage: Baggage = {};
9083
if (headerValue.length == 0) {
9184
return context;
9285
}
9386
const pairs = headerValue.split(ITEMS_SEPARATOR);
9487
pairs.forEach(entry => {
9588
const keyPair = this._parsePairKeyValue(entry);
9689
if (keyPair) {
97-
correlationContext[keyPair.key] = { value: keyPair.value };
90+
baggage[keyPair.key] = { value: keyPair.value };
9891
}
9992
});
100-
if (Object.entries(correlationContext).length === 0) {
93+
if (Object.entries(baggage).length === 0) {
10194
return context;
10295
}
103-
return setCorrelationContext(context, correlationContext);
96+
return setBaggage(context, baggage);
10497
}
10598

10699
private _parsePairKeyValue(entry: string): KeyPair | undefined {
@@ -120,6 +113,6 @@ export class HttpCorrelationContext implements TextMapPropagator {
120113
}
121114

122115
fields(): string[] {
123-
return [CORRELATION_CONTEXT_HEADER];
116+
return [BAGGAGE_HEADER];
124117
}
125118
}

packages/opentelemetry-core/src/correlation-context/correlation-context.ts

Lines changed: 0 additions & 48 deletions
This file was deleted.

0 commit comments

Comments
 (0)