sentry-javascript: startTransaction method no longer returning transaction
Is there an existing issue for this?
- I have checked for existing issues https://github.com/getsentry/sentry-javascript/issues
- I have reviewed the documentation https://docs.sentry.io/
- I am using the latest SDK release https://github.com/getsentry/sentry-javascript/releases
How do you use Sentry?
Saas (sentry.io)
Which package are you using?
SDK Version
6.18.2
Framework Version
No response
Link to Sentry event
No response
Steps to Reproduce
We are using Nestjs and create spanned transactions for logging. Recently upgraded from 6.11.0 to 6.18.2 and began seeing the issue. Here’s just a bit of sample usage:
const { method, headers, url } = this.request;
const transaction = Sentry.startTransaction({
name: `Route: ${method} ${url}`,
op: 'transaction'
});
Sentry.getCurrentHub().configureScope((scope) => {
scope.setSpan(transaction);
scope.setContext('http', {
method,
url,
headers
});
});
Transaction is undefined in this instance so a scope is never configured. I have tested the startTransaction method in two separate projects and both are experiencing the same issue. Downgrading library back to 6.11.0 fixes the issue.
Expected Result
startTransaction method should return an instance of transaction so it can be used for proper scoping.
Actual Result
When pulling the scoped span via Sentry.getCurrentHub().getScope()?.getSpan(); I am receiving undefined as the span was never created properly due to the transaction being undefined.
About this issue
- Original URL
- State: closed
- Created 2 years ago
- Reactions: 14
- Comments: 24 (6 by maintainers)
Commits related to this issue
- Bugfix: make Transaction great again! https://github.com/getsentry/sentry-javascript/issues/4731 — committed to coffeacloudberry/galleria by coffeacloudberry 2 years ago
- fix: explicitely import @sentry/tracing see https://github.com/getsentry/sentry-javascript/issues/4731 — committed to andipaetzold/zwiftmap by andipaetzold 2 years ago
You can use:
import "@sentry/tracing"when importing@sentry/nodeas a temporary workaround while we’re working on this.Name-space imports such as:
import * as Tracing from "@sentry/tracing"currently don’t inject relevant functionality unless you specifically useTracingsomewhere in your project.@JVMartin just checked back with the rest of the team. In short: The way you’ve set up things right now is the intended and correct way. We have updated the docs to list
import '@sentry/tracing';as a required import statement.For anyone stumbling onto this issue, please import as follows for tracing to work:
Importing the
@sentry/tracingpackage before callingSentry.startTransaction()fixed the issue for me.This repo is not mine, but is affected with the same issue
If you were to update the sentry SDK to current in the project, you’ll see the error being thrown.
I am also getting the undefined transaction issue for a Nest JS API. In my case it only happens on windows, I tested on a Macbook Air with an M1 chip and transactions where working properly but tested on two PCs (Windows 10 and 11) and I am not able to create transactions. I also got the idea of trying with version 6.11.0 of @sentry/node and transactions started working
Thanks @crice88, saw your message on StackOverflow. I am the owner of the Nest.js example. I can reproduce the bug on my side as well. I am not sure what’s happening so far. It seems I have another error in my log:
Sentry Logger [Warn]: Extension method startTransaction couldn't be found, doing nothing.As you said this started after upgrading from 6.11. My repo hasn’t changed since Aug 18, 2021.
Encountered the same problem. Confirming that
import "@sentry/tracing"as a workaround fixes the issue.@lforst Even tho it’s documented like that, given all the comments and confusion in this ticket, it’s rather unexpected.
How about something like this:
Even if its useless and does nothing, but it adds the syntactic sugar to avoid confusion.
Still facing this issue with version
"@sentry/node": "7.14.2",. Any update on this?In 6.19.6 having a
import "@sentry/tracing";statement is still mandatory for a normal (unbundled) Node.js application. 😕Manually reverting eb09c284180d5024158b569adb343468457a50ed solved this for me.
@onurtemizkan I can submit a PR to revert, but unsure of the consequences of that.6.19.4 confirmed good
@SimonSchick Sometimes your bundler might be a little too smart and will remove the import statement that has no use. Try
import * as Tracing from "@sentry/tracing";, then use it somewhere below likeTracing && true;.Encountering the same issue after updating to sentry sdk latest version
6.19.6, this unfortunately caused us some downtime, can you please alter the return type ofstartTransactionto include| undefined? This would be a temporary indicator so at least some or your users will not be affected.Adding
import '@sentry/tracing';as an explicit import doesn’t seem to affect this either, (we already import parts of it elsewhere in the code base).Hi, @crice88.
This is very odd.
startTransaction, when set up correctly, should always return a transaction, so what this says to me is that the guys of the function aren’t getting injected the way they should. Here is the code that does that, which runs when@sentry/tracingis imported.I can’t think right now of any change we’ve made at all recently which would affect that. Would you be able to provide a minimal repro for us to poke at?