Skip to content

Commit 614973b

Browse files
authored
fix(prisma): only add tracing helper when helper is defined (#7765)
* only add tracing helper when helper is defined * added test
1 parent d028be3 commit 614973b

File tree

2 files changed

+26
-2
lines changed

2 files changed

+26
-2
lines changed

packages/datadog-instrumentations/src/prisma.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -172,8 +172,10 @@ const prismaHook = (runtime, versions, name, isIitm) => {
172172
prismaHelperInit.publish(prismaHelperCtx)
173173

174174
const helper = prismaHelperCtx.helper
175-
this._tracingHelper = helper
176-
this._engine.tracingHelper = helper
175+
if (helper) {
176+
this._tracingHelper = helper
177+
this._engine.tracingHelper = helper
178+
}
177179
}
178180
}
179181
}

packages/datadog-plugin-prisma/test/index.spec.js

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -508,6 +508,28 @@ describe('Plugin', () => {
508508
})
509509
})
510510

511+
describe('without tracer initialization', () => {
512+
before(async function () {
513+
this.timeout(10000)
514+
clearPrismaEnv()
515+
setPrismaEnv(config)
516+
517+
const cwd = await copySchemaToVersionDir(config.schema, range)
518+
519+
execPrismaGenerate(config, cwd)
520+
521+
require('../../dd-trace')
522+
523+
prisma = loadPrismaModule(config, range)
524+
prismaClient = createPrismaClient(prisma, config)
525+
})
526+
527+
it('should not break prisma load when dd-trace is loaded but not initialized', async function () {
528+
const result = await prismaClient.$queryRaw`SELECT 1`
529+
assert.ok(result)
530+
})
531+
})
532+
511533
describe('with configuration', () => {
512534
describe('with custom service name', () => {
513535
before(async function () {

0 commit comments

Comments
 (0)