-
-
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
[Sentry] Express is not instrumented. This is likely because you required/imported express before calling Sentry.init()
#12056
Comments
Strange... I did some code refactoring, and didn't touch this part I shared at all.. somehow I'm not having this error anymore. I will close this issue for a bit, if I encounter it again, I'll reopen it |
Isse came back again, I have no idea why. I didn't change anything. tried to update to latest Sentry, didn't help. Tried to nuke node_modules. lock file and everything, still didn't work. This is some weird mystery... |
Hi there, Things changed in v8 a bit, most integrations are now automatically added and you no longer have to take care of those (with the exception of We recommend going through the migration guide here. You can use In your particular example, could you try removing |
hey, thanks for getting back @andreiborza! I did follow the migration guide, and used As you suggested, i removed |
If it helps, you may check my comment on another similar issue that was opened 2 days ago: |
If that help,s we can have a short screensharing call so u can get the context you need |
Have you updated to Could you please provide
I see a |
yes, updated just yesterday. And yes, same result.
Regarding bundler: I'm using @nx/esbuild, as it comes as built-in bundler in NX. Here is part of my NX project (this microservice) config: {
"name": "auth-service",
"$schema": "../../node_modules/nx/schemas/project-schema.json",
"sourceRoot": "apps/auth-service/src",
"projectType": "application",
"targets": {
"build": {
"executor": "@nx/esbuild:esbuild",
"outputs": ["{projectRoot}/build"],
"defaultConfiguration": "production",
"options": {
"platform": "node",
"outputPath": "{projectRoot}/build",
"format": ["cjs"],
"bundle": true,
"main": "apps/auth-service/src/main.ts",
"tsConfig": "apps/auth-service/tsconfig.app.json",
"assets": ["apps/auth-service/src/assets"],
"generatePackageJson": true,
"esbuildOptions": {
"sourcemap": true,
"outExtension": {
".js": ".js"
}
}
},
"configurations": {
"development": {},
"production": {
"generateLockfile": true,
"esbuildOptions": {
"sourcemap": false,
"outExtension": {
".js": ".js"
}
}
}
}
}, |
I figured why I stopped having this issue at that time, I removed sentry.setupExpressErrorHandler(app), that's why I didn't get that message. But the problem was still there, although I didn't see it in the console. So this issue is persistent |
So you should def. not remove the error handler :D Do you know if your app is being run as a CommonJS or ESM app? Basically, if you look into your build/dist folder, are the files in there using |
@amiranvarov @Nabil372 @cyrus-za @ollipa @ebosetalee @RubeCarton6231 @mr-moon Just a follow-up on this issue: Are you still getting this warning or was it resolved with a more recent version of the SDK? In case it works now, let us know by reacting with a 👍 to not notify everyone in this thread again. Regarding ESM vs. CJS: We have some docs on how to correctly set up Sentry with ESM and CJS https://docs.sentry.io/platforms/javascript/guides/node/install/ |
I'm having the same issue on the latest version of instrument.ts import { env } from './env'
import * as Sentry from '@sentry/node'
import { nodeProfilingIntegration } from '@sentry/profiling-node'
Sentry.init({
dsn: env.SENTRY_EXPRESS_DSN,
environment: env.NODE_ENV,
debug: env.NODE_ENV != 'production',
integrations: [nodeProfilingIntegration()],
// Tracing
tracesSampleRate: env.NODE_ENV != 'production' ? 1.0 : 0.5,
})
Sentry.profiler.startProfiler() index.ts import './instrument'
import 'express-async-errors'
import AppServer from './server'
import MongoDBClient from '@homa/db/client'
const db = MongoDBClient.getInstance()
db.span = '[tRPC][db]'
const server = new AppServer(db)
await server.start()
async function closeGracefully(signal: NodeJS.Signals) {
console.log(`*^!@4=====> Received signal to terminate: ${signal}`)
server.getServer?.close()
await db.close()
process.kill(process.pid, signal)
}
process.once('SIGINT', closeGracefully)
process.once('SIGTERM', closeGracefully) I followed the ESM instructions to no avail. There are no bugs in the sentry debug logs either. I can see spans and profiles on the sentry portal, but it's not picking up errors in the issues tab (which is my primary need). |
Your example looks different from the docs you linked - you have Also, you need to follow the express specific instructions here: https://docs.sentry.io/platforms/javascript/guides/express/#use |
As I mentioned, I tried that as well, and it does not worked.
…On Fri, Dec 13, 2024, 00:15 Francesco Gringl-Novy ***@***.***> wrote:
Your example looks different from the docs you linked - you have import
'./instrument' on the top of your file, instead of running this in
--import? Instrumentation sadly cannot work in this scenario, you have to
do e.g. node --import ./instrument.mjs ./index.mjs for instrumentation to
work, as described in
https://docs.sentry.io/platforms/javascript/guides/node/install/esm/.
—
Reply to this email directly, view it on GitHub
<#12056 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AJ2T6ANQVJZSUPPAMXQBGMD2FKJSTAVCNFSM6AAAAABHYT75LCVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDKNBQHA2DAMBZGM>
.
You are receiving this because you commented.Message ID:
***@***.***>
|
Sorry, there are a lot of messages in this issue, it can be hard to keep track of what belongs where. What I would ask of you is:
|
Okay so I am also getting the same issue.
Console Code
Logs:
Sentry Logger [log]: Initializing Sentry: process: 20132, thread: main. Sentry Logger [debug]: @opentelemetry_sentry-patched/instrumentation-http outgoingRequest on response() |
@ritvick I'm not seeing any logs that Also, which version of Express are you using? |
Also having this issue.
instrument.js:
webserver.js:
server output:
One thing I noticed in the sentry debug logs is that it says "Running in CommonJS mode." when I'm using ESM.. That output is from starting it via I have also run it via Node version 18. Thanks! |
@OakBehringer if you remove the |
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.0.0
Framework Version
express@^4.18.1, @nx/express": "18.2.2
Link to Sentry event
No response
SDK Setup
Steps to Reproduce
I did right as you suggested it in your docs. Imprted and initialised Sentry first thing first. But still, it's not working
Expected Result
Do not have [Sentry] Express is not instrumented. This is likely because you required/imported express before calling
Sentry.init()
message, andActual Result
Having error message: [Sentry] Express is not instrumented. This is likely because you required/imported express before calling
Sentry.init()
message, andThe text was updated successfully, but these errors were encountered: