question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Getting route match path instead of full route

See original GitHub issue

Hello!

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:closed
  • Created 2 years ago
  • Comments:8 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
pragmaticivancommented, Apr 21, 2022

@hesham-desouky that might be a bug, would you mind opening a ticket?

0reactions
hesham-desoukycommented, Apr 20, 2022

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?

Read more comments on GitHub >

github_iconTop Results From Across the Web

react-router v6: get path pattern for current route - Stack Overflow
I made a custom hook useCurrentPath with react-router v6 to get the current path of route, and it work for me. If the...
Read more >
Use matchPath to Match Nested Route Paths in Parent Routes ...
In this lesson we'll use the `matchPath` function exported by react-router to find active nested routes inside of a parent component.
Read more >
Angular route: pathMatch='full', when to NOT use?
When you try navigating to 'home/child-route', the full path is now not matching with 'home', and this gives error.
Read more >
matchPath - React Router v5
matchPath. This lets you use the same matching code that <Route> uses except outside of the normal render cycle, like gathering up data...
Read more >
[V6] [Feature]: Support absolute paths in descendant `<Routes ...
Currently (v6.0.0-beta.4) the route definition in the nested <Routes> will match on a relative route, even though they start with ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found