-
Notifications
You must be signed in to change notification settings - Fork 1
fix: use endpoint templates in metrics labels #115
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
4366645
fix: use endpoint templates instead of paths in metrics labels
rsbh 6d2e638
refactor: extract ROUTES constants for endpoint templates
rsbh dc170aa
refactor: rename API/APIS routes to API_INTERNAL/API_PROXY
rsbh e4d72ee
fix: rename API_PROXY to API_REFERENCE for /apis/ route
rsbh afc03cf
test: add toEndpoint tests for metric route templates
rsbh 55b8949
fix(ci): use in-process Nitro runner for Windows dev smoke test
rsbh File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,47 @@ | ||
| import { describe, expect, test } from 'bun:test' | ||
| import { toEndpoint } from './telemetry' | ||
|
|
||
| describe('toEndpoint', () => { | ||
| test('root path', () => { | ||
| expect(toEndpoint('/')).toBe('/') | ||
| }) | ||
|
|
||
| test('docs pages map to /docs/:slug', () => { | ||
| expect(toEndpoint('/docs/intro')).toBe('/docs/:slug') | ||
| expect(toEndpoint('/docs/guides/installation')).toBe('/docs/:slug') | ||
| expect(toEndpoint('/developer/gettingstarted/auth')).toBe('/docs/:slug') | ||
| }) | ||
|
|
||
| test('api internal routes keep exact path', () => { | ||
| expect(toEndpoint('/api/page')).toBe('/api/page') | ||
| expect(toEndpoint('/api/search')).toBe('/api/search') | ||
| expect(toEndpoint('/api/specs')).toBe('/api/specs') | ||
| expect(toEndpoint('/api/health')).toBe('/api/health') | ||
| }) | ||
|
|
||
| test('api reference pages map to /apis/:slug', () => { | ||
| expect(toEndpoint('/apis/petstore/listPets')).toBe('/apis/:slug') | ||
| expect(toEndpoint('/apis/frontier/getUser')).toBe('/apis/:slug') | ||
| }) | ||
|
|
||
| test('assets map to /assets/:file', () => { | ||
| expect(toEndpoint('/assets/chunk-abc123.js')).toBe('/assets/:file') | ||
| expect(toEndpoint('/assets/style-xyz.css')).toBe('/assets/:file') | ||
| }) | ||
|
|
||
| test('content paths map to /_content/:path', () => { | ||
| expect(toEndpoint('/_content/docs/intro.mdx')).toBe('/_content/:path') | ||
| }) | ||
|
|
||
| test('static routes keep exact path', () => { | ||
| expect(toEndpoint('/llms.txt')).toBe('/llms.txt') | ||
| expect(toEndpoint('/robots.txt')).toBe('/robots.txt') | ||
| expect(toEndpoint('/sitemap.xml')).toBe('/sitemap.xml') | ||
| expect(toEndpoint('/og')).toBe('/og') | ||
| }) | ||
|
|
||
| test('versioned docs map to /docs/:slug', () => { | ||
| expect(toEndpoint('/v1/docs/intro')).toBe('/docs/:slug') | ||
| expect(toEndpoint('/v2/guides/setup')).toBe('/docs/:slug') | ||
| }) | ||
| }) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🧩 Analysis chain
🏁 Script executed:
Repository: raystack/chronicle
Length of output: 2143
🌐 Web query:
Nitro h3 event.req.url format full URL or relative path💡 Result:
Nitro/H3: event.req.url is a relative URL/path component (not a full absolute URL). In Nitro, you typically access the request URL parts via: - event.url.pathname for the matched pathname (example middleware/routing uses event.url.pathname) [1] - event.req.url is then used as the path-ish value when Nitro/H3 creates the H3 event (and is consumed as such by proxy/middleware expectations); in an H3 bug report, overwriting node req.url with a decoded path is explicitly called out as wrong because it’s “consumed by HTTP proxies and Node.js middleware that expect the percent-encoded form” [2]. That implies req.url holds the (encoded) path/relative portion, not an origin-based full URL. If you need a full absolute URL, Nitro provides getRequestURL(event) (discussed in Nitro issues about origin/hostname extraction) rather than relying on event.req.url [3]. So, the answer to “Nitro h3 event.req.url format full URL or relative path” is: relative path (path + query), not an absolute URL with scheme/host.
Citations:
Fix unsafe
new URL(event.req.url)usage in telemetry (can throw).In Nitro/H3,
event.req.urlis typically a relative path (path + query), sonew URL(event.req.url).pathnamecan throwTypeError: Invalid URLand break request metrics. This matches the repo’s existing pattern usingevent.path || event.req.url?.split('?')[0]inpackages/chronicle/src/server/routes/[...slug].md.ts.🔧 Proposed fix
📝 Committable suggestion
🤖 Prompt for AI Agents