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

Conversation

dyladan
Copy link
Member

@dyladan dyladan commented May 5, 2021

Fixes #2166 by providing a parent span with an invalid span context to the sampler

From the spec:

ShouldSample
Returns the sampling Decision for a Span to be created.

Required arguments:

  • Context with parent Span. The Span's SpanContext may be invalid to indicate a root span.

@codecov
Copy link

codecov bot commented May 5, 2021

Codecov Report

Merging #2185 (09f4333) into main (3f82ff4) will increase coverage by 1.07%.
The diff coverage is n/a.

❗ Current head 09f4333 differs from pull request most recent head f65c5c8. Consider uploading reports for the commit f65c5c8 to get more accurate results

@@            Coverage Diff             @@
##             main    #2185      +/-   ##
==========================================
+ Coverage   92.72%   93.79%   +1.07%     
==========================================
  Files         141       53      -88     
  Lines        5087     1709    -3378     
  Branches     1045      356     -689     
==========================================
- Hits         4717     1603    -3114     
+ Misses        370      106     -264     
Impacted Files Coverage Δ
...s/opentelemetry-core/src/platform/node/sdk-info.ts 0.00% <0.00%> (-100.00%) ⬇️
...pentelemetry-core/src/platform/node/performance.ts 0.00% <0.00%> (-100.00%) ⬇️
...emetry-api-metrics/src/platform/node/globalThis.ts 0.00% <0.00%> (-100.00%) ⬇️
...ckages/opentelemetry-exporter-zipkin/src/zipkin.ts 83.92% <0.00%> (-16.08%) ⬇️
...y-instrumentation-grpc/src/enums/AttributeNames.ts
...ges/opentelemetry-instrumentation-http/src/http.ts
...ontext-async-hooks/src/AsyncHooksContextManager.ts
...ges/opentelemetry-metrics/src/SumObserverMetric.ts
...emetry-instrumentation-grpc/src/instrumentation.ts
packages/opentelemetry-resources/src/Resource.ts
... and 81 more

@@ -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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Sampler doesn't honor SpanOptions#root
4 participants