kysely-org / kysely

A type-safe typescript SQL query builder
https://kysely.dev
MIT License
10.71k stars 271 forks source link

Kysely does not work in combination with OpenTelemetry (using mysql dialect) #503

Closed jballentine-sharpen closed 1 year ago

jballentine-sharpen commented 1 year ago

It seems something with OpenTelemetry's mysql2 instrumentation conflicts with Kysely. When I attempt to execute a query, I get an error of TypeError: format is not a function as well as some warnings of Warning: Accessing non-existent property 'format' of module exports inside circular dependency, with the error coming from @opentelemetry/instrumentation-mysql2/src/utils.ts:105:21. and caused by kysely/dist/esm/dialect/mysql/mysql-driver.js:117:33

This issue does not happen with regular connections using the mysql2 package directly, or when using connections created via Knex. It seems something Kysely-specific is causing this conflict.

Any suggestions are welcome, but I'm assuming this is just a bug that nobody has encountered before.

igalklebanov commented 1 year ago

Hey 👋

Kysely will never provide opentelemetry support in its core. This is something that has to be published by opentelemetry, same as they did with Knex.

I'd be happy to collaborate with them.

rhyek commented 3 months ago

FYI, I believe it's not required for opentelemetry to publish the instrumentation. Prisma developed their own here. However, it's not super compliant the the otel db spec. This is what brought me here, actually. Was wondering what otel support looked like.

igalklebanov commented 3 months ago

DISCLAIMER: I am a Prisma employee at the time of writing this. These are just my opinions.

Prisma is:

  1. a company. Companies have the resources to put individuals on a task full-time. I imagine implementing it in-house and under the organization was faster to ship than waiting on the OTEL maintainers, and in the long run, gives 100% control.
  2. an ORM with a TypeScript API and a Rust engine under the hood that makes the requests. This, I imagine, required a Prisma-specific OTEL implementation that "knows" the engine.

image

With kysely you can probably just instrument the underlying drivers (e.g. pg, mysql2, etc.) with existing OTEL implementations and call it a day. Isn't it enough or am I missing something?

rhyek commented 3 months ago

With kysely you can probably just instrument the underlying drivers (e.g. pg, mysql2, etc.) with existing OTEL implementations and call it a day. Isn't it enough or am I missing something?

This might be the case. Unsure about the kysely internals. Good to know!