Skip to content

Commit 0ae3e85

Browse files
Flarnadyladan
authored andcommitted
chore: improve naming of span related context APIs (open-telemetry#1749)
1 parent d6f983a commit 0ae3e85

File tree

3 files changed

+18
-24
lines changed

3 files changed

+18
-24
lines changed

api/src/context/context.ts

+14-20
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,9 @@ import { Context, createContextKey } from '@opentelemetry/context-base';
1818
import { Baggage, NoopSpan, Span, SpanContext } from '../';
1919

2020
/**
21-
* Active span key
21+
* span key
2222
*/
23-
const ACTIVE_SPAN_KEY = createContextKey(
24-
'OpenTelemetry Context Key ACTIVE_SPAN'
25-
);
23+
const SPAN_KEY = createContextKey('OpenTelemetry Context Key SPAN');
2624

2725
/**
2826
* Shared key for indicating if instrumentation should be suppressed beyond
@@ -38,49 +36,45 @@ const SUPPRESS_INSTRUMENTATION_KEY = createContextKey(
3836
const BAGGAGE_KEY = createContextKey('OpenTelemetry Baggage Key');
3937

4038
/**
41-
* Return the active span if one exists
39+
* Return the span if one exists
4240
*
4341
* @param context context to get span from
4442
*/
45-
export function getActiveSpan(context: Context): Span | undefined {
46-
return (context.getValue(ACTIVE_SPAN_KEY) as Span) || undefined;
43+
export function getSpan(context: Context): Span | undefined {
44+
return (context.getValue(SPAN_KEY) as Span) || undefined;
4745
}
4846

4947
/**
50-
* Set the active span on a context
48+
* Set the span on a context
5149
*
5250
* @param context context to use as parent
5351
* @param span span to set active
5452
*/
55-
export function setActiveSpan(context: Context, span: Span): Context {
56-
return context.setValue(ACTIVE_SPAN_KEY, span);
53+
export function setSpan(context: Context, span: Span): Context {
54+
return context.setValue(SPAN_KEY, span);
5755
}
5856

5957
/**
60-
* Wrap extracted span context in a NoopSpan and set as active span in a new
58+
* Wrap span context in a NoopSpan and set as span in a new
6159
* context
6260
*
6361
* @param context context to set active span on
6462
* @param spanContext span context to be wrapped
6563
*/
66-
export function setExtractedSpanContext(
64+
export function setSpanContext(
6765
context: Context,
6866
spanContext: SpanContext
6967
): Context {
70-
return setActiveSpan(context, new NoopSpan(spanContext));
68+
return setSpan(context, new NoopSpan(spanContext));
7169
}
7270

7371
/**
74-
* Get the span context of the parent span if it exists,
75-
* or the extracted span context if there is no active
76-
* span.
72+
* Get the span context of the span if it exists.
7773
*
7874
* @param context context to get values from
7975
*/
80-
export function getParentSpanContext(
81-
context: Context
82-
): SpanContext | undefined {
83-
return getActiveSpan(context)?.context();
76+
export function getSpanContext(context: Context): SpanContext | undefined {
77+
return getSpan(context)?.context();
8478
}
8579

8680
/**

api/src/trace/NoopTracer.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ import { Span, SpanOptions, Tracer, SpanContext } from '..';
1818
import { Context } from '@opentelemetry/context-base';
1919
import { NoopSpan, NOOP_SPAN } from './NoopSpan';
2020
import { isSpanContextValid } from './spancontext-utils';
21-
import { getParentSpanContext } from '../context/context';
21+
import { getSpanContext } from '../context/context';
2222

2323
/**
2424
* No-op implementations of {@link Tracer}.
@@ -35,7 +35,7 @@ export class NoopTracer implements Tracer {
3535
return NOOP_SPAN;
3636
}
3737

38-
const parentFromContext = context && getParentSpanContext(context);
38+
const parentFromContext = context && getSpanContext(context);
3939

4040
if (
4141
isSpanContext(parentFromContext) &&

api/test/noop-implementations/noop-tracer.test.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ import {
2222
SpanKind,
2323
TraceFlags,
2424
context,
25-
setExtractedSpanContext,
25+
setSpanContext,
2626
} from '../../src';
2727

2828
describe('NoopTracer', () => {
@@ -70,7 +70,7 @@ describe('NoopTracer', () => {
7070
const span = tracer.startSpan(
7171
'test-1',
7272
{},
73-
setExtractedSpanContext(context.active(), parent)
73+
setSpanContext(context.active(), parent)
7474
);
7575
assert(span.context().traceId === parent.traceId);
7676
assert(span.context().spanId === parent.spanId);

0 commit comments

Comments
 (0)