-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
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
@sentry/node creates duplicate Transactions #15830
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? |
It is paramount to only run |
Sentry.init() gets called only once. The automatic instrumentations are triggered by imports. I am asking if there is a possibility on your side to ensure the patching of the http and https node modules by @sentry/instrumentation-http and @opentelemetry_sentry-patched/instrumentation-http is only applied once, because when it is, everything behaves as expected (no duplicated transactions). |
Hm, otel should already take care of not double patching. You're saying it behaves as expected when not double patched, have you tried patching anything on your side? Mind sharing? |
@andreiborza Is there another or better way to achieve this? |
I tried looking at your repro, but I have no idea what is going on and what is called where. We're diverging pretty far from how we intend people to use the node SDK here. My best guess is that somehow there are two processes of some sort running and one is properly instrumented and the other one isn't - potentially due to ESM. I understand way to little though how AdonisJS works though to be able to make a judgment call for that. |
@lforst The same behaviour happens in it, when you initialize Sentry and after that you have multiple http and https module imports (in my example I import them directly and then I import axios which also imports them, you can test this with ENV variable), you'll get multiple patches and duplicate transactions:
|
@smeubank It could be related. |
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: