-
Notifications
You must be signed in to change notification settings - Fork 225
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
handling subtleties with how span.end() impacts the run context
For example, this handles the problem case from #1964
- Loading branch information
Showing
6 changed files
with
105 additions
and
74 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
// This test case shows that `span.end()` impacts the current run context's | ||
// span stack, even if the ended span is not the current one. When s3 and s2 | ||
// are ended below, they are not the current span. | ||
// | ||
// Expected: | ||
// transaction "t0" | ||
// `- span "s1" | ||
// `- span "s2" | ||
// `- span "s3" | ||
// `- span "s4" | ||
|
||
const apm = require('../../../').start({ // elastic-apm-node | ||
captureExceptions: false, | ||
captureSpanStackTraces: false, | ||
metricsInterval: 0, | ||
cloudProvider: 'none', | ||
centralConfig: false, | ||
// ^^ Boilerplate config above this line is to focus on just tracing. | ||
serviceName: 'run-context-end-non-current-spans' | ||
}) | ||
|
||
const assert = require('assert').strict | ||
|
||
const t0 = apm.startTransaction('t0') | ||
const s1 = apm.startSpan('s1') | ||
setImmediate(function () { | ||
const s3 = apm.startSpan('s3') | ||
setImmediate(function () { | ||
const s4 = apm.startSpan('s4') | ||
// Ending a span removes it from the current run context, even if it is | ||
// not top of stack, or not even part of this run context. | ||
s3.end() // out of order | ||
s2.end() // not in this run context | ||
s4.end() | ||
assert(apm.currentSpan === s1) | ||
s1.end() | ||
t0.end() | ||
}) | ||
}) | ||
|
||
const s2 = apm.startSpan('s2') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters