dd-trace-js icon indicating copy to clipboard operation
dd-trace-js copied to clipboard

[BUG]: Cannot use `dd-trace` with Prisma 6.13

Open paambaati opened this issue 4 months ago • 8 comments

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

  1. Set up any app with Prisma 16.3.0 and dd-trace 5.62.0.
  2. Include OTEL override in package.json
    {
        "overrides": {
            "@opentelemetry/api": "1.8.0"
         }
    }
    
  3. Follow instructions at https://www.prisma.io/docs/guides/data-dog
  4. Run app.
  5. 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

paambaati avatar Aug 14 '25 13:08 paambaati

We recently added support for prisma directly to the client and I believe the prisma documentation does not yet reflect that.

BridgeAR avatar Aug 14 '25 16:08 BridgeAR

@BridgeAR would you happen to have links to the docs or a PR perhaps so I can learn how to make this work?

paambaati avatar Aug 14 '25 16:08 paambaati

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?

paambaati avatar Aug 14 '25 16:08 paambaati

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.

paambaati avatar Aug 25 '25 09:08 paambaati

Are we able to use with earlier versions ? and any earlier versions working fine with prisma.

ravivarma4003 avatar Aug 25 '25 12:08 ravivarma4003

Anyone have any luck here in finding workarounds?

ianwoodfill avatar Oct 31 '25 14:10 ianwoodfill

It worked for me @ianwoodfill @paambaati : With below set up :

⚙️ Implementation Steps

  1. 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

  1. 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.

  1. 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 :

Image

ravivarma4003 avatar Oct 31 '25 16:10 ravivarma4003

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" }

danny-fairly avatar Nov 14 '25 16:11 danny-fairly

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

michael-rzero avatar Dec 16 '25 16:12 michael-rzero