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

Commit

Permalink
feat: make context.active() the default value for context functions
Browse files Browse the repository at this point in the history
Signed-off-by: naseemkullah <[email protected]>
  • Loading branch information
naseemkullah committed Apr 2, 2021
1 parent 504041a commit ccc3599
Showing 1 changed file with 12 additions and 12 deletions.
24 changes: 12 additions & 12 deletions src/context/context.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
*/

import { Context } from './types';
import { Baggage, Span, SpanContext } from '../';
import { Baggage, context, Span, SpanContext } from '../';
import { NoopSpan } from '../trace/NoopSpan';

/**
Expand All @@ -39,20 +39,20 @@ const BAGGAGE_KEY = createContextKey('OpenTelemetry Baggage Key');
/**
* Return the span if one exists
*
* @param context context to get span from
* @param ctx context to get span from
*/
export function getSpan(context: Context): Span | undefined {
return (context.getValue(SPAN_KEY) as Span) || undefined;
export function getSpan(ctx = context.active()): Span | undefined {
return (ctx.getValue(SPAN_KEY) as Span) || undefined;
}

/**
* Set the span on a context
*
* @param context context to use as parent
* @param ctx context to use as parent
* @param span span to set active
*/
export function setSpan(context: Context, span: Span): Context {
return context.setValue(SPAN_KEY, span);
export function setSpan(ctx = context.active(), span: Span): Context {
return ctx.setValue(SPAN_KEY, span);
}

/**
Expand Down Expand Up @@ -82,10 +82,10 @@ export function getSpanContext(context: Context): SpanContext | undefined {
* Sets value on context to indicate that instrumentation should
* be suppressed beyond this current scope.
*
* @param context context to set the suppress instrumentation value on.
* @param ctx context to set the suppress instrumentation value on.
*/
export function suppressInstrumentation(context: Context): Context {
return context.setValue(SUPPRESS_INSTRUMENTATION_KEY, true);
export function suppressInstrumentation(ctx = context.active()): Context {
return ctx.setValue(SUPPRESS_INSTRUMENTATION_KEY, true);
}

/**
Expand All @@ -109,15 +109,15 @@ export function isInstrumentationSuppressed(context: Context): boolean {
}

/**
* @param {Context} Context that manage all context values
* @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 {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 {
Expand Down

0 comments on commit ccc3599

Please sign in to comment.