P
Prisma•6mo ago
samuelcole

Prisma Optimize does not show queries

I've installed the extension, it shows the prompt in my terminal, but the web UI does not show queries.
No description
18 Replies
jonfanz
jonfanz•6mo ago
We changed a few things about Optimize (today actually!) Which version of the extension are you using?
samuelcole
samuelcoleOP•6mo ago
"@prisma/extension-optimize": "^0.9.0",
"@prisma/extension-optimize": "^0.9.0",
i'm very cutting edge 😉 @Jon Harrell just for background, i've never gotten it to work, but this week i'm tasked with solving some performance issues that i think optimize can help with
jonfanz
jonfanz•6mo ago
I’ve unfortunately got an appointment to run to, but it should work if you start the recording and then start the app. I’m not sure why it wouldn’t. I’ll double check with our engineers
samuelcole
samuelcoleOP•6mo ago
also i use prisma accelerate i've had 'tracing' on forever, because i love open telemetry... not sure what other clues would help
const generatePrismaClient = () => {
const prisma = new PrismaClient().$extends(withAccelerate());

if (process.env.NODE_ENV === "development") {
return prisma.$extends(withOptimize());
}

return prisma;
};

export const prisma = global._prismaSingleton ?? generatePrismaClient();

if (process.env.NODE_ENV !== "production") {
global._prismaSingleton = prisma;
}
const generatePrismaClient = () => {
const prisma = new PrismaClient().$extends(withAccelerate());

if (process.env.NODE_ENV === "development") {
return prisma.$extends(withOptimize());
}

return prisma;
};

export const prisma = global._prismaSingleton ?? generatePrismaClient();

if (process.env.NODE_ENV !== "production") {
global._prismaSingleton = prisma;
}
jonfanz
jonfanz•6mo ago
Might have something to do with accelerate. Would it be possible to update your code and connection strings such that you connect directly when in dev?
samuelcole
samuelcoleOP•6mo ago
we use a direct DATABASE_URL in development, but we still need withAccelerate so that the client supports cacheStrategy
jonfanz
jonfanz•6mo ago
Oh duh you’re right. Okay, let me test this out
samuelcole
samuelcoleOP•6mo ago
i don't think that it's it... i just removed withAccelerate and my cacheStrategy entries, and it still isn't coming through my prisma user id is clm0yz2qp003kpq0h0b80tng0 my url (which i assume is my optimize project account id?) is https://optimize.prisma.io/clm0yz2pe003ipq0h6sh2x91o i thought it was weird they were different, so i tried logging out and in, and that didn't help
jonfanz
jonfanz•6mo ago
heard back from engineering: try extending with Optimize first.
samuelcole
samuelcoleOP•6mo ago
K k! I’m out for the day, I’ll try that tomorrow, thanks for following up!
jonfanz
jonfanz•6mo ago
No problem at all, thanks for your patience 🙂
samuelcole
samuelcoleOP•6mo ago
@Jon Harrell just getting back to this, no dice:
const generatePrismaClient = () => {
if (process.env.NODE_ENV === "development") {
return new PrismaClient()
.$extends(withOptimize())
.$extends(withAccelerate());
}

return new PrismaClient().$extends(withAccelerate());
};

export const prisma = global._prismaSingleton ?? generatePrismaClient();

if (process.env.NODE_ENV !== "production") {
global._prismaSingleton = prisma;
}
const generatePrismaClient = () => {
if (process.env.NODE_ENV === "development") {
return new PrismaClient()
.$extends(withOptimize())
.$extends(withAccelerate());
}

return new PrismaClient().$extends(withAccelerate());
};

export const prisma = global._prismaSingleton ?? generatePrismaClient();

if (process.env.NODE_ENV !== "production") {
global._prismaSingleton = prisma;
}
jonfanz
jonfanz•6mo ago
Bizarre. Let me review the info I was given again
samuelcole
samuelcoleOP•6mo ago
i'm curious how it uploads the traces to you? like i said, we also have our own opentelemetry tooling, so i wonder if that's interfering this is instrumentation.node.ts
import { PrismaInstrumentation } from "@prisma/instrumentation";
import { FetchInstrumentation, registerOTel } from "@vercel/otel";
import { getNodeAutoInstrumentations } from "@opentelemetry/auto-instrumentations-node";
import {
ConsoleLogRecordExporter,
LoggerProvider,
SimpleLogRecordProcessor,
} from "@opentelemetry/sdk-logs";
import { logs } from "@opentelemetry/api-logs";

const serviceName = "platform";

registerOTel({
serviceName,
instrumentations: [
new PrismaInstrumentation(),
new FetchInstrumentation(),
...getNodeAutoInstrumentations({
"@opentelemetry/instrumentation-grpc": { enabled: false },
}),
],
});

const loggerProvider = new LoggerProvider();
loggerProvider.addLogRecordProcessor(
new SimpleLogRecordProcessor(new ConsoleLogRecordExporter()),
);
logs.setGlobalLoggerProvider(loggerProvider);
import { PrismaInstrumentation } from "@prisma/instrumentation";
import { FetchInstrumentation, registerOTel } from "@vercel/otel";
import { getNodeAutoInstrumentations } from "@opentelemetry/auto-instrumentations-node";
import {
ConsoleLogRecordExporter,
LoggerProvider,
SimpleLogRecordProcessor,
} from "@opentelemetry/sdk-logs";
import { logs } from "@opentelemetry/api-logs";

const serviceName = "platform";

registerOTel({
serviceName,
instrumentations: [
new PrismaInstrumentation(),
new FetchInstrumentation(),
...getNodeAutoInstrumentations({
"@opentelemetry/instrumentation-grpc": { enabled: false },
}),
],
});

const loggerProvider = new LoggerProvider();
loggerProvider.addLogRecordProcessor(
new SimpleLogRecordProcessor(new ConsoleLogRecordExporter()),
);
logs.setGlobalLoggerProvider(loggerProvider);
samuelcole
samuelcoleOP•6mo ago
ok, when i disable my own instrumentation, i get this error: https://github.com/prisma/optimize-feedback/issues/11
GitHub
Error: "prisma:client span is expected to be entered in the client ...
Describe the bug When using Prisma Optimize with Prisma ORM and following the setup instructions, the following error occurs: Error: prisma:client:operation span is expected to be entered in the cl...
jonfanz
jonfanz•6mo ago
Alrighty, this is a bit more complex than my knowledge 😅 What I'm doing is writing this up and getting all the info over to our engineers. Would you mind if I shared the above code snippets? Also, in case it is a bug, it might be worth opening a new issue in the optimize-feedback repo.
samuelcole
samuelcoleOP•6mo ago
yup! all that code is perfectly shareable i'm excited to help, i think this product is much needed, and will be very helpful
jonfanz
jonfanz•6mo ago
I (and the whole team) is super appreciative. And I'll give them that feedback! Thank you so much for your time thus far
Want results from more Discord servers?
Add your server