[BUG]: Cannot use `dd-trace` with Prisma 6.13
Tracer Version(s)
5.62.0
Node.js Version(s)
20.19.4
Bug Report
Following the exact steps detailed in the official documentation at https://www.prisma.io/docs/guides/data-dog, I cannot get my Prisma app to work with dd-trace/Datadog v5.62.0.
ERROR [unhandledRejection] Cannot read properties of undefined (reading 'sample') 6:58:37 PM
at DatadogSpan._addTags (node_modules/dd-trace/packages/dd-trace/src/opentracing/span.js:385:27)
at DatadogSpan.addTags (node_modules/dd-trace/packages/dd-trace/src/opentracing/span.js:189:10)
at Span.setAttributes (node_modules/dd-trace/packages/dd-trace/src/opentelemetry/span.js:210:18)
at new Span (node_modules/dd-trace/packages/dd-trace/src/opentelemetry/span.js:155:12)
at Tracer.startSpan (node_modules/dd-trace/packages/dd-trace/src/opentelemetry/tracer.js:140:12)
at Tracer.startActiveSpan (node_modules/dd-trace/packages/dd-trace/src/opentelemetry/tracer.js:168:23)
at ActiveTracingHelper.runInChildSpan (node_modules/@prisma/instrumentation/dist/index.mjs:75:19)
at Io.runInChildSpan (node_modules/@prisma/client/runtime/library.js:121:1913)
at Qr.getCurrentBinaryTarget (node_modules/@prisma/client/runtime/library.js:111:12070)
at Qr.instantiateLibrary (node_modules/@prisma/client/runtime/library.js:111:11844)
NOTE: This is x-posted from https://github.com/prisma/prisma/issues/27871.
Reproduction Code
- Set up any app with Prisma 16.3.0 and
dd-trace5.62.0. - Include OTEL override in
package.json{ "overrides": { "@opentelemetry/api": "1.8.0" } } - Follow instructions at https://www.prisma.io/docs/guides/data-dog
- Run app.
- See error –
ERROR [unhandledRejection] Cannot read properties of undefined (reading 'sample') at DatadogSpan._addTags (node_modules/dd-trace/packages/dd-trace/src/opentracing/span.js:385:27) at DatadogSpan.addTags (node_modules/dd-trace/packages/dd-trace/src/opentracing/span.js:189:10) at Span.setAttributes (node_modules/dd-trace/packages/dd-trace/src/opentelemetry/span.js:210:18) at new Span (node_modules/dd-trace/packages/dd-trace/src/opentelemetry/span.js:155:12) at Tracer.startSpan (node_modules/dd-trace/packages/dd-trace/src/opentelemetry/tracer.js:140:12) at Tracer.startActiveSpan (node_modules/dd-trace/packages/dd-trace/src/opentelemetry/tracer.js:168:23) at ActiveTracingHelper.runInChildSpan (node_modules/@prisma/instrumentation/dist/index.mjs:75:19) at Io.runInChildSpan (node_modules/@prisma/client/runtime/library.js:121:1913) at Qr.getCurrentBinaryTarget (node_modules/@prisma/client/runtime/library.js:111:12070) at Qr.instantiateLibrary (node_modules/@prisma/client/runtime/library.js:111:11844)
Error Logs
ERROR [unhandledRejection] Cannot read properties of undefined (reading 'sample')
at DatadogSpan._addTags (node_modules/dd-trace/packages/dd-trace/src/opentracing/span.js:385:27)
at DatadogSpan.addTags (node_modules/dd-trace/packages/dd-trace/src/opentracing/span.js:189:10)
at Span.setAttributes (node_modules/dd-trace/packages/dd-trace/src/opentelemetry/span.js:210:18)
at new Span (node_modules/dd-trace/packages/dd-trace/src/opentelemetry/span.js:155:12)
at Tracer.startSpan (node_modules/dd-trace/packages/dd-trace/src/opentelemetry/tracer.js:140:12)
at Tracer.startActiveSpan (node_modules/dd-trace/packages/dd-trace/src/opentelemetry/tracer.js:168:23)
at ActiveTracingHelper.runInChildSpan (node_modules/@prisma/instrumentation/dist/index.mjs:75:19)
at Io.runInChildSpan (node_modules/@prisma/client/runtime/library.js:121:1913)
at Qr.getCurrentBinaryTarget (node_modules/@prisma/client/runtime/library.js:111:12070)
at Qr.instantiateLibrary (node_modules/@prisma/client/runtime/library.js:111:11844)
Tracer Config
{
logger, // logger is just a standard Pino instance.
logInjection: true,
}
Operating System
Darwin Mac 24.6.0 Darwin Kernel Version 24.6.0: Mon Jul 14 11:28:30 PDT 2025; root:xnu-11417.140.69~1/RELEASE_ARM64_T6030 arm64
Bundling
Vite
We recently added support for prisma directly to the client and I believe the prisma documentation does not yet reflect that.
@BridgeAR would you happen to have links to the docs or a PR perhaps so I can learn how to make this work?
Found it — https://github.com/DataDog/dd-trace-js/pull/5605
Is it as simple as just enabling the plugin? Does it work with both regular Prisma and Prisma with the new ESM generated code?
Can confirm this doesn't work with Prisma 6.14, nor with [email protected]. Additionally, I tried setting this up with Prisma ESM + QueryCompiler as well (their pure TS port of their Rust engine), and it doesn't work either.
Are we able to use with earlier versions ? and any earlier versions working fine with prisma.
Anyone have any luck here in finding workarounds?
It worked for me @ianwoodfill @paambaati : With below set up :
⚙️ Implementation Steps
- Upgrade Dependencies Update your package.json to include the following versions:
{ "dependencies": { "@prisma/client": "^6.6.0", "dd-trace": "5.64.0" } } Then run: npm install
- Update Prisma Client Generation (IMPORTANT) Datadog currently supports only the default Prisma client generation path.
✅ Works (Default Path)
generator client {
provider = "prisma-client-js"
}
❌ Does NOT Work (Custom Path)
generator client {
provider = "prisma-client-js"
output = "../../../../../node_modules/@prisma/workflow/client"
}
⚠️ Note: Services connecting to multiple databases (which require custom generation paths) will not have Prisma traces captured until Datadog provides a fix or alternative hook.
For now, services using a single database should keep the default Prisma client path to enable tracing.
- Initialize dd-trace Early Make sure the Datadog tracer is initialized before importing Prisma or any other application code.
Example (main.ts or index.ts):
import 'tracing';
import { PrismaClient } from '@prisma/client';
import { NestFactory } from '@nestjs/core';
import { AppModule } from './app.module';
async function bootstrap() {
const app = await NestFactory.create(AppModule);
await app.listen(3000);
}
bootstrap();
import tracer from 'dd-trace';
tracer.init({
runtimeMetrics: true,
profiling: true,
});
export default tracer;
💡 If your service has a custom tracer configuration, ensure Prisma instrumentation is not disabled in the tracer initialization.
Sample screen shot :
Thanks @ravivarma4003 for your example of what works and what and what does not work.
@BridgeAR is supporting this example of what @ravivarma4003 called out as not working something we can expect as enhancement to dd-trace? All of our prisma clients use a custom output path so getting this working would be a need for us:
Does NOT Work (Custom Path)
generator client { provider = "prisma-client-js" output = "../../../../../node_modules/@prisma/workflow/client" }
Getting it to work with different output paths would also be important for us. Perhaps a pointer in the direction of how to fix this and maybe I could take a look