File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -63,14 +63,20 @@ function normalizeOtlpTracesUrl(url: string): string {
6363 }
6464}
6565
66- // Metrics counterpart to `normalizeOtlpTracesUrl`. The endpoint may already
67- // carry a signal-specific suffix (traces); swap it for `/v1/metrics`.
66+ // Metrics counterpart to `normalizeOtlpTracesUrl`. Operates on the parsed
67+ // pathname (not a raw string suffix) so query strings and trailing slashes
68+ // don't corrupt the result: swap a `/v1/traces` suffix for `/v1/metrics`,
69+ // otherwise append `/v1/metrics`.
6870function normalizeOtlpMetricsUrl ( url : string ) : string {
6971 if ( ! url ) return url
7072 try {
71- if ( url . endsWith ( '/v1/metrics' ) ) return url
72- const base = url . replace ( / \/ v 1 \/ t r a c e s $ / , '' ) . replace ( / \/ $ / , '' )
73- return `${ base } /v1/metrics`
73+ const u = new URL ( url )
74+ const path = u . pathname . replace ( / \/ $ / , '' )
75+ if ( path . endsWith ( '/v1/metrics' ) ) return url
76+ u . pathname = path . endsWith ( '/v1/traces' )
77+ ? path . replace ( / \/ v 1 \/ t r a c e s $ / , '/v1/metrics' )
78+ : `${ path } /v1/metrics`
79+ return u . toString ( )
7480 } catch {
7581 return url
7682 }
You can’t perform that action at this time.
0 commit comments