Skip to content

Sentry breadcrumbs are not shown in the Express request context  #11516

@spacetoha

Description

@spacetoha

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

7.109.0

Framework Version

7.109.0

Link to Sentry event

https://bringlynl.sentry.io/discover/breadcrumbs-issue:746f68983de34056a2441ce2cfde2375/?field=title&field=event.type&field=project&field=user.display&field=timestamp&name=All+Events&project=4507056912269312&query=&sort=-timestamp&statsPeriod=24h&yAxis=count%28%29

SDK Setup

// You can also use ESM `import * as Sentry from "@sentry/node"` instead of `require`
import * as Sentry from "@sentry/node";
import { nodeProfilingIntegration, } from "@sentry/profiling-node";
import { captureConsoleIntegration } from "@sentry/integrations";
import express from "express";

const app = express();

Sentry.init({
  dsn: "DSN",
  integrations: [
    // enable HTTP calls tracing
   
    new Sentry.Integrations.Http({ tracing: true }),
    new Sentry.Integrations.Express({ app }),
   // captureConsoleIntegration(),
    // enable Express.js middleware tracing
    nodeProfilingIntegration()
  ],
  // Performance Monitoring
  tracesSampleRate: 1.0, //  Capture 100% of the transactions
  // Set sampling rate for profiling - this is relative to tracesSampleRate
  profilesSampleRate: 1.0,
});

// The request handler must be the first middleware on the app
app.use(Sentry.Handlers.requestHandler());

// TracingHandler creates a trace for every incoming request
app.use(Sentry.Handlers.tracingHandler());

// All your controllers should live here
app.get("/test-call", function rootHandler(req, res) {
  const message = 'This message is not shown as console log';
  console.log(message);
  Sentry.addBreadcrumb({
    message: message,
    level: "info",
  });
  res.send("OK")
});

// The error handler must be registered before any other error middleware and after all controllers
app.use(Sentry.Handlers.errorHandler());

// Optional fallthrough error handler
app.use(function onError(err, req, res, next) {
  // The error id is attached to `res.sentry` to be returned
  // and optionally displayed to the user for support.
  res.statusCode = 500;
  res.end(res.sentry + "\n");
});

app.get("/debug-sentry", function mainHandler(req, res) {
  throw new Error("My first Sentry error!");
});

app.listen(3000);

Steps to Reproduce

Sentry is not picking up console logs as breadcrumbs on HTTP requests for express integration.
Adding breadcrumbs explicitly does not work either.

Please find the playground project attached.

We recently stopped seeing breadcrumbs for all the HTTP requests.
We were able to reproduce this issue using a minimum viable project.

Expected Result

Console logs are being shown as breadcrumns in the sentry console on express HTTP event

Actual Result

Console logs are not being shown as breadcrumbs in the sentry console on express HTTP event

Metadata

Metadata

Assignees

No one assigned

    Labels

    BugPackage: nodeIssues related to the Sentry Node SDK

    Projects

    Status

    No status

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions