Skip to content

[@sentry/tracing][express] Span is lost for last middleware #3001

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

Closed
xr0master opened this issue Oct 25, 2020 · 1 comment · Fixed by #3022
Closed

[@sentry/tracing][express] Span is lost for last middleware #3001

xr0master opened this issue Oct 25, 2020 · 1 comment · Fixed by #3022

Comments

@xr0master
Copy link
Contributor

xr0master commented Oct 25, 2020

issue

It happens because of event finish order.
In handler:
https://github.com/getsentry/sentry-javascript/blob/master/packages/node/src/handlers.ts#L65
In express
https://github.com/getsentry/sentry-javascript/blob/master/packages/tracing/src/integrations/express.ts#L121

The handlers listener fires before express, as result the last spin has been filtered in:
https://github.com/getsentry/sentry-javascript/blob/master/packages/tracing/src/transaction.ts#L90
because the last span still doesn't have the endTimestamp

2 options to fix this issue:

  1. use close listener instead of finish in handlers.ts. The close event runs after finish.
res.once('close', () => {
    transaction.setHttpStatus(res.statusCode);
    transaction.finish();
});
  1. finish all spans if transaction.finish(); runs
const finishedSpans = this.spanRecorder ? this.spanRecorder.spans
    .reduce((spans, s) => {
        !s.endTimestamp && s.finish();
        s !== this && spans.push(s);

        return spans;
    }, []) : [];

Let me know which option is best for you.

@xr0master xr0master changed the title [@sentry/tracing][express] Spin is lost for last middleware [@sentry/tracing][express] Span is lost for last middleware Oct 27, 2020
@xr0master
Copy link
Contributor Author

any updates?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants