Missing @opentelemetry/api module at runtime when upgrading to 0.28.4

Just upgraded drizzle-orm to 0.28.4, and running my project (after a successful typecheck) I get the error Cannot find module '@opentelemetry/api'. Here is the full stack trace:
Require stack:
- C:\Users\...\node_modules\.pnpm\[email protected][email protected]\node_modules\drizzle-orm\index-b1dbb7ec.cjs
- C:\Users\...\node_modules\.pnpm\[email protected][email protected]\node_modules\drizzle-orm\postgres-js\index.cjs
- C:\Users\...\dist\global\services\drizzle.service.js
- C:\Users\ngreg\...\dist\modules\users\users.service.js
- C:\Users\ngreg\...\dist\app.module.js
- C:\Users\...\dist\main.js
at Function.Module._resolveFilename (node:internal/modules/cjs/loader:1072:15)
at Function.Module._load (node:internal/modules/cjs/loader:925:27)
at Module.require (node:internal/modules/cjs/loader:1139:19)
at require (node:internal/modules/helpers:121:18)
at Object.<anonymous> (C:\Users\...\node_modules\.pnpm\[email protected][email protected]\node_modules\drizzle-orm\index-b1dbb7ec.cjs:3:1)
at Module._compile (node:internal/modules/cjs/loader:1257:14)
at Object.Module._extensions..js (node:internal/modules/cjs/loader:1311:10)
at Module.load (node:internal/modules/cjs/loader:1115:32)
at Function.Module._load (node:internal/modules/cjs/loader:962:12)
at Module.require (node:internal/modules/cjs/loader:1139:19)
Require stack:
- C:\Users\...\node_modules\.pnpm\[email protected][email protected]\node_modules\drizzle-orm\index-b1dbb7ec.cjs
- C:\Users\...\node_modules\.pnpm\[email protected][email protected]\node_modules\drizzle-orm\postgres-js\index.cjs
- C:\Users\...\dist\global\services\drizzle.service.js
- C:\Users\ngreg\...\dist\modules\users\users.service.js
- C:\Users\ngreg\...\dist\app.module.js
- C:\Users\...\dist\main.js
at Function.Module._resolveFilename (node:internal/modules/cjs/loader:1072:15)
at Function.Module._load (node:internal/modules/cjs/loader:925:27)
at Module.require (node:internal/modules/cjs/loader:1139:19)
at require (node:internal/modules/helpers:121:18)
at Object.<anonymous> (C:\Users\...\node_modules\.pnpm\[email protected][email protected]\node_modules\drizzle-orm\index-b1dbb7ec.cjs:3:1)
at Module._compile (node:internal/modules/cjs/loader:1257:14)
at Object.Module._extensions..js (node:internal/modules/cjs/loader:1311:10)
at Module.load (node:internal/modules/cjs/loader:1115:32)
at Function.Module._load (node:internal/modules/cjs/loader:962:12)
at Module.require (node:internal/modules/cjs/loader:1139:19)
For reference I'm using PNPM and CJS
32 Replies
ak4zh
ak4zh17mo ago
Also I would like to know what is that @opentelemetry/api even doing in drizzle?
Screw
Screw17mo ago
+1 for this issue
Noahh
NoahhOP17mo ago
I don't know the codebase very well, so I might be wrong about it, but from a quick glance it looks like they use it for tracing (seen here https://github.com/drizzle-team/drizzle-orm/blob/594e96538e588fee5748e372884dbaf32c331524/drizzle-orm/src/postgres-js/session.ts#L29). I've never used opentelemetry, but it looks like it keeps very minimal information (a name, timestamp, duration, and not much else) that I'd assume helps the Drizzle team debug issues and benchmark. It also looks like (https://github.com/drizzle-team/drizzle-orm/blob/594e96538e588fee5748e372884dbaf32c331524/drizzle-orm/src/tracing.ts#L5) it is not required (although I don't know if it is an optional peer dependency or bundled with drizzle-orm), and for the record I don't see anywhere that would indicate the information is being sent anywhere. Again, take this with a grain of salt, this is from about 5 minutes of going through the codebase/open telemetry docs
GitHub
drizzle-orm/drizzle-orm/src/tracing.ts at 594e96538e588fee5748e3728...
TypeScript ORM that feels like writing SQL. Contribute to drizzle-team/drizzle-orm development by creating an account on GitHub.
GitHub
drizzle-orm/drizzle-orm/src/postgres-js/session.ts at 594e96538e588...
TypeScript ORM that feels like writing SQL. Contribute to drizzle-team/drizzle-orm development by creating an account on GitHub.
HimbothySwaggins
HimbothySwaggins17mo ago
So... installing the package solves this. Should this not be a peer dependency? Confused why this is a thing. Installing @opentelemetry/api until this is sorted I guess. 10/10 release
Noahh
NoahhOP17mo ago
If it's used for what I think it is used for, it seems like it should be an optional peer dependency. That was my takeaway from the code in tracing.ts linked above, since they check if it exists and skip it if it doesn't. Regardless, it's definitely a bug, I don't think Drizzle would require a peer dependency like that unless @bloberenober just wants to know all of our dirty little sweating
Noahh
NoahhOP17mo ago
Can confirm installing it works
Eureka
Eureka17mo ago
I ran into this, too nomore
Andrii Sherman
Andrii Sherman17mo ago
It’s not required and not used by us 😅 It came from one of beta releases to support opentelemetry for your projects So if you need to check query execution for your apps, you can install this package and setup your credentials for that After that it will send needed data you your OT instance It shouldn’t be required, so I guess @bloberenober will check why the error is back Drizzle ORM has 0 dependencies bundled, so nothing is required, unless you need specific driver to install
Amur
Amur17mo ago
Yeah also getting this error🙈
Andrii Sherman
Andrii Sherman17mo ago
Sending internal branch with fix to check sorry, was working on checking this one we will start doing beta/pre-prod/similar releases, I promise Let's check and fix this one give me 10 mins and I'll send you internal branch with fixes drizzle-orm@types-bugs Could someone please check this tag. It worked well for me
Amur
Amur17mo ago
seems to be working
Andrii Sherman
Andrii Sherman17mo ago
good need a few more approves, just to be sure
Amur
Amur17mo ago
now i'm a bit confused because if i deploy my lambdas locally then it works but if i deploy it through the aws codepipeline then it breaks with the same error
Andrii Sherman
Andrii Sherman17mo ago
You deploy same versions? No cache, etc.?
Amur
Amur17mo ago
yeah it should be the version drizzle-orm@types-bugs without any cache
Andrii Sherman
Andrii Sherman17mo ago
Not sure how it’s possible. I just commented all opentelemetry code for now, because we will rewrite it anyway
Andrii Sherman
Andrii Sherman17mo ago
GitHub
Types bugs by AndriiSherman · Pull Request #1107 · drizzle-team/dri...
The OTEL-specific functions have been removed from Postgres for now. They were added for testing purposes in the beta branch and were accidentally merged into the main branch. They have been left c...
Amur
Amur17mo ago
i'll look into it a bit further, might be something on my side
Boian Ivanov
Boian Ivanov17mo ago
I also had this issue this morning, but the drizzle-orm@types-bugs tag fixed it 🎉
Dan
Dan17mo ago
@here As @Andrew Sherman mentioned, the OpenTelemetry logic isn't meant to be used by Drizzle and no stats are collected by Drizzle. OpenTelemetry is simply a protocol. If you take a look at the actual code that uses it in drizzle-orm, it simply uses the tracer to collect the query stats and doesn't send it anywhere. It was designed for the ORM users to be able to send those stats to their own telemetry consumers. The important thing is - the OpenTelemetry logic is disabled on the current version. It literally does nothing. We experimented with it at some point in the past, but disabled it before the release. As to the reason of the current issue: it happens because of an incorrect type import on this line - https://github.com/drizzle-team/drizzle-orm/blob/main/drizzle-orm/src/tracing.ts#L1. I've used import {type ... } syntax instead of import type { ... }, which resulted in the import '@opentelemetry/api' line at runtime. This change was made some time ago and I have no idea why it became an issue only after the last release. In any case, I've fixed the immediate issue by fixing the type import and deployed a new drizzle-orm@beta version. Please test it and let me know if you still experience the error.
attka
attka17mo ago
It fixed it!
Dan
Dan17mo ago
Fixed in 0.28.5.
Noahh
NoahhOP17mo ago
Thanks for the quick fix y'all! I had complete faith that Drizzle wasn't stealing my proprietary, horribly written, overcomplicated, truly first-of-their-kind SQL queries!
Andrii Sherman
Andrii Sherman17mo ago
😅😅
Noahh
NoahhOP17mo ago
I will ask though, it sounds like it's planned to be added back in the future. Will that be a way for us to trace how Drizzle is performing our own queries? Are the spans something we can use in our own queries to help document our performance? Never used opentelemetry but it seems like that's what it could be useful for Nevermind, I completely missed the line where Dan explained exactly that
Andrii Sherman
Andrii Sherman17mo ago
Yes, you are right It will help to check all of that For your app And the where are bottlenecks or slow performance We will add diagrams on how that works with all the examples, but in the future, after we will add a proper support for it
Noahh
NoahhOP17mo ago
Great to know!
Théo
Théo16mo ago
Hey I'm quite interested in this, where can we track progress/contribute?
Noahh
NoahhOP16mo ago
Do you mean a fix for this or the implementation of @opentelemetry/api working?
Dan
Dan16mo ago
The OTEL implementation is already there, it's just disabled for the time being because it was causing import issues. I plan to rework it to remove conditional imports from the code and move them to the user land. But only the small part would need to be reworked, specifically the initialization
Makisuo
Makisuo15mo ago
any updates on this, would love to contribute for it aswell if wanted?
Want results from more Discord servers?
Add your server