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

Transactions aren't capturing async child spans #3659

Closed
5 tasks done
jpike88 opened this issue Jun 9, 2021 · 8 comments
Closed
5 tasks done

Transactions aren't capturing async child spans #3659

jpike88 opened this issue Jun 9, 2021 · 8 comments
Assignees

Comments

@jpike88
Copy link

jpike88 commented Jun 9, 2021

Package + Version

  • @sentry/node

Version:

6.5.1

Description

const transaction = Sentry.startTransaction({
					op: encodedApiFunctionToRealName[finalPublicMethodName],
					name: encodedApiFunctionToRealName[finalPublicMethodName],
				});

				try {
					const result = await auth(accessToken);
transaction.finish();
}
})

In the above code, many mysql functions are running, but none of the spans are showing up in the log. I breakpointed inside @sentry/tracing/dist/integrations/mysql.js, and the problem seems to be this code is failing:

const parentSpan = scope?.getSpan();

getSpan() returns undefined.

The transaction logic doesn't seem to be very 'smart', it's not propagating the scope properly via the stack.

This is a big problem for our business, we want to switch to your product from Elastic APM but this makes that untenable.

@jpike88
Copy link
Author

jpike88 commented Jun 9, 2021

The elastic-apm-node library may provide some insight on how to redesign things better

@jpike88 jpike88 changed the title Transactions aren't capturing child spans in mysql Transactions aren't capturing async child methods Jun 9, 2021
@jpike88 jpike88 changed the title Transactions aren't capturing async child methods Transactions aren't capturing async child spans Jun 9, 2021
@AdriVanHoudt
Copy link

You might need to do

        Sentry.configureScope((scope) => {

            scope.setSpan(transaction);
        });

@jpike88
Copy link
Author

jpike88 commented Jun 9, 2021

I'll try within the next hour. Why isn't that done by default?

@AdriVanHoudt
Copy link

No clue 🤷 , it is in the example on https://docs.sentry.io/platforms/node/performance/

@jpike88
Copy link
Author

jpike88 commented Jun 9, 2021

wtf it actually worked. but this to me still seems like bizarre/unexpected behaviour and warrants further explanation or maybe a fix

@AdriVanHoudt
Copy link

My guess would be that you need to do this for your 'root' transaction but startTransaction doesn't know if it is the 'root' one so it can't do it automatically. But no clue if that is actually the reason :D
Glad it works now for you.

Since you're switching you might run into #3660 as well btw.

@jpike88
Copy link
Author

jpike88 commented Jun 9, 2021

Yeah weird. With elastic-apm-node I just had an init call, and a simple one liner in the block of interest, no need to finish it or call any weird methods:

apm.setTransactionName('blah');

I hope this lib can learn from the others and implement a simpler approach.

@smeubank
Copy link
Member

smeubank commented Jan 12, 2023

it actually worked.

we are aware of this issue, and at least for this specific topic it appears a fix was possible so I will close the issue and we address overarching topic internally

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

No branches or pull requests

5 participants