Skip to content
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/bun] Recent update breaks bun integration #15827

Open
3 tasks done
ShaneIsrael opened this issue Mar 25, 2025 · 12 comments
Open
3 tasks done

[@sentry/bun] Recent update breaks bun integration #15827

ShaneIsrael opened this issue Mar 25, 2025 · 12 comments
Labels
Package: bun Issues related to the Sentry Bun SDK

Comments

@ShaneIsrael
Copy link

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

8.50.0

Framework Version

No response

Link to Sentry event

No response

Reproduction Example/SDK Setup

No response

Steps to Reproduce

  1. Use bun as your nodejs server
  2. Setup sentry

Expected Result

The application stands up without issue and sentry initializes correctly.

Actual Result

The application crashes with a TypeError error.

[2025-03-25 18:00:50] [Sentry] express is not instrumented. This is likely because you required/imported express before calling `Sentry.init()`.
[2025-03-25 18:00:50] 40 | 
[2025-03-25 18:00:50] 41 | /**
[2025-03-25 18:00:50] 42 |  * Instruments Bun.serve `fetch` option to automatically create spans and capture errors.
[2025-03-25 18:00:50] 43 |  */
[2025-03-25 18:00:50] 44 | function instrumentBunServeOptions(serveOptions) {
[2025-03-25 18:00:50] 45 |   serveOptions.fetch = new Proxy(serveOptions.fetch, {
[2025-03-25 18:00:50]                                 ^
[2025-03-25 18:00:50] TypeError: A Proxy's 'target' should be an Object
[2025-03-25 18:00:50]       at Proxy (/app/node_modules/@sentry/bun/build/esm/integrations/bunserver.js:45:28)
[2025
@getsantry getsantry bot moved this to Waiting for: Product Owner in GitHub Issues with 👀 3 Mar 25, 2025
@github-actions github-actions bot added the Package: bun Issues related to the Sentry Bun SDK label Mar 25, 2025
@AbhiPrasad
Copy link
Member

@ShaneIsrael thanks for writing in.

You said the version you were using was 8.50.0. If you upgrade to 9.x of the SDK, does the issue still occur?

@ShaneIsrael
Copy link
Author

@AbhiPrasad Same exact error with 9.9.0 as well.

@getsantry getsantry bot moved this to Waiting for: Product Owner in GitHub Issues with 👀 3 Mar 25, 2025
@AbhiPrasad
Copy link
Member

Could you share how you import and initialize Sentry? Also how you are running bun (in the CLI)? Just want to see what the exact starting conditions are.

@ShaneIsrael
Copy link
Author

ShaneIsrael commented Mar 25, 2025

The server is built in a docker image.

# use the official Bun image
# see all versions at https://hub.docker.com/r/oven/bun/tags
FROM oven/bun:1 AS base
WORKDIR /app

FROM base AS install
RUN mkdir -p /temp/dev
COPY package.json bun.lockb /temp/dev/
RUN cd /temp/dev && bun install --frozen-lockfile

# install with --production (exclude devDependencies)
RUN mkdir -p /temp/prod
COPY package.json bun.lockb /temp/prod/
RUN cd /temp/prod && bun install --frozen-lockfile --production

# copy node_modules from temp directory
# then copy all (non-ignored) project files into the image
FROM base AS prerelease
COPY --from=install /temp/dev/node_modules node_modules
COPY . .

# copy production dependencies and source code into final image
FROM base AS release
COPY --from=install /temp/prod/node_modules node_modules
COPY --from=prerelease /app/src src
COPY --from=prerelease /app/server.ts .
COPY --from=prerelease /app/package.json .
COPY --from=prerelease /app/entrypoint.sh .

# run the app
USER bun
EXPOSE 3000/tcp
ENTRYPOINT [ "bash", "entrypoint.sh" ]

// entrypoint.sh

#!/bin/bash
bun run migration:up && bun server.ts

// server.ts file

import 'dotenv/config'
import * as Sentry from '@sentry/bun'
import 'reflect-metadata'

Sentry.init({
  dsn: process.env.SENTRY_DSN,
  tracesSampleRate: 1.0,
  enabled: process.env.ENVIRONMENT !== 'development',
})

import express, { type Application } from 'express'
import Server from './src/index'

process.env.TZ = 'GMT'

const PORT: number = process.env.PORT ? Number.parseInt(process.env.PORT, 10) : 3000

const app: Application = express()
new Server(app, PORT)

// in the src/index file

Sentry.setupExpressErrorHandler(app)

@getsantry getsantry bot moved this to Waiting for: Product Owner in GitHub Issues with 👀 3 Mar 25, 2025
@ShaneIsrael
Copy link
Author

I should note, nothing in any of these files I shared has changed code wise in probably 2 months and we've had new builds and deploys going out daily without issue until this morning.

@AbhiPrasad
Copy link
Member

Did the version of bun change? Looks like https://bun.sh/blog/bun-v1.2.6 came out today. If you force pin to Bun v1.2.5, do you get the same error?

@paulxuca
Copy link

It only happens on the new version of bun released today. It looks like a change related to https://bun.sh/blog/bun-v1.2.6#faster-express-fastify broke the sentry integration

@getsantry getsantry bot moved this to Waiting for: Product Owner in GitHub Issues with 👀 3 Mar 25, 2025
@AbhiPrasad
Copy link
Member

Ah that seems like it. We should file a bug with bun!

@ShaneIsrael or @paulxuca could you open a GH issue with them and fill in the details about your apps? I can also leave a comment there too.

@ShaneIsrael
Copy link
Author

ShaneIsrael commented Mar 26, 2025 via email

@getsantry getsantry bot moved this to Waiting for: Product Owner in GitHub Issues with 👀 3 Mar 26, 2025
@getsantry getsantry bot moved this from Waiting for: Product Owner to Waiting for: Community in GitHub Issues with 👀 3 Mar 26, 2025
@ShaneIsrael
Copy link
Author

I have made a report here: oven-sh/bun#18496

@getsantry getsantry bot moved this from Waiting for: Community to Waiting for: Product Owner in GitHub Issues with 👀 3 Mar 26, 2025
@dzkfzn
Copy link

dzkfzn commented Mar 26, 2025

Image

same, I also experienced the same issue.

@AbhiPrasad
Copy link
Member

AbhiPrasad commented Mar 26, 2025

The current workaround is to either revert Bun to 1.2.3 OR remove the BunServer integration like so:

import * as Sentry from '@sentry/bun';

Sentry.init({
  dsn: '__MY_DSN__',
  integrations: function (integrations) {
    // integrations will be all default integrations
    return integrations.filter(function (integration) {
      return integration.name !== "BunServer";
    });
  },
  tracesSampleRate: 1.0,
});

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Package: bun Issues related to the Sentry Bun SDK
Projects
Status: No status
Development

No branches or pull requests

5 participants