P
Prisma6mo ago
Blank

Optimize recording does not record any query

I start the recording, I interact with the app, all queries function correctly and are logged to console, but nothing shows up in the recording, I have already tried: - removing the settings and the $on callback - reassigning the client with the result of $extend prisma.ts
import { serverConfig } from '#app/server/config.ts';
import { logDebug } from '#app/server/logger.ts';
import { isProduction } from '#app/server/utils.ts';
import { Prisma, PrismaClient } from '@prisma/client';
import { withAccelerate } from '@prisma/extension-accelerate';
import { withOptimize } from '@prisma/extension-optimize';

let client: PrismaClient;
if (isProduction())
{
client = new PrismaClient();
}
else
{
const globalStore = global as { prisma?: PrismaClient };
if (!globalStore.prisma)
{
const settings =
{
log:
[
{
emit: 'event',
level: 'query',
},
],
} as Prisma.PrismaClientOptions;

globalStore.prisma = new PrismaClient(settings);
globalStore.prisma.$on('query' as never, (e : Prisma.QueryEvent) =>
{
logDebug('[Prisma] Executed Query:', e.timestamp);
logDebug('- Duration:', `${e.duration}ms`);
logDebug('- Params:', e.params);
logDebug('- Query:', e.query);
});
}

client = globalStore.prisma;
}

//

if (serverConfig.PRISMA_OPTIMIZE_API_KEY)
{
logDebug('[Prisma] Added extension: optimize');
client.$extends(withOptimize({ apiKey: serverConfig.PRISMA_OPTIMIZE_API_KEY }));
}

logDebug('[Prisma] Added extension: accelerate');
client.$extends(withAccelerate());

//

client.$connect();

export const prisma = client;
import { serverConfig } from '#app/server/config.ts';
import { logDebug } from '#app/server/logger.ts';
import { isProduction } from '#app/server/utils.ts';
import { Prisma, PrismaClient } from '@prisma/client';
import { withAccelerate } from '@prisma/extension-accelerate';
import { withOptimize } from '@prisma/extension-optimize';

let client: PrismaClient;
if (isProduction())
{
client = new PrismaClient();
}
else
{
const globalStore = global as { prisma?: PrismaClient };
if (!globalStore.prisma)
{
const settings =
{
log:
[
{
emit: 'event',
level: 'query',
},
],
} as Prisma.PrismaClientOptions;

globalStore.prisma = new PrismaClient(settings);
globalStore.prisma.$on('query' as never, (e : Prisma.QueryEvent) =>
{
logDebug('[Prisma] Executed Query:', e.timestamp);
logDebug('- Duration:', `${e.duration}ms`);
logDebug('- Params:', e.params);
logDebug('- Query:', e.query);
});
}

client = globalStore.prisma;
}

//

if (serverConfig.PRISMA_OPTIMIZE_API_KEY)
{
logDebug('[Prisma] Added extension: optimize');
client.$extends(withOptimize({ apiKey: serverConfig.PRISMA_OPTIMIZE_API_KEY }));
}

logDebug('[Prisma] Added extension: accelerate');
client.$extends(withAccelerate());

//

client.$connect();

export const prisma = client;
schema.prisma
generator client {
provider = "prisma-client-js"
previewFeatures = [ "multiSchema", "tracing"]
}

datasource db {
provider = "postgresql"
url = env("DB_URL")
directUrl = env("DB_DIRECT_URL")
shadowDatabaseUrl = env("DB_SHADOW_URL")
schemas = ["bff"]
}

...
generator client {
provider = "prisma-client-js"
previewFeatures = [ "multiSchema", "tracing"]
}

datasource db {
provider = "postgresql"
url = env("DB_URL")
directUrl = env("DB_DIRECT_URL")
shadowDatabaseUrl = env("DB_SHADOW_URL")
schemas = ["bff"]
}

...
6 Replies
Blank
BlankOP6mo ago
I have also tried only calling $extend if the client was not in the globalStore, to prevent adding duplicate extensions.
Nurul
Nurul5mo ago
Hello @Blank 👋 Can you please let us know if you are using NestJS? We have had reports were this issue of queries not showing up occurs when using NestJS.
Blank
BlankOP5mo ago
HI, I'm using Tanstack Start which uses vinxi (vite + nitro)
Nurul
Nurul5mo ago
Thank you for getting back. Is your repository open source?
Blank
BlankOP5mo ago
it's private, but I can share other details if needed
Nurul
Nurul5mo ago
A minimal reproduction example would be very helpful 🙏

Did you find this page helpful?