-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
fix(apm): Sampling of traces #2500
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
Changes from 30 commits
94a9e2e
a92c730
715bd45
c82f1d8
7c8d803
895c188
b0870b6
a5b5f2b
2c662dc
b96e512
4139da7
5a66e0b
450259e
b29a8b4
86ce10f
a1b2496
ea581e7
3583578
2bbd2e7
c3f2750
de8fefa
29f392e
878a8fc
a2733e6
74a9894
319fe10
4332b35
7a114f5
a695cd9
498e3ff
26bee09
a2351ab
0ad436e
6d471b9
106905d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -30,39 +30,42 @@ function traceHeaders(): { [key: string]: string } { | |||||
|
|
||||||
| /** | ||||||
| * This functions starts a span. If argument passed is of type `Span`, it'll run sampling on it if configured | ||||||
| * and attach a `SpanRecorder`. If it's of type `SpanContext` and there is already a `Span` on the Scope, | ||||||
| * and attach a `SpanList`. If it's of type `SpanContext` and there is already a `Span` on the Scope, | ||||||
| * the created Span will have a reference to it and become it's child. Otherwise it'll crete a new `Span`. | ||||||
| * | ||||||
| * @param span Already constructed span which should be started or properties with which the span should be created | ||||||
| * @param spanOrSpanContext Already constructed span or properties with which the span should be created | ||||||
| * @param makeRoot This will just create the span as it is and will not attach it to the span on the scope (if there is one). | ||||||
| * Under some circumstances, in internal integrations, for example, this is used to make sure they are not interfering with each other. | ||||||
| */ | ||||||
| function startSpan(spanOrSpanContext?: Span | SpanContext, forceNoChild: boolean = false): Span { | ||||||
| function startSpan(spanOrSpanContext?: Span | SpanContext, makeRoot: boolean = false): Span { | ||||||
| // @ts-ignore | ||||||
| const that = this as Hub; | ||||||
| const scope = that.getScope(); | ||||||
| const client = that.getClient(); | ||||||
| const hub = this as Hub; | ||||||
| const scope = hub.getScope(); | ||||||
| const client = hub.getClient(); | ||||||
| let span; | ||||||
|
|
||||||
| if (!isSpanInstance(spanOrSpanContext) && !forceNoChild) { | ||||||
| if (scope) { | ||||||
| const parentSpan = scope.getSpan() as Span; | ||||||
| if (parentSpan) { | ||||||
| span = parentSpan.child(spanOrSpanContext); | ||||||
| } | ||||||
| if (!isSpanInstance(spanOrSpanContext) && !makeRoot && scope) { | ||||||
| const parentSpan = scope.getSpan() as Span; | ||||||
| if (parentSpan) { | ||||||
| span = parentSpan.child(spanOrSpanContext); | ||||||
| } | ||||||
| } | ||||||
|
|
||||||
| if (!isSpanInstance(span)) { | ||||||
| span = new Span(spanOrSpanContext, that); | ||||||
| span = new Span(spanOrSpanContext, hub); | ||||||
| } | ||||||
|
||||||
|
|
||||||
| if (span.sampled === undefined && span.transaction !== undefined) { | ||||||
| // We only roll the dice on sampling for "root" spans (transactions) because the childs inherit this state | ||||||
| if (span.sampled === undefined && !span.isChildSpan()) { | ||||||
|
||||||
| const sampleRate = (client && client.getOptions().tracesSampleRate) || 0; | ||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Similarly, isn't it a programming error if Shouldn't we be able to write simply:
Suggested change
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If there is no |
||||||
| span.sampled = Math.random() < sampleRate; | ||||||
| } | ||||||
|
|
||||||
| // We only want to create a span list if we sampled the transaction | ||||||
| // in case we will discard the span anyway because sampled == false, we safe memory and do not store child spans | ||||||
| if (span.sampled) { | ||||||
| const experimentsOptions = (client && client.getOptions()._experiments) || {}; | ||||||
| span.initFinishedSpans(experimentsOptions.maxSpans as number); | ||||||
| span.initSpanList(experimentsOptions.maxSpans as number); | ||||||
| } | ||||||
|
|
||||||
| return span; | ||||||
|
|
||||||
Uh oh!
There was an error while loading. Please reload this page.