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

Bun instrumentation stops working if reload is called on the server #15144

Open
3 tasks done
nathankleyn opened this issue Jan 23, 2025 · 2 comments · May be fixed by #15148
Open
3 tasks done

Bun instrumentation stops working if reload is called on the server #15144

nathankleyn opened this issue Jan 23, 2025 · 2 comments · May be fixed by #15148
Labels
Package: bun Issues related to the Sentry Bun SDK Waiting for: Product Owner

Comments

@nathankleyn
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.51.0

Framework Version

Bun 1.1.45

Link to Sentry event

No response

Reproduction Example/SDK Setup

Sentry.init({
  tracesSampleRate: 1.0,
  environment: "some_env",
});

// server before reloading is instrumented
const server = Bun.serve({
  async fetch(_req) {
    throw new Error("I should have instrumentation, and I do");
  },
  port: 3000,
});

// server after reloading is not instrumented
server.reload({
  async fetch(_req) {
    throw new Error("I should have instrumentation, but I don't");
  },
})

await fetch('http://localhost:3000/');

Steps to Reproduce

  1. Create a Bun server
  2. Reload the server
  3. Throw an error in the handler and look at the Sentry error

Reloading is done out of the box by some frameworks built on top of Bun Serve, like ElysiaJS (which does it after AOT / precompilation is completed).

Expected Result

The error should have instrumentation, such as request URL, request headers, browser information and trace information:

Image

Actual Result

The error has no instrumentation at all:

Image

@getsantry getsantry bot moved this to Waiting for: Product Owner in GitHub Issues with 👀 3 Jan 23, 2025
@github-actions github-actions bot added the Package: bun Issues related to the Sentry Bun SDK label Jan 23, 2025
nathankleyn added a commit to nathankleyn/sentry-javascript that referenced this issue Jan 23, 2025
If `#reload` is called on an instance of `Bun.serve`, the Sentry
intrumentation doesn't surive. This is because the Bun instrumentation
works by using `Proxy` on the call to `Bun.serve`, which isn't called
for a reload.

We can't wrap the serve created by calling `Bun.serve` with a `Proxy` as
Bun seems to do some internal checks using `instanceof` which break if
the instance is now reporting itself as a `ProxyObject`.

This fixes getsentry#15144.
@Lms24
Copy link
Member

Lms24 commented Jan 23, 2025

Hey @nathankleyn thanks for reporting this! I see you're already working on a fix for this? I had a quick look at the commit and it looks good to me. Are you interested in opening a PR once it's ready?

nathankleyn added a commit to nathankleyn/sentry-javascript that referenced this issue Jan 23, 2025
If `#reload` is called on an instance of `Bun.serve`, the Sentry
intrumentation doesn't surive. This is because the Bun instrumentation
works by using `Proxy` on the call to `Bun.serve`, which isn't called
for a reload.

We can't wrap the serve created by calling `Bun.serve` with a `Proxy` as
Bun seems to do some internal checks using `instanceof` which break if
the instance is now reporting itself as a `ProxyObject`.

This fixes getsentry#15144.
@nathankleyn
Copy link
Author

Hey @Lms24 — thanks so much for your superfast reply! I've raised the PR now at #15148 (review), although I hit a bit of a problem when I discovered the tests for the @sentry/bun basically all were not actually working in practice (silently nothing was being tested due to how the tests were structured).

I've reworked the tests a bit and raised a working version but I will definitely need a small amount of assistance to solve one last remaining problem with test isolation before it can be merged.

Thanks in advance!

@getsantry getsantry bot moved this to Waiting for: Product Owner in GitHub Issues with 👀 3 Jan 23, 2025
nathankleyn added a commit to nathankleyn/sentry-javascript that referenced this issue Jan 23, 2025
If `#reload` is called on an instance of `Bun.serve`, the Sentry
intrumentation doesn't surive. This is because the Bun instrumentation
works by using `Proxy` on the call to `Bun.serve`, which isn't called
for a reload.

We can't wrap the serve created by calling `Bun.serve` with a `Proxy` as
Bun seems to do some internal checks using `instanceof` which break if
the instance is now reporting itself as a `ProxyObject`.

This fixes getsentry#15144.
nathankleyn added a commit to nathankleyn/sentry-javascript that referenced this issue Jan 23, 2025
If `#reload` is called on an instance of `Bun.serve`, the Sentry
intrumentation doesn't surive. This is because the Bun instrumentation
works by using `Proxy` on the call to `Bun.serve`, which isn't called
for a reload.

We can't wrap the serve created by calling `Bun.serve` with a `Proxy` as
Bun seems to do some internal checks using `instanceof` which break if
the instance is now reporting itself as a `ProxyObject`.

This fixes getsentry#15144.
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 Waiting for: Product Owner
Projects
Status: Waiting for: Product Owner
Development

Successfully merging a pull request may close this issue.

2 participants