Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: use invalid parent for sampler when options.root #2185

Merged
merged 3 commits into from
May 13, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions packages/opentelemetry-tracing/src/Tracer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@

import * as api from '@opentelemetry/api';
import {
InstrumentationLibrary,
IdGenerator,
InstrumentationLibrary,
RandomIdGenerator,
sanitizeAttributes,
} from '@opentelemetry/core';
Expand Down Expand Up @@ -87,7 +87,9 @@ export class Tracer implements api.Tracer {
const attributes = sanitizeAttributes(options.attributes);
// make sampling decision
const samplingResult = this._sampler.shouldSample(
context,
options.root
? api.setSpanContext(context, api.INVALID_SPAN_CONTEXT)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think context.deleteValue(SPAN_KEY) would be the correct approach here. I have seen several places around where checks like if (getSpan(context) != null) are done to detect presence of a parent.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Spec states that "The Span's SpanContext may be invalid to indicate a root span." and there is no function to remove span from context currently. We don't have the SPAN_KEY outside of the API

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok.

Maybe we should add deleteSpan(context) (and deleteBaggage(context)) at some time?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe we should add deleteSpan(context) (and deleteBaggage(context)) at some time?

totally make sense

: context,
traceId,
name,
spanKind,
Expand Down