Skip to content

Commit

Permalink
chore: rename CorrelationContext to Baggage (open-telemetry#1687)
Browse files Browse the repository at this point in the history
* chore: rename CorrelationContext to Baggage

* chore: lint
  • Loading branch information
dyladan committed Feb 18, 2021
1 parent f0f27f2 commit ecf6eb7
Show file tree
Hide file tree
Showing 6 changed files with 31 additions and 14 deletions.
Expand Up @@ -17,13 +17,13 @@
import { EntryValue } from './EntryValue';

/**
* CorrelationContext represents collection of entries. Each key of
* CorrelationContext is associated with exactly one value. CorrelationContext
* Baggage represents collection of entries. Each key of
* Baggage is associated with exactly one value. Baggage
* is serializable, to facilitate propagating it not only inside the process
* but also across process boundaries. CorrelationContext is used to annotate
* but also across process boundaries. Baggage is used to annotate
* telemetry with the name:value pair Entry. Those values can be used to add
* dimension to the metric or additional contest properties to logs and traces.
*/
export interface CorrelationContext {
export interface Baggage {
[entryKey: string]: EntryValue;
}
File renamed without changes.
23 changes: 22 additions & 1 deletion api/src/context/context.ts
Expand Up @@ -14,8 +14,8 @@
* limitations under the License.
*/

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

/**
* Active span key
Expand All @@ -32,6 +32,11 @@ const SUPPRESS_INSTRUMENTATION_KEY = createContextKey(
'OpenTelemetry Context Key SUPPRESS_INSTRUMENTATION'
);

/**
* Baggage key
*/
const BAGGAGE_KEY = createContextKey('OpenTelemetry Baggage Key');

/**
* Return the active span if one exists
*
Expand Down Expand Up @@ -107,3 +112,19 @@ export function unsuppressInstrumentation(context: Context): Context {
export function isInstrumentationSuppressed(context: Context): boolean {
return Boolean(context.getValue(SUPPRESS_INSTRUMENTATION_KEY));
}

/**
* @param {Context} Context that manage all context values
* @returns {Baggage} Extracted baggage from the context
*/
export function getBaggage(context: Context): Baggage | undefined {
return (context.getValue(BAGGAGE_KEY) as Baggage) || undefined;
}

/**
* @param {Context} Context that manage all context values
* @param {Baggage} baggage that will be set in the actual context
*/
export function setBaggage(context: Context, baggage: Baggage): Context {
return context.setValue(BAGGAGE_KEY, baggage);
}
4 changes: 2 additions & 2 deletions api/src/index.ts
Expand Up @@ -20,8 +20,8 @@ export * from './common/Time';
export * from './context/context';
export * from './context/propagation/TextMapPropagator';
export * from './context/propagation/NoopTextMapPropagator';
export * from './correlation_context/CorrelationContext';
export * from './correlation_context/EntryValue';
export * from './baggage/Baggage';
export * from './baggage/EntryValue';
export * from './metrics/BatchObserverResult';
export * from './metrics/BoundInstrument';
export * from './metrics/Meter';
Expand Down
8 changes: 2 additions & 6 deletions api/src/metrics/NoopMeter.ts
Expand Up @@ -33,7 +33,7 @@ import {
BoundCounter,
BoundBaseObserver,
} from './BoundInstrument';
import { CorrelationContext } from '../correlation_context/CorrelationContext';
import { Baggage } from '../baggage/Baggage';
import { SpanContext } from '../trace/span_context';
import { ObserverResult } from './ObserverResult';

Expand Down Expand Up @@ -198,11 +198,7 @@ export class NoopBoundCounter implements BoundCounter {
}

export class NoopBoundValueRecorder implements BoundValueRecorder {
record(
_value: number,
_correlationContext?: CorrelationContext,
_spanContext?: SpanContext
): void {
record(_value: number, _baggage?: Baggage, _spanContext?: SpanContext): void {
return;
}
}
Expand Down
2 changes: 1 addition & 1 deletion api/src/trace/span_context.ts
Expand Up @@ -18,7 +18,7 @@ import { TraceState } from './trace_state';

/**
* A SpanContext represents the portion of a {@link Span} which must be
* serialized and propagated along side of a {@link CorrelationContext}.
* serialized and propagated along side of a {@link Baggage}.
*/
export interface SpanContext {
/**
Expand Down

0 comments on commit ecf6eb7

Please sign in to comment.