Blank
Blank
PPrisma
Created by Blank on 11/29/2024 in #help-and-questions
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"]
}

...
2 replies