Open kibertoad opened 1 year ago
It is worth mentioning that currently it is possible to instrument the driver library itself using instrumentation libraries provided by otel:
pg - https://www.npmjs.com/package/@opentelemetry/instrumentation-pg mysql - https://www.npmjs.com/package/@opentelemetry/instrumentation-mysql
It is worth mentioning that currently it is possible to instrument the driver library itself using instrumentation libraries provided by otel:
pg - https://www.npmjs.com/package/@opentelemetry/instrumentation-pg mysql - https://www.npmjs.com/package/@opentelemetry/instrumentation-mysql
@bohdan-sviripa Did you manage to make it work with Drizzle?
@gustavolzangelo I opened #1054 and tried it on my project.
I was able to work on drizzle with pg, and get the instrumentation working properly with instrumentation-pg
There's already OpenTelemetry traces set up throughout the pg-core
module. I've already setup Otel tracing in the rest of my app and it would be great to be able to turn it on for Drizzle as well.
Does any similar library exists for OTEL Tracing for Planetscale? any suggestions on how one could include automatic tracing for queries?
Also curious if there's any documentation on how you best go about setting up OpenTelemetry tracing when using Drizzle. I've done this with Prisma in the past and benefited from documentation such as the links below:
Can you point us in the right direction here @AndriiSherman, @Angelelz? Thanks for a great ORM!
Drizzle doesn't have official support for this yet. At some point the team stated implementing something like that but it is not done yet.
for postgres you can use this packages to track traces
instrumentation libraries:
probably will be like this:
instrumentations: [
new PgInstrumentation({
enhancedDatabaseReporting: true,
enabled: true,
addSqlCommenterCommentToQueries: true,
}),
],
We use MySQL (Planetscale) and for us patching the db
instance (or js Proxy) at the entry-point of package with manual tracing worked out. We only use it for dev/staging, no performance or other issues found so far.
Eg.
Connection.prototype.execute = async function (query, values, options) {
return trace.getTracer('database').startActiveSpan(query.toString(), async (span) => {
span.setAttribute('db.statement', query);
const _res = await originalMethod.call(this, query, values as any, options as any);
span.end();
return _res;
});
};
Suggestion:
OR even simpler:
Add this to src/drizzle-orm/tracing.ts
let otel: typeof import('@opentelemetry/api') | undefined;
export function setGlobalOtelApi(api: typeof import('@opentelemetry/api') | undefined): void {
otel = api;
}
And this to index.ts
export { setGlobalOtelApi } from './tracing.ts';
OpenTelemetry itself uses global configuration, for example when starting Node SDK, so i believe usage of globals if appropriate here
@AlexXanderGrib Could you do a pull request?
I tried vite rewrites and found out that drizzle tries to serialize query params to JSON for span attribues. But query params can be BigInt so it blows up
APM solutions, such as DataDog and New Relic can benefit from execution traces, such as OpenTelemetry, in order to provide useful runtime information about how queries are performing.
See how Prisma did it: https://github.com/prisma/prisma/tree/main/packages/instrumentation