Skip to content

CaptureMessage not including full stack trace via console integration on node server #18094

@md384

Description

@md384

Is there an existing issue for this?

How do you use Sentry?

Self-hosted/on-premise

Which SDK are you using?

@sentry/node

SDK Version

10.21.0

Framework Version

No response

Link to Sentry event

No response

Reproduction Example/SDK Setup

Sentry.init({
  dsn: SENTRY_DSN,
  attachStacktrace: true,
  integrations: [
    Sentry.captureConsoleIntegration({ levels: ['error'] }),
    Sentry.extraErrorDataIntegration({ captureErrorCause: true }),
  ],
  ...
})

Steps to Reproduce

We are observing the behaviour in our node express app.

Log only a message (i.e. not containing an Error object) so captureMessage is called via the captureConsoleIntegration.

console.error('Some error happened here')

Expected Result

A stacktrace including a frame with the file and lineno where the console.error is called - for example (note this is an example from the client app where stacktraces are working)

null: Some error happened here
  at captureMessage(../../../node_modules/@sentry/core/src/exports.ts:44:28)
  at callback(../../../node_modules/@sentry/core/src/integrations/captureconsole.ts:90:95)
  at AsyncContextStack.withScope(../../../node_modules/@sentry/core/src/asyncContext/stackStrategy.ts:48:28)
  at withScope(../../../node_modules/@sentry/core/src/asyncContext/stackStrategy.ts:134:33)
  at withScope(../../../node_modules/@sentry/core/src/currentScopes.ts:65:14)
  at consoleHandler(../../../node_modules/@sentry/core/src/integrations/captureconsole.ts:62:3)
  at handler(../../../node_modules/@sentry/core/src/integrations/captureconsole.ts:43:9)
  at triggerHandlers(../../../node_modules/@sentry/core/src/instrument/handlers.ts:58:68)
  at error(../../../node_modules/@sentry/core/src/instrument/console.ts:36:9)
  at initHelper(index.client.jsx:321:11)
  at <anonymous>(index.client.jsx:529:5)

Actual Result

null: Some error happened here
  File "/node_modules/@sentry/core/build/cjs/integrations/captureconsole.js", line 78, col 15
    exports$1.captureMessage(message, captureContext);
  File "/node_modules/@sentry/opentelemetry/build/cjs/index.js", line 1308, col 14
    return callback(getCurrentScope());
  File "node:internal/async_local_storage/async_hooks", line 91, col 14, in AsyncLocalStorage.run
  File "/node_modules/@opentelemetry/context-async-hooks/build/src/AsyncLocalStorageContextManager.js", line 33, col 40, in SentryContextManager.with
    return this._asyncLocalStorage.run(context, cb, ...args);
  File "/node_modules/@sentry/opentelemetry/build/cjs/index.js", line 1433, col 24, in SentryContextManager.with
    return super.with(ctx2, fn, thisArg, ...args);
  File "/node_modules/@opentelemetry/api/build/src/api/context.js", line 60, col 46, in ContextAPI.with
    return this._getContextManager().with(context, fn, thisArg, ...args);
  File "/node_modules/@sentry/opentelemetry/build/cjs/index.js", line 1307, col 28, in Object.withScope
    return api.context.with(ctx, () => {
  File "/node_modules/@sentry/core/build/cjs/currentScopes.js", line 61, col 14, in Module.withScope
    return acs.withScope(rest[0]);

only sentry and internal frames.

Additional Context

  • All the issues have the title AsyncLocalStorage.run.
  • I think this might have started after upgrading from JS SDK v8 to v10 - it has affected multiple v10 versions (we've tried 10.11.0, 10.13.0, 10.22.0)
  • Log calls with an Error in the args get a correct stacktrace - i.e. the stacktrace from the Error.
  • Log messages from the client (via @sentry/react) do get a correct stacktrace in the issue
  • Using latest node v22

Tip: React with 👍 to help prioritize this issue. Please use comments to provide useful context, avoiding +1 or me too, to help us triage it.

Metadata

Metadata

Assignees

Projects

Status

No status

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions