getsentry / sentry-javascript

Official Sentry SDKs for JavaScript
https://sentry.io
MIT License
7.76k stars 1.52k forks source link

@sentry/bun not reporting any span data #12705

Open nzapponi opened 2 days ago

nzapponi commented 2 days ago

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.13.0

Framework Version

No response

Link to Sentry event

No response

SDK Setup/Reproduction Example

Entrypoint line 1:

import "./sentry.ts"

sentry.ts

import { SocketIoInstrumentation } from "@opentelemetry/instrumentation-socket.io";
import * as Sentry from "@sentry/bun";
import data from "../../../package.json";
import { SENTRY_DSN, SENTRY_ENVIRONMENT } from "./const";

Sentry.init({
  dsn: SENTRY_DSN,
  tracesSampleRate: 1.0,
  environment: SENTRY_ENVIRONMENT,
  release: data.version,
});

Sentry.addOpenTelemetryInstrumentation(new SocketIoInstrumentation());

Steps to Reproduce

  1. Start the bun server (which uses Express)
  2. Make an API call from the client (or curl) to the server

Expected Result

A trace of the API call from request to response, including all the middleware calls, database queries (I'm using pg), etc.

Actual Result

I get a trace, but every transaction just says "Empty - Transaction did not report any span data" This also happens on server-side events that I instrumented using await Sentry.startSpan(...): I get a trace that the span is there, but no data within it.

Screenshot 2024-06-30 at 16 05 21

andreiborza commented 2 days ago

Hi, thank you for reporting this. Could you please add debug: true to your sentry options and paste some output?

nzapponi commented 1 day ago

Thanks @andreiborza !

Here it is:

$ bun run --hot src/server.ts
Sentry Logger [log]: Initializing Sentry: process: 72557, thread: main.
Sentry Logger [log]: Integration installed: InboundFilters
Sentry Logger [log]: Integration installed: FunctionToString
Sentry Logger [log]: Integration installed: LinkedErrors
Sentry Logger [log]: Integration installed: RequestData
Sentry Logger [log]: Integration installed: Console
Sentry Logger [log]: Integration installed: Http
Sentry Logger [log]: Integration installed: NodeFetch
Sentry Logger [log]: Integration installed: OnUncaughtException
Sentry Logger [log]: Integration installed: OnUnhandledRejection
Sentry Logger [log]: Integration installed: ContextLines
Sentry Logger [log]: Integration installed: Context
Sentry Logger [log]: Integration installed: Modules
Sentry Logger [log]: Integration installed: BunServer
Sentry Logger [log]: Running in CommonJS mode.
Sentry Logger [debug]: @opentelemetry/api: Registered a global for diag v1.9.0.
Sentry Logger [debug]: @opentelemetry/api: Registered a global for trace v1.9.0.
Sentry Logger [debug]: @opentelemetry/api: Registered a global for context v1.9.0.
Sentry Logger [debug]: @opentelemetry/api: Registered a global for propagation v1.9.0.
Sentry Logger [warn]: @opentelemetry/instrumentation-socket.io Module socket.io has been loaded before @opentelemetry/instrumentation-socket.io so it might not work, please initialize it before requiring socket.io
Sentry Logger [warn]: @opentelemetry/instrumentation-socket.io Module socket.io has been loaded before @opentelemetry/instrumentation-socket.io so it might not work, please initialize it before requiring socket.io
  server:app Registered data model +0ms
[Sentry] express is not instrumented. This is likely because you required/imported express before calling `Sentry.init()`.
  server:app Bootstrapping services +0ms
  server:pg Initializing database +0ms
  server:pg Running migrations +0ms
  server:app Listening on port 28001... +0ms
nzapponi commented 1 day ago

Weird that it says Running in CommonJS mode... isn't it?

lforst commented 1 day ago

@nzapponi The logic for that log message basically just checks whether require is in the global namespace. This is a bit weird in bun, because it maximizes compatibility.

Could you provide a reproduction of where this is not working? Thanks! It's a bit hard to gauge things from looking afar.

nzapponi commented 1 day ago

Here is a sample repo to reproduce: https://github.com/nzapponi/bun-sentry-repro I keep getting no span data.

Thanks!

Screenshot 2024-07-02 at 11 53 10

chargome commented 1 day ago

Thank you @nzapponi, we'll look into it!

chargome commented 23 hours ago

@nzapponi it seems that there are issues regarding the auto-instrumentation with express and bun.

I keep getting no span data.

For now, although you do not receive auto-generated span data you can still make use of custom instrumentation and error monitoring for your app with your current setup.

We'll reference this issue once we have a fix.

nzapponi commented 23 hours ago

Ok thanks