Skip to content

Commit

Permalink
fix: span compression handling could crash on a span without a set pa…
Browse files Browse the repository at this point in the history
…rent span (#2701)

Creating a span with a manual `{ childOf: 'some-traceparent-string' }` results
in a span without a parent `Span`. An attempt to compress it on .end()
needs to handle that.
  • Loading branch information
sakari authored May 20, 2022
1 parent 07b30a9 commit 4019c99
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/instrumentation/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -364,7 +364,7 @@ Instrumentation.prototype.addEndedSpan = function (span) {
this._encodeAndSendSpan(span.getBufferedSpan())
}

if (span.getParentSpan().ended || !span.isCompressionEligible()) {
if (!span.isCompressionEligible() || span.getParentSpan().ended) {
const buffered = span.getBufferedSpan()
if (buffered) {
this._encodeAndSendSpan(buffered)
Expand Down
1 change: 1 addition & 0 deletions test/agent.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -440,6 +440,7 @@ test('#startSpan()', function (t) {
t.notEqual(span._context.traceparent.id, '00f067aa0ba902b7')
t.strictEqual(span._context.traceparent.parentId, '00f067aa0ba902b7')
t.strictEqual(span._context.traceparent.flags, '01')
span.end()
agent.destroy()
t.end()
})
Expand Down

0 comments on commit 4019c99

Please sign in to comment.