Skip to content

Allow additional (custom) tags in HTTP events#259

Open
aj-foster wants to merge 2 commits intoakoutmos:masterfrom
aj-foster:aj/http-tags
Open

Allow additional (custom) tags in HTTP events#259
aj-foster wants to merge 2 commits intoakoutmos:masterfrom
aj-foster:aj/http-tags

Conversation

@aj-foster
Copy link

Change description

This PR allows users of the library to define additional_tags that 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:

def plugins do
  [
    {PromEx.Plugins.Phoenix,
     router: MyApp.Router,
     endpoint: MyApp.Endpoint,
     additional_tags: [:authenticated]}
  ]
end

Then, set data in the connection struct's private data using a matching prefixed key:

# Authentication Plug
def call(conn, opts) do
  # ...
  Plug.Conn.put_private(conn, :prom_ex_authenticated, true)
end

Additional details and screenshots

I initially implemented this PR in a way that required additional tags to be stored in a nested :prom_ex map 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_ex map 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

  • I have added unit tests to cover my changes.
  • I have added documentation to cover my changes.
  • My changes have passed unit tests and have been tested E2E in an example project.

This obviates the need for a helper function to set additional
tag data on a connection struct.
@PragTob
Copy link

PragTob commented Jul 3, 2025

Ayo, @akoutmos is there anything we can do to help move this forward? :)

IMG_20171221_144804_Bokeh

@akoutmos
Copy link
Owner

akoutmos commented Jul 4, 2025

Hey there!

Sorry I have been unresponsive as of late. Currently in the middle of a cross country move. I may be able to get to this next week when I have a functional office once again.

@PragTob
Copy link

PragTob commented Jul 4, 2025

@akoutmos if there's anyone who can't say anything about OSS maintainers being unresponsive then that's me as you well know 😅 😬

Have a good move and if you manage to take a look I'd appreciate it, but no worries whatsoever! I imagine such a move being quite involved and stressful - take care! 💚

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.

3 participants