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

Unexpected Asynchronous Spans #1878

Closed
astorm opened this issue Nov 17, 2020 · 1 comment · Fixed by #1879
Closed

Unexpected Asynchronous Spans #1878

astorm opened this issue Nov 17, 2020 · 1 comment · Fixed by #1879
Assignees
Labels
agent-nodejs Make available for APM Agents project planning.

Comments

@astorm
Copy link
Contributor

astorm commented Nov 17, 2020

I ran into a situation where the Elastic Node.js Agent is marking span payloads with the sync=false key/value pair even when the spans themselves contain no asynchronous work.

Consider the following program

const http = require('http');

const requestListener = function (req, res) {
  const span1 = apm.startSpan('This is span 1')
  span1.end()
  const span2 = apm.startSpan('This is span 2')
  span2.end()
  const span3 = apm.startSpan('This is span 3')
  span3.end()
  res.writeHead(200);
  res.end('Hello, World!');
}

const server = http.createServer(requestListener);
server.listen(8080);

This program handles an HTTP request, and then manually starts and stops three spans. Payloads are generated for each span, and those payload have the value sync=false. As a user, my first instinct would be that these spans would be considered synchronous work.

It's unclear whether this is a bug, or a deliberate tradeoff decision to treat all NodeJS spans as async.

Next Steps: Investigate where and why these spans have their default sync=true property set to false.

@trentm
Copy link
Member

trentm commented Nov 17, 2020

Discussion:

Alan Storm
early debugging pointed to unrelated async work being able to set span.sync after a span had ended -- but I didn't want to go too deep down this rabbit hole without a map (edited)

Trent Mick
A guess:

  function before (asyncId) {
    const span = activeSpans.get(asyncId)
    if (span) {
      span.sync = false
    }

at this point the "ended" span is still in activeSpans (because that removal is async, I don't profess to be confident in this code path yet), but span.ended == true because that is set synchronously.

@astorm astorm added the agent-nodejs Make available for APM Agents project planning. label Nov 18, 2020
trentm added a commit that referenced this issue Nov 20, 2020
Sync spans (e.g. for template rendering) were having their span.sync==true
overwritten after having been ended, but before data was sent to the APM
server.

Fixes #1878
@trentm trentm self-assigned this Nov 20, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
agent-nodejs Make available for APM Agents project planning.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants