-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
startSpan experience weird behavior with events #13848
Comments
Hi, thanks for writing in! I don't yet fully understand in what way the SDK has seemingly weird behaviour. Would you mind giving a bit of context, of what you are trying to achieve and what you want your traces to look like? |
Hi, unfortunately I can't find much information on how exactly startSpan behaves so I'm just going off of what I found when testing SDK and reading the available docs. So currently, I want to trace events that are wrapped with SomeClass.on('someEvent', async(data) => {
await withScope(async (scope)=>{
scope.setTag("user", data.user.id);
await startSpan({
name: "ChatHandler",
op: "processMessage",
}, async () => {
if(content === "!ping")
return await data.reply("Pong!");
await data.reply("Fail!")
});
});
}); I'm expecting the SDK to automatically treat each trace uniquely under the EventEmitter's callback function (which I may be wrong if that's not the intended behavior for spanStart). Instead, the trace "session" are being shared each time when the events are invoked. To better explain: Spans that are not under the event callback functions (i.e. Prisma call inside a startup function), will be traced as normal. |
All of this is intended behaviour and more or less matches what opentelemetry does for their tracing. I recommend you update your event handler to the following: SomeClass.on('someEvent', data => {
return Sentry.withIsolationScope(() => {
return Sentry.withActiveSpan(null, async () => {
Sentry.setTag('user', data.user.id);
await Sentry.startSpan(
{
name: 'ChatHandler',
op: 'processMessage',
},
async () => {
if (content === '!ping') return await data.reply('Pong!');
await data.reply('Fail!');
},
);
});
});
}); You probably read this already, but if not, I recommend this docs page: https://docs.sentry.io/platforms/javascript/tracing/instrumentation/custom-instrumentation/ It explains all the primitives. |
Ah sorry, I had a brainfart. Instead of doing |
This solves the issue, thanks again! |
@lforst Hi, so after running the software for a while, I did notice another behaivor. From the doc Is it possible that |
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
8.32.0
Framework Version
No response
Link to Sentry event
No response
Reproduction Example/SDK Setup
Assume two different file and
index.js
will always be the first to load ANDrequire("./main.js");
will be inserted somewhere in index.js for the main to run.index.js:
main.js:
Steps to Reproduce
Make sentry init run first (as intended) before other code (aka
require("./main.js");
will be set at the bottom of theindex.js
)Expected Result
All the tracing should process through properly when sentry is initialized first.
Actual Result
Span will eventually hit the 5 minutes timeout and be dropped unless
spanParent: null
is set insidestartSpan
(only required if the span is the parent of the rootSpan or "trace span").startSpan
will also reuse trace ID for the duration of the software's lifetime, requiring me to use the following workaround to ensure each event callback is assigned a unique rootSpan ID:The text was updated successfully, but these errors were encountered: