-
Notifications
You must be signed in to change notification settings - Fork 225
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: span compression bug where a buffered span would not be sent when an incompressible sibling ended #3076
Conversation
…n an incompressible sibling ended https://github.com/elastic/apm/blob/main/specs/agents/handling-huge-traces/tracing-spans-compress.md#span-buffering says: > A buffered span gets reported when > 1. its parent ends > 2. a non-compressible sibling ends Before this change, case 2 was not being handled. Further, a possibly buffered span on the ending sibling would incorrectly get sent *twice*. The scenario is as follows: trans t0 span s1: _bufferdSpan=s2 span s2: ended, compressible -> buffered on s1 span s3: incompressible, _bufferdSpan=s4 span s4: ended, compressible -> buffered on s3 What happens when s3 ends? We expect: - s4 is encoded and sent - s2 is encoded and sent - s3 is encoded and sent Before this change the agent would send: s4, s4, s3 Refs: https://discuss.elastic.co/t/apm-agent-send-duplicate-record-in-mysql/321440
…tor to avoid numerous calls to .getParentSpan()
@@ -414,24 +414,26 @@ Instrumentation.prototype.addEndedSpan = function (span) { | |||
// if I have ended and I have something buffered, send that buffered thing | |||
if (span.getBufferedSpan()) { | |||
this._encodeAndSendSpan(span.getBufferedSpan()) | |||
span.setBufferedSpan(null) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
REVIEW NOTE: This clearing avoids the bug where we would encode and send a span twice -- the first time here, the second time in the next if-block.
const buffered = parentSpan && parentSpan.getBufferedSpan() | ||
if (buffered) { | ||
this._encodeAndSendSpan(buffered) | ||
span.setBufferedSpan(null) | ||
parentSpan.setBufferedSpan(null) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
REVIEW NOTE: This corrects the logic to make the spec pseudo code: this block is meant to be able looking at the possibly buffered span on the parent. This fixes the case where a buffered span would not get sent if it was followed by an incompressible sibling span.
Here is a snippet of the output of a test run showing the newly added test failing before the fix:
|
[email protected] is published with this fix now. |
…lemetry-actions * upstream/main: (148 commits) chore(deps): bump jsonwebtoken and @azure/msal-node (elastic#3087) fix bitrot.js dev-util to work for Next.js versions (elastic#3086) synchronize json schema specs (elastic#3082) chore(deps): bump json5 from 1.0.1 to 1.0.2 (elastic#3085) synchronize json schema specs (elastic#3078) chore(deps-dev): bump fastify from 4.10.2 to 4.11.0 (elastic#3083) chore(deps): bump next (elastic#3081) docs: fix header name with sampled flag (elastic#3069) 3.41.1 (elastic#3077) fix: span compression bug where a buffered span would not be sent when an incompressible sibling ended (elastic#3076) chore(deps-dev): bump wait-on from 6.0.1 to 7.0.1 (elastic#3075) chore(deps-dev): bump undici from 5.12.0 to 5.14.0 (elastic#3068) chore(deps-dev): bump got from 11.8.5 to 11.8.6 (elastic#3067) chore(deps-dev): bump koa from 2.13.4 to 2.14.1 (elastic#3066) chore(deps-dev): bump @hapi/hapi from 21.0.0 to 21.1.0 (elastic#3058) chore(deps-dev): bump @fastify/formbody from 7.3.0 to 7.4.0 (elastic#3057) 3.41.0 (elastic#3064) Support publishing a snapshot build for each commit to main (elastic#3050) fix: Add `tracestate` to the `TransactionOptions` TypeScript type (elastic#3063) fix: avoid IPv4 vs IPv6 ambiguity in default 'serverUrl' by using '127.0.0.1' rather than 'localhost' (elastic#3049) ...
…n an incompressible sibling ended (elastic#3076) https://github.com/elastic/apm/blob/main/specs/agents/handling-huge-traces/tracing-spans-compress.md#span-buffering says: > A buffered span gets reported when > 1. its parent ends > 2. a non-compressible sibling ends Before this change, case 2 was not being handled. Further, a possibly buffered span on the ending sibling would incorrectly get sent *twice*. The scenario is as follows: trans t0 span s1: _bufferdSpan=s2 span s2: ended, compressible -> buffered on s1 span s3: incompressible, _bufferdSpan=s4 span s4: ended, compressible -> buffered on s3 What happens when s3 ends? We expect: - s4 is encoded and sent - s2 is encoded and sent - s3 is encoded and sent Before this change the agent would send: s4, s4, s3 Refs: https://discuss.elastic.co/t/apm-agent-send-duplicate-record-in-mysql/321440
https://github.com/elastic/apm/blob/main/specs/agents/handling-huge-traces/tracing-spans-compress.md#span-buffering says:
Before this change, case 2 was not being handled. Further, a possibly
buffered span on the ending sibling would incorrectly get sent twice.
The scenario is as follows:
What happens when s3 ends? We expect:
Before this change the agent would send: s4, s4, s3
Refs: https://discuss.elastic.co/t/apm-agent-send-duplicate-record-in-mysql/321440