Skip to content

Using both Bun and Express leads to "express is not instrumented" warning (Bun not publishing to http Diagnostic Channel) #17779

Description

@RudolfSchreier

Is there an existing issue for this?

How do you use Sentry?

Sentry Saas (sentry.io)

Which SDK are you using?

@sentry/bun

SDK Version

10.15.0

Framework Version

Express 5.1.0

Link to Sentry event

No response

Reproduction Example/SDK Setup

https://github.com/RudolfSchreier/sentry-express-bun-demo

Steps to Reproduce

  1. Get a working SENTRY_DSN for some project
  2. start the demo using env SENTRY_DSN=... bun run dev

Expected Result

The express server starts up with working Sentry integration and no warnings.

Actual Result

The express server starts up, but with a Sentry warning about missing instrumentation:

[Sentry] express is not instrumented. Please make sure to initialize Sentry in a separate file that you --import when running node, see: https://docs.sentry.io/platforms/javascript/guides/express/install/esm/.

Additional Context

When using both Bun and Express, it is unclear which SDK to preferably use (@sentry/node or @sentry/bun), but both appear to show this issue.

It is unclear if the warning is correct or erroneous (and Express integration is actually working).

It is unclear to me from the description of #13674 if this the expected result for Express v5.

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.

Activity

  1. moved this to Waiting for: Product Owner in GitHub Issues with 👀 3on Sep 25, 2025
  2. s1gr1d commented on Sep 26, 2025

    @s1gr1d
    Member

    Hello, and thanks for your reproduction!

    The OTel-based Node SDKs need the instrument.ts file early-imported so it can run before the application starts. In Node, this flag is called --import, but in bun it's --preload.

    We probably need to update the docs and the log for this.

  3. moved this from Waiting for: Product Owner to No status in GitHub Issues with 👀 3on Sep 26, 2025
  4. self-assigned this
    on Sep 26, 2025
  5. RudolfSchreier commented on Sep 26, 2025

    @RudolfSchreier
    Author

    Hi and thanks for the triage :)

    The call to bun already uses --preload, and I am not quite sure what else to configure to make Bun behave more node-y here.

  6. moved this to Waiting for: Product Owner in GitHub Issues with 👀 3on Sep 26, 2025
  7. s1gr1d commented on Sep 26, 2025

    @s1gr1d
    Member

    Ah sorry, I missed this. I can have a closer look at this next week :)

    But this check if it's wrapped is throwing the warning:

    ensureIsWrapped(app.use, 'express');

    The function is using this OTel function under the hood. Either it's not instrumented correctly or the check is not correct.

  8. 51 remaining items

  9. moved this from Waiting for: Product Owner to No status in GitHub Issues with 👀 3on Jan 28, 2026
  10. ckblockit commented on Jan 28, 2026

    @ckblockit

    tl;dr;
    Is there a workaround to instrument Express when using it with Bun?

  11. moved this to Waiting for: Product Owner in GitHub Issues with 👀 3on Jan 28, 2026
  12. Lms24 commented on Jan 29, 2026

    @Lms24
    Member

    There is a semi-functional workaround @s1gr1d and I just found:

    If you require express instead of importing it, the express instrumentation can intercept the require call and patch it. But you also need to manually start the server span that would usually be started by the http instrumentation. Once that's started, the express instrumentation can correctly pick up middleware and request handler spans.

    Here's a simplified example:

    import * as SentryBun from "@sentry/bun";
    
    const express = require("express");
    
    const app = express();
    
    app.use((req, res, next) => {
      const rawUrl = `${req.method} ${req.path}`;
      return SentryBun.withIsolationScope((isolationScope) => {
        isolationScope.setTransactionName(rawUrl);
        return SentryBun.startSpan(
          {
            name: rawUrl,
            attributes: {
              "sentry.op": "http.server",
            },
          },
          () => {
            next();
          }
        );
      });
    
    
    // Add your routes and middlewares here
    
    app.get("/endpoint", (req, res) => {
      // ...
    });
    
    
    app.use(SentryBun.expressErrorHandler());
    
    app.listen(PORT, () => {
      console.log(`Server running on http://localhost:${PORT}`);
    });

    This is far from optimal of course but it at least should give you basic tracing. In my testing, this also isolated traces for individual requests. Take it with a grain of salt but maybe this helps you for the time being.

    I'd imagine you need to require other libraries like pg as well to get instrumentation for database spans working.

  13. moved this from Waiting for: Product Owner to No status in GitHub Issues with 👀 3on Jan 29, 2026
  14. itajenglish commented on Feb 15, 2026

    @itajenglish

    Hey @Lms24, Any updates from the Bun team?

  15. moved this to Waiting for: Product Owner in GitHub Issues with 👀 3on Feb 15, 2026
  16. s1gr1d commented on Feb 16, 2026

    @s1gr1d
    Member

    Hi, sadly no updates so far. I saw that @Lms24 also commented on the PR itself already: oven-sh/bun#24375 (comment)

    We'll keep you updated - until then we suggest to only comment on this issue to provide useful context on this topic. The state of the PR can be checked in the Bun repository (link above). Thank you 🙏

  17. moved this from Waiting for: Product Owner to No status in GitHub Issues with 👀 3on Feb 16, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

Projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions