oven-sh / bun

Incredibly fast JavaScript runtime, bundler, test runner, and package manager – all in one
https://bun.sh
Other
74.13k stars 2.76k forks source link

Prisma Optimize depends on `async_hooks.createHook` #13866

Open crishoj opened 1 month ago

crishoj commented 1 month ago

What is the problem this feature would solve?

Prisma Optimize, which just entered general availability, appears to rely on async_hooks.createHook:

┌─────────────────────────────────┐
│ See your Optimize dashboard at: │
│ https://optimize.prisma.io      │
└─────────────────────────────────┘
[bun] Warning: async_hooks.createHook is not implemented in Bun. Hooks can still be created but will never be called.
error: prisma:client:operation span is expected to be entered in the client extension when tracing is enabled
error: script "dev" exited with code 1

What is the feature you are proposing to solve the problem?

Implement async_hooks.createHook 🙏 🥺

What alternatives have you considered?

Going to bed instead of having fun with Bun 💤

paperdave commented 1 month ago

i've avoided implementing createHook because it has very concerning performance characteristics, and the node.js docs mark it as an experimental feature; Stability: 1. most code using createHook can use async_hooks.AsyncLocalStorage

prisma optimize is using @opentelemetry/context-async-hooks, which provides two exports: one using AsyncLocalStorage (the API which is not marked experimental), and one using createHook. It is probable that they can just use the other implementation (a one line change)

I'll keep this issue open until we can resolve Prisma Optimize.

re-thc commented 1 month ago

Seeing a similar problem drizzle-kit, so problem likely not restricted to prisma.

hlege commented 1 month ago

I’m experiencing the same issue in Next.js Canary with turbo: [bun] Warning: async_hooks.createHook is not implemented in Bun. Hooks can still be created but will never be called.

paperdave commented 1 month ago

i believe this one in Next.js is from react-server. for this case, the async hooks has no observable effect. the code in React is TODO and seems to be

Image

I've been tempted to upstream removing this call. the warning it emits is useful for places like prisma optimize where the thing does depend on async hooks, we can identify that.