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

Include event and handler name as tags with handle_in metrics #187

Merged
merged 4 commits into from
Jan 22, 2023
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions lib/prom_ex/plugins/phoenix.ex
Original file line number Diff line number Diff line change
Expand Up @@ -330,12 +330,14 @@ if Code.ensure_loaded?(Phoenix) do
reporter_options: [
buckets: [10, 100, 500, 1_000, 5_000, 10_000]
],
tag_values: fn %{socket: %Socket{endpoint: endpoint}} ->
tag_values: fn %{socket: %Socket{endpoint: endpoint, handler: handler}, event: event} ->
%{
endpoint: normalize_module_name(endpoint)
endpoint: normalize_module_name(endpoint),
event: event,
Copy link
Owner

Choose a reason for hiding this comment

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

Overall this looks good to me. The only part that gives me pause is the event since it is a binary and has the potential to be an unbounded value. I think it would be best if this module accepts an option to normalize event values. The default implementation would be a passthrough:

fn event -> 
  event
end

But then the user could override this to do something like so:

fn 
  "join" -> "join"
  "leave" -> "leave"
  _ -> "unknown"
end

Thoughts?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Hey @akoutmos good idea and I can implement it like you've described. Just might be a little slow due to the holiday season!

Copy link
Owner

Choose a reason for hiding this comment

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

No worries at all my friend! Happy holidays!

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've updated the PR with support for a normalizer function. I also added some new tests- one to test for handled_in metrics generally which I noticed were missing and another to test that configuring the normalize_event_names option works as expected.

handler: handler
}
end,
tags: [:endpoint],
tags: [:endpoint, :handler, :event],
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 noticed the phoenix tests only check for event counts and not the tag values, so this is a bit hard to test without editing a decent chunk of code. I could add additional test coverage there for this whole module in a follow-up PR if that would be preferred!

unit: {:native, duration_unit}
)
]
Expand Down