-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
@sentry/node creates duplicate Transactions #15830
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
Comments
Thanks for opening this issue. It could be that this is the same or similar issue like #15803. We're going to take a look at this. |
@enixsoft Would you be able to provide a small reproduction example? |
@s1gr1d |
Hi, since this issue is about |
@lforst |
@enixsoft makes sense, however, we have no reason to believe that |
@lforst The automatically created transaction with name without hyphens is the one that doesn't have all the data and the one I consider an unnecessary duplicate for the same request and route. My understanding of this issue is that:
|
It's possible that not all requests are routed through that middleware which would mean that not all span names are updated. (or rather that that code path is not always hit but you know what I mean) |
I think I found the cause of the problem. The automatic instrumentation module patching can run more than once and when it does, this is when the duplicated transactions start to happen. I have updated the reproduction example in #15830 (comment) and added a preload file which imports axios (and axios imports http and https modules and this triggers the patching). Both modules are first patched right after the Sentry.init() call, then again by axios import. This is what I get by running the reproduction example and sending one request (GET /test/span/123):
And this is how it looks like in dashboard: Is it possible to make sure that the http and https module patching happens only once or can it be forced during the initialization of Sentry, so it is not triggered by import of the modules? |
@smeubank It could be related. |
Thanks for the reproduction! I just had time to look at this issue and I was able to pin it down to the version and a suspect PR, but still need to fix it. Until version
From version
The thing that's actually causing the double root spans are the imports from Another thing I noticed in your application: You are using ESM and you are supposed to start the application like this: |
@s1gr1d I still think what I said above could be the solution: Is it possible to make sure that the http and https module patching happens only once or can it be forced during the initialization of Sentry, so it is not triggered by import of the modules? |
The
Yes, this is an actual issue and needs to be fixed. We are on it - and thanks again for the reproduction! |
A PR closing this issue has just been released 🚀This issue was referenced by PR #16177, which was included in the 9.16.0 release. |
Is there an existing issue for this?
How do you use Sentry?
Sentry Saas (sentry.io)
Which SDK are you using?
@sentry/node
SDK Version
9.9.0
Framework Version
No response
Link to Sentry event
No response
Reproduction Example/SDK Setup
// middleware
import * as Sentry from '@sentry/node'
const activeSpan = Sentry.getActiveSpan()
const rootSpan = activeSpan && Sentry.getRootSpan(activeSpan)
if (rootSpan) {
// ctx.routeKey is string, for example "GET-/users"
Sentry.updateSpanName(rootSpan, ctx.routeKey || 'unknown')
}
Steps to Reproduce
I am using AdonisJS v6 framework with the Sentry integration rlanz/sentry v0.3.3 and @sentry/node package v9.9.0.
In my reproduction example there is a code from middleware that runs on every request and it's supposed to update the root span (transaction) name. The root span is expected to always be http.server operation with origin auto.http.otel.http.
In my Sentry dashboard, I see transactions on the sampled events with the correct updated name, they contain spans and have user attached, but I also see events from another transaction which is using the automatically generated name, but always without any spans and without user. Those duplicate transactions are easy to notice because the names are similar, the events are traced at the same time with nearly the same duration. Also the data (like request query string, headers, cookies) is same in both, so I assume that it's a duplicated transaction from the exact same request.
There is also other difference I see comparing the JSON of both sampled events which might explain this, the transaction with updated name by middleware has sentry.source: custom and
"transaction_info": { "source": "custom" }
in its data. And the duplicate has sentry.source: url and"transaction_info": { "source": "sanitized" }.
Expected Result
Only one transaction (the one with updated name) will appear in Sentry dashboard for specific request.
Actual Result
Transactions seem to be duplicated.
The text was updated successfully, but these errors were encountered: