Replies: 12 comments 31 replies
-
Hey @olamiwhat, I am also interested in this. Were you able to find anything? |
Beta Was this translation helpful? Give feedback.
-
In our cluster we are obliged to use it and normally we have it in express route INTERNAL handler as default. For next i have it fully working with the following setup below. The trick is using express as server, because we need custom other things as well :)
it then exposed the metrics:
|
Beta Was this translation helpful? Give feedback.
-
is there any other way to do this without a custom server? i'm also trying to avoid doing that. |
Beta Was this translation helpful? Give feedback.
-
@olamiwhat |
Beta Was this translation helpful? Give feedback.
-
I am still struggling to get the route names back from Next e.g. |
Beta Was this translation helpful? Give feedback.
-
Hey guys. How to add http custom metrics (requests per seconds, requests duration, 4xx, 5xx) in NextJS without custom server? I guess I need to use middleware API, but I don't know how to catch end of response. I don't see any callback or res.end in NextResponse |
Beta Was this translation helpful? Give feedback.
-
For anyone following this, Lee said
|
Beta Was this translation helpful? Give feedback.
-
With the new instrumentation hook & open-telementry, I was able to build my own prometheus exporter; Enabling the experimental instrumentationHook // next.config.js
experimental: {
instrumentationHook: true,
serverComponentsExternalPackages: [
'@opentelemetry/instrumentation',
],
} Only use the instrumentation for nodejs environments (in my case) // instrumentation.ts
export const register = async () => {
if (process.env.NEXT_RUNTIME === 'nodejs') {
await import('./instrumentation-node')
}
}; Initialize OpenTelementry setup with some handy metrics and instrumentations // instrumentation-node.ts
import { PrometheusExporter } from '@opentelemetry/exporter-prometheus';
import { HostMetrics } from '@opentelemetry/host-metrics';
import { registerInstrumentations } from '@opentelemetry/instrumentation';
import { HttpInstrumentation } from '@opentelemetry/instrumentation-http';
import { RuntimeNodeInstrumentation } from '@opentelemetry/instrumentation-runtime-node';
import {
Resource,
detectResourcesSync,
envDetector,
hostDetector,
processDetector,
} from '@opentelemetry/resources';
import { MeterProvider } from '@opentelemetry/sdk-metrics';
import {
ATTR_SERVICE_NAME,
ATTR_SERVICE_VERSION,
} from '@opentelemetry/semantic-conventions';
const exporter = new PrometheusExporter({
port: 9464,
});
const detectedResources = detectResourcesSync({
detectors: [envDetector, processDetector, hostDetector],
});
const customResources = new Resource({
[ATTR_SERVICE_NAME]: 'my-app',
[ATTR_SERVICE_VERSION]: '0.1.0',
});
const resources = detectedResources.merge(customResources);
const meterProvider = new MeterProvider({
readers: [exporter],
resource: resources,
});
const hostMetrics = new HostMetrics({
name: `my-app-metrics`,
meterProvider,
});
registerInstrumentations({
meterProvider,
instrumentations: [
new HttpInstrumentation(),
new RuntimeNodeInstrumentation(),
],
});
hostMetrics.start(); After start-up you can find the metrics at Oh hello @maapteh, long time no see :D |
Beta Was this translation helpful? Give feedback.
-
Any news about normal connection Prometheus to NextJs? |
Beta Was this translation helpful? Give feedback.
-
Beta Was this translation helpful? Give feedback.
-
Is there any way we can collect and create metrics out of the default spans provided by next.js? I'm missing the "route/path" information in the "http_server_duration_bucket" metrics. |
Beta Was this translation helpful? Give feedback.
-
here is solution I found working on next 15+ (at least what I have now): |
Beta Was this translation helpful? Give feedback.
-
I am wondering if there is a way to integrate Prometheus with Next.js to scrape metrics. I know that Next.js has a built-in relayer that allows you to analyze and measure the performance of pages using different metrics., just don't know how to hook that up with Prometheus. Any idea or help on this please?
Beta Was this translation helpful? Give feedback.
All reactions