Allow additional (custom) tags in HTTP events #259
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.
Change description
This PR allows users of the library to define
additional_tagsthat should be included in HTTP metrics from the Phoenix plugin.What problem does this solve?
Folks may wish to tag HTTP events with information other than the default tags (status, route, etc.). For example, someone might want to tag events with
authenticated="true"based on the authentication status of the request. While this kind of custom tagging can be abused, when used well, it can greatly improve one's ability to query the collected data.Example usage
First, configure the Phoenix plugin to look for additional tags:
Then, set data in the connection struct's private data using a matching prefixed key:
Additional details and screenshots
I initially implemented this PR in a way that required additional tags to be stored in a nested
:prom_exmap in the private connection data (you can see the first commit for that version). This made it difficult to store metadata, however, because callers would have to check for the existence of the:prom_exmap and either create it or merge data into it as appropriate. Using top-level interpolated keys solves this issue while still preventing naming collisions with other private data.Checklist