Skip to content
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

Extract route name logic to a single middleware and use it everywhere #527

Merged
merged 3 commits into from
May 28, 2024

Conversation

charleskorn
Copy link
Contributor

@charleskorn charleskorn commented May 27, 2024

What this PR does:

This PR introduces a new HTTP middleware, RouteInjector, that extracts and stores the active request's route name for use in telemetry.

This route name can then be used in traces, metrics and logs. The existing tracing and metrics middlewares have been updated to use this single source of the route name, and applications can call middleware.ExtractRouteName to include the route name in logs when appropriate.

Which issue(s) this PR fixes:

(none)

Checklist

  • Tests updated
  • CHANGELOG.md updated - the order of entries should be [CHANGE], [FEATURE], [ENHANCEMENT], [BUGFIX]

middleware/route_injector.go Outdated Show resolved Hide resolved
@@ -31,6 +31,7 @@ type contextKey int

const (
contextKeyMethodName contextKey = 1
contextKeyRouteName contextKey = 2
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: move to route_injector.go?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wanted to keep all the contextKey values in one place, as otherwise there's a risk that we define two contextKeys with the same value (eg. two contextKeys with value 3).

@charleskorn charleskorn merged commit 27d7d41 into main May 28, 2024
6 checks passed
@charleskorn charleskorn deleted the charleskorn/inject-request-route branch May 28, 2024 01:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants