File tree Expand file tree Collapse file tree 4 files changed +16
-3
lines changed
Expand file tree Collapse file tree 4 files changed +16
-3
lines changed Original file line number Diff line number Diff line change @@ -49,3 +49,12 @@ export function getStatusCodeGroup(statusCode: number) {
4949 }
5050 }
5151}
52+
53+ export const trimUrl = ( url : string , maxDepth ?: number ) => {
54+ if ( typeof maxDepth === 'number' ) {
55+ const withStartingSlashUrl = url . startsWith ( '/' ) ? url : '/' + url
56+ return withStartingSlashUrl . split ( '/' , maxDepth + 1 ) . join ( '/' )
57+ } else {
58+ return url
59+ }
60+ }
Original file line number Diff line number Diff line change @@ -3,6 +3,8 @@ import path from 'node:path'
33
44import { glob } from 'glob'
55
6+ import { trimUrl } from '../metrics/util'
7+
68interface RouteInfo {
79 page : string
810 regex : string
@@ -69,6 +71,6 @@ export function createNextRoutesUrlGroup(maxDepth: number) {
6971 }
7072 }
7173
72- return typeof maxDepth === 'number' ? withoutBasePathUrl . split ( '/' , maxDepth + 1 ) . join ( '/' ) : withoutBasePathUrl
74+ return trimUrl ( withoutBasePathUrl , maxDepth )
7375 }
7476}
Original file line number Diff line number Diff line change 44 getStatusCodeGroup ,
55 isBypassPath ,
66 startTraceHistogram ,
7+ trimUrl ,
78} from '@naverpay/prometheus-core'
89
910import type { HonoPrometheusExporterOptions } from '../types'
@@ -29,7 +30,7 @@ export function getHonoMetricsMiddleware({
2930
3031 const extendedNormalizePath = ( context : Context ) => {
3132 const url = new URL ( context . req . url )
32- return normalizeNextRoutesPath ?.( url . href ) || normalizePath ?.( context ) || url . pathname
33+ return normalizeNextRoutesPath ?.( url . href ) || normalizePath ?.( context ) || trimUrl ( url . pathname , maxDepth )
3334 }
3435
3536 return async ( context , next ) => {
Original file line number Diff line number Diff line change 44 getStatusCodeGroup ,
55 isBypassPath ,
66 startTraceHistogram ,
7+ trimUrl ,
78} from '@naverpay/prometheus-core'
89import onFinished from 'on-finished'
910
@@ -29,7 +30,7 @@ export function getKoaMetricsMiddleware({
2930 const normalizeNextRoutesPath = nextjs ? createNextRoutesUrlGroup ( maxDepth ) : undefined
3031
3132 const extendedNormalizePath = ( context : Context ) => {
32- return normalizeNextRoutesPath ?.( context . url ) || normalizePath ?.( context ) || context . path
33+ return normalizeNextRoutesPath ?.( context . url ) || normalizePath ?.( context ) || trimUrl ( context . path )
3334 }
3435
3536 return async ( context , next ) => {
You can’t perform that action at this time.
0 commit comments