Getting route match path instead of full route
See original GitHub issueHello!
First of all, nice package, very useful for Prometheus. Then, I’m experimenting Prometheus and its metrics (and observability overall), so I’m pretty new.
Context
Currently, my application expose metrics based on all paths (which is something great), until I noticed that every path is exposed in metrics. For instance, a route matching /api/v1/users/:userId
will creates a metric with the requested userId ({ path: "/api/v1/users/myUserIDRoot"}
). Here is the configuration I have for otel
:
const telemetryConfig = OpenTelemetryModule.forRoot({
metrics: {
defaultMetrics: true, // Includes Default Metrics
apiMetrics: {
enable: true, // Includes api metrics
timeBuckets: [],
},
},
nodeSDKConfiguration: {
metricExporter: new PrometheusExporter({
port: 3001,
}),
},
});
Current Behavior
With the above configuration, I have metrics like these for path:
http_request_duration_seconds_bucket{method="GET",status="200",path="/api/v1/videos/11e6f85f-02ba-4e11-ab9b-1300d3946942",le="600"} 1 1627067714334
http_request_duration_seconds_bucket{method="GET",status="200",path="/api/v1/videos/11e6f85f-02ba-4e11-ab9b-1300d3946942",le="+Inf"} 1 1627067714334
Expected behavior
http_request_duration_seconds_bucket{method="GET",status="200",path="/api/v1/videos/:videoId",le="600"} 1 1627067714334
http_request_duration_seconds_bucket{method="GET",status="200",path="/api/v1/videos/:videoId",le="+Inf"} 1 1627067714334
Problem
First, I was wondering if it was a good thing to expose every id’s of resources in metrics, as it could generate a lot of entry ? Then, is there a way this module can only expose the endpoint (e.g. /api/v1/users/:userId
), maybe I missed something in the configuration ?
Thanks!
Issue Analytics
- State:
- Created 2 years ago
- Comments:8 (5 by maintainers)
Top GitHub Comments
@hesham-desouky that might be a bug, would you mind opening a ticket?
Hi @pragmaticivan
We tested this on NestJS with fastify using version 3.0.1 This is our registration code
OpenTelemetryModule.forRoot({ metrics: { hostMetrics: true, // Includes Host Metrics defaultMetrics: true, // Includes Default Metrics apiMetrics: { enable: true, // Includes api metrics timeBuckets: [], // You can change the default time buckets ignoreRoutes: ['/favicon.ico'], // You can ignore specific routes (See https://docs.nestjs.com/middleware#excluding-routes for options) ignoreUndefinedRoutes: true, //Records metrics for all URLs, even undefined ones }, }, }),
But we still say a separate counter for each route parameters. Are we missing something?