Getting error this.getGlobalTracingHelper(...).dispatchEngineSpans is not a function

Hello! I just installed the prisma extension optimize, I'm using: - Node: 20.x - TypeScript: ^5.5.3 - Express: ^4.19.2 - Prisma: ^6.1.0 - @prisma/client: ^6.1.0 - @prisma/extension-optimize: ^1.1.1 I updated the prisma file to allow this feature like this:
generator client {
provider = "prisma-client-js"
binaryTargets = ["native", "linux-musl"]
previewFeatures = ["relationJoins", "tracing"]
}
generator client {
provider = "prisma-client-js"
binaryTargets = ["native", "linux-musl"]
previewFeatures = ["relationJoins", "tracing"]
}
then I updated the prisma client to look like this:
import { Prisma, PrismaClient } from '@prisma/client';
import prismaCache from '../utils/prisma-cache';
import { withOptimize } from '@prisma/extension-optimize';
import envConfig from './env.config';
const cacheManager = Prisma.defineExtension((client) => {
return client.$extends({
query: {
$allModels: {
async $allOperations({ model, operation, args, query }) {
const result = await query(args);
prismaCache.cachePrismaUserAllowedCountries(model, operation);
return result;
},
},
},
});
});
const prisma = new PrismaClient()
.$extends(cacheManager)
.$extends(withOptimize({ apiKey: envConfig.OPTIMIZE_API_KEY }));
export default prisma;
import { Prisma, PrismaClient } from '@prisma/client';
import prismaCache from '../utils/prisma-cache';
import { withOptimize } from '@prisma/extension-optimize';
import envConfig from './env.config';
const cacheManager = Prisma.defineExtension((client) => {
return client.$extends({
query: {
$allModels: {
async $allOperations({ model, operation, args, query }) {
const result = await query(args);
prismaCache.cachePrismaUserAllowedCountries(model, operation);
return result;
},
},
},
});
});
const prisma = new PrismaClient()
.$extends(cacheManager)
.$extends(withOptimize({ apiKey: envConfig.OPTIMIZE_API_KEY }));
export default prisma;
however once I run the app I get this error:
ERROR { 9:15:02 a.m.
"name": "TypeError",
"message": "this.getGlobalTracingHelper(...).dispatchEngineSpans is not a function",
"stack": "TypeError: this.getGlobalTracingHelper(...).dispatchEngineSpans is not a function\n at ho.dispatchEngineSpans (/home/nicotordev/Escritorio/spiritory/backend/node_modules/@prisma/client/runtime/library.js:121:1715)\n at Object.connect (/home/nicotordev/Escritorio/spiritory/backend/node_modules/@prisma/client/runtime/library.js:111:11492)\n at async t (/home/nicotordev/Escritorio/spiritory/backend/node_modules/@prisma/client/runtime/library.js:112:2309)"
}
ERROR { 9:15:02 a.m.
"name": "TypeError",
"message": "this.getGlobalTracingHelper(...).dispatchEngineSpans is not a function",
"stack": "TypeError: this.getGlobalTracingHelper(...).dispatchEngineSpans is not a function\n at ho.dispatchEngineSpans (/home/nicotordev/Escritorio/spiritory/backend/node_modules/@prisma/client/runtime/library.js:121:1715)\n at Object.connect (/home/nicotordev/Escritorio/spiritory/backend/node_modules/@prisma/client/runtime/library.js:111:11492)\n at async t (/home/nicotordev/Escritorio/spiritory/backend/node_modules/@prisma/client/runtime/library.js:112:2309)"
}
Thanks in advance.
No description
No description
No description
4 Replies
Nurul
Nurul5w ago
Hello @N I C O 👋 Thank you for reporting this error. I was able to reproduce this in version Prisma v6.1.0. Can you try using the version 6.0.0 and check? For me it worked in version 6.0.0 and not in 6.1.0. I have informed our team to look into this 🙏
N I C O
N I C OOP5w ago
@Nurul Thanks for answering, indeed it works in prisma v6.0.0, but I now have a new problem, my model has Ids as BigInt and I think that at the moment of sending the query, optimize can't process this Ids
Unhandled Rejection at: TypeError: Do not know how to serialize a BigInt
at JSON.stringify (<anonymous>)
at /home/nicotordev/Escritorio/spiritory/backend/node_modules/@prisma/extension-optimize/dist/index.js:1:1007
at Object.post (/home/nicotordev/Escritorio/spiritory/backend/node_modules/@prisma/extension-optimize/dist/index.js:1:1275)
at B (/home/nicotordev/Escritorio/spiritory/backend/node_modules/@prisma/extension-optimize/dist/index.js:1:2007)
at b.onFlush (/home/nicotordev/Escritorio/spiritory/backend/node_modules/@prisma/extension-optimize/dist/index.js:1:6501)
at b.forceFlush (/home/nicotordev/Escritorio/spiritory/backend/node_modules/@prisma/extension-optimize/dist/index.js:1:3567)
at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
Unhandled Rejection at: TypeError: Do not know how to serialize a BigInt
at JSON.stringify (<anonymous>)
at /home/nicotordev/Escritorio/spiritory/backend/node_modules/@prisma/extension-optimize/dist/index.js:1:1007
at Object.post (/home/nicotordev/Escritorio/spiritory/backend/node_modules/@prisma/extension-optimize/dist/index.js:1:1275)
at B (/home/nicotordev/Escritorio/spiritory/backend/node_modules/@prisma/extension-optimize/dist/index.js:1:2007)
at b.onFlush (/home/nicotordev/Escritorio/spiritory/backend/node_modules/@prisma/extension-optimize/dist/index.js:1:6501)
at b.forceFlush (/home/nicotordev/Escritorio/spiritory/backend/node_modules/@prisma/extension-optimize/dist/index.js:1:3567)
at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
personally I use this script to send bigints back to the client
export default function convertBigIntToString(obj: any): any {
if (typeof obj === "bigint") {
return obj.toString();
} else if (obj instanceof Date) {
return obj.toISOString();
} else if (obj instanceof Map) {
return {
type: "Map",
value: Array.from(obj.entries()).map(([key, value]) => [
convertBigIntToString(key),
convertBigIntToString(value),
]),
};
} else if (obj instanceof Set) {
return {
type: "Set",
value: Array.from(obj).map(convertBigIntToString),
};
} else if (obj === null || typeof obj !== "object") {
return obj;
} else if (Array.isArray(obj)) {
return obj.map(convertBigIntToString);
} else {
return Object.fromEntries(
Object.entries(obj).map(([key, value]) => [
key,
convertBigIntToString(value),
]),
);
}
}
export default function convertBigIntToString(obj: any): any {
if (typeof obj === "bigint") {
return obj.toString();
} else if (obj instanceof Date) {
return obj.toISOString();
} else if (obj instanceof Map) {
return {
type: "Map",
value: Array.from(obj.entries()).map(([key, value]) => [
convertBigIntToString(key),
convertBigIntToString(value),
]),
};
} else if (obj instanceof Set) {
return {
type: "Set",
value: Array.from(obj).map(convertBigIntToString),
};
} else if (obj === null || typeof obj !== "object") {
return obj;
} else if (Array.isArray(obj)) {
return obj.map(convertBigIntToString);
} else {
return Object.fromEntries(
Object.entries(obj).map(([key, value]) => [
key,
convertBigIntToString(value),
]),
);
}
}
Nurul
Nurul5w ago
We have this recommendation for serializing BigInt: https://www.prisma.io/docs/orm/prisma-client/special-fields-and-types#serializing-bigint It looks like you are doing the same. Let me try to use a BigInt type and try to reproduce this error
Fields & types | Prisma Documentation
Learn how to use about special fields and types with Prisma Client.
Nurul
Nurul4w ago
You are correct! I am able to reproduce the BigInt serialization error. I am reporting this as well 🙏 @N I C O Can you try the latest Optimize extension version 1.1.4? This should fix both the issues you were observing. Thank you for reporting 🙏

Did you find this page helpful?