Skip to content

Commit d87b92c

Browse files
committed
Use a type-guard for Prisma clients.
1 parent 679265c commit d87b92c

File tree

1 file changed

+13
-3
lines changed
  • packages/tracing/src/integrations/node

1 file changed

+13
-3
lines changed

packages/tracing/src/integrations/node/prisma.ts

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,10 @@ interface PrismaClient {
3838
$use: (cb: PrismaMiddleware) => void;
3939
}
4040

41+
function isValidPrismaClient(possibleClient: unknown): possibleClient is PrismaClient {
42+
return possibleClient && !!(possibleClient as PrismaClient)['$use'];
43+
}
44+
4145
/** Tracing integration for @prisma/client package */
4246
export class Prisma implements Integration {
4347
/**
@@ -58,8 +62,14 @@ export class Prisma implements Integration {
5862
/**
5963
* @inheritDoc
6064
*/
61-
public constructor(options: { client?: PrismaClient } = {}) {
62-
this._client = options.client;
65+
public constructor(options: { client?: unknown } = {}) {
66+
if (isValidPrismaClient(options.client)) {
67+
this._client = options.client;
68+
} else {
69+
logger.warn(
70+
`Unsupported Prisma client provided to PrismaIntegration. Provided client: ${JSON.stringify(options.client)}`,
71+
);
72+
}
6373
}
6474

6575
/**
@@ -71,7 +81,7 @@ export class Prisma implements Integration {
7181
return;
7282
}
7383

74-
this._client.$use((params: PrismaMiddlewareParams, next: (params: PrismaMiddlewareParams) => Promise<unknown>) => {
84+
this._client.$use((params, next: (params: PrismaMiddlewareParams) => Promise<unknown>) => {
7585
const scope = getCurrentHub().getScope();
7686
const parentSpan = scope?.getSpan();
7787

0 commit comments

Comments
 (0)