-
-
Notifications
You must be signed in to change notification settings - Fork 721
Enable prisma metrics and add them to the /metrics endpoint #2111
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
@@ -1,8 +1,22 @@ | ||||||||||||||||||||||||||||||||||
import { LoaderFunctionArgs } from "@remix-run/server-runtime"; | ||||||||||||||||||||||||||||||||||
import { prisma } from "~/db.server"; | ||||||||||||||||||||||||||||||||||
import { metricsRegister } from "~/metrics.server"; | ||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||
export async function loader({ request }: LoaderFunctionArgs) { | ||||||||||||||||||||||||||||||||||
return new Response(await metricsRegister.metrics(), { | ||||||||||||||||||||||||||||||||||
// If the TRIGGER_METRICS_AUTH_PASSWORD is set, we need to check if the request has the correct password in auth header | ||||||||||||||||||||||||||||||||||
const authPassword = process.env.TRIGGER_METRICS_AUTH_PASSWORD; | ||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||
if (authPassword) { | ||||||||||||||||||||||||||||||||||
const auth = request.headers.get("Authorization"); | ||||||||||||||||||||||||||||||||||
if (auth !== `Bearer ${authPassword}`) { | ||||||||||||||||||||||||||||||||||
return new Response("Unauthorized", { status: 401 }); | ||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||
const prismaMetrics = await prisma.$metrics.prometheus(); | ||||||||||||||||||||||||||||||||||
const coreMetrics = await metricsRegister.metrics(); | ||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||
return new Response(coreMetrics + prismaMetrics, { | ||||||||||||||||||||||||||||||||||
Comment on lines
+17
to
+19
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 💡 Verification agent 🧩 Analysis chainVerify the metrics concatenation approach. Simple string concatenation of Prometheus metrics may not be the correct approach. Prometheus metrics typically require proper formatting, and there could be conflicts between metric names or improper line endings. Consider using a proper Prometheus metrics library for combining metrics: - return new Response(coreMetrics + prismaMetrics, {
+ // Ensure proper line separation between metric sets
+ const combinedMetrics = [coreMetrics.trim(), prismaMetrics.trim()]
+ .filter(Boolean)
+ .join('\n');
+
+ return new Response(combinedMetrics, { 🏁 Script executed: #!/bin/bash
# Description: Search for existing Prometheus metrics handling patterns in the codebase
# Expected: Find examples of how metrics are properly combined or formatted
# Search for other prometheus metrics usage
rg -A 5 -B 5 "prometheus|metrics" --type typescript --type javascript
# Look for existing metrics formatting or combination logic
ast-grep --pattern 'metricsRegister.$_($$$)' Length of output: 244 🏁 Script executed: #!/bin/bash
# Locate prismaMetrics usage and display the metrics route implementation
grep -n "prismaMetrics" apps/webapp/app/routes/metrics.ts || true
sed -n '1,200p' apps/webapp/app/routes/metrics.ts Length of output: 693 Ensure proper Prometheus metrics formatting when combining outputs Directly concatenating two metrics strings can lead to missing newline separators or duplicated HELP/TYPE directives, which breaks the Prometheus exposition format. It’s safer to trim each output and join them with a newline. • File: apps/webapp/app/routes/metrics.ts Suggested diff: const prismaMetrics = await prisma.$metrics.prometheus();
const coreMetrics = await metricsRegister.metrics();
-
- return new Response(coreMetrics + prismaMetrics, {
+ // Combine metrics outputs with proper newline separation
+ const combinedMetrics = [coreMetrics.trim(), prismaMetrics.trim()]
+ .filter(Boolean)
+ .join('\n');
+
+ return new Response(combinedMetrics, {
headers: {
"Content-Type": metricsRegister.contentType,
},
}); 📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents
|
||||||||||||||||||||||||||||||||||
headers: { | ||||||||||||||||||||||||||||||||||
"Content-Type": metricsRegister.contentType, | ||||||||||||||||||||||||||||||||||
}, | ||||||||||||||||||||||||||||||||||
|
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -7,7 +7,7 @@ datasource db { | |||||
generator client { | ||||||
provider = "prisma-client-js" | ||||||
binaryTargets = ["native", "debian-openssl-1.1.x"] | ||||||
previewFeatures = ["tracing"] | ||||||
previewFeatures = ["tracing", "metrics"] | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 💡 Verification agent 🧩 Analysis chainVerify the stability of the Prisma metrics preview feature. Adding the "metrics" preview feature enables Prisma client metrics collection. Since preview features can have breaking changes and may not be production-ready, ensure this feature is stable enough for your use case. 🌐 Web query:
💡 Result: As of May 2025, Prisma has announced plans to discontinue the "metrics" preview feature between June and August 2025 due to low usage and compatibility issues with the Query Compiler. (github.com) Consequently, the "metrics" feature is not considered production-ready. For monitoring and observability, Prisma recommends using the "tracing" feature, which provides detailed insights into database interactions and is fully supported. (prismagraphql.com) Citations:
Remove the “metrics” preview feature – it’s unstable and slated for removal Prisma has announced that the “metrics” preview feature will be discontinued between June and August 2025 and is not production-ready. To avoid future breakages, remove it from your schema and rely on the fully supported “tracing” feature for observability. Please update:
- previewFeatures = ["tracing", "metrics"]
+ previewFeatures = ["tracing"] 📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents
|
||||||
} | ||||||
|
||||||
model User { | ||||||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🛠️ Refactor suggestion
Add error handling for the Prisma metrics call.
The call to
prisma.$metrics.prometheus()
could potentially fail, which would cause the entire metrics endpoint to fail. Consider adding error handling to gracefully degrade when Prisma metrics are unavailable.🤖 Prompt for AI Agents