-
Notifications
You must be signed in to change notification settings - Fork 48
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
Add telemetry events to handlers #25
Changes from all commits
b2afaec
661248c
3452b5c
da57bfb
b1bb2df
b64e364
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,6 +4,13 @@ defmodule Plug.Cowboy.Handler do | |
@already_sent {:plug_conn, :sent} | ||
|
||
def init(req, {plug, opts}) do | ||
start = System.monotonic_time() | ||
|
||
:telemetry.execute([:plug_adapter, :request, :start], %{ | ||
name: :plug_cowboy, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It looks like for this execute, There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Also, the |
||
start_time: System.system_time() | ||
}) | ||
|
||
conn = @connection.conn(req) | ||
|
||
try do | ||
|
@@ -15,13 +22,24 @@ defmodule Plug.Cowboy.Handler do | |
{:ok, req, {plug, opts}} | ||
catch | ||
kind, reason -> | ||
exit_on_error(kind, reason, System.stacktrace(), {plug, :call, [conn, opts]}) | ||
stacktrace = System.stacktrace() | ||
metadata = %{kind: kind, error: reason, stacktrace: stacktrace, name: :plug_cowboy} | ||
measurements = %{duration: System.monotonic_time() - start} | ||
:telemetry.execute([:plug_adapter, :request, :exception], measurements, metadata) | ||
|
||
exit_on_error(kind, reason, stacktrace, {plug, :call, [conn, opts]}) | ||
after | ||
receive do | ||
@already_sent -> :ok | ||
after | ||
0 -> :ok | ||
0 -> | ||
:ok | ||
end | ||
else | ||
result -> | ||
measurements = %{duration: System.monotonic_time() - start} | ||
:telemetry.execute([:plug_adapter, :request, :stop], measurements, %{name: :plug_cowboy}) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ideally we'd have the updated There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Did you see the discussion at #25 (comment)? I'm happy to add it back. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I mean, w/o the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Let's add the connection to all events then (and in this case it is There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is the updated There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. A problem I ran into in my PR is that there's no way that I could figure out to get ahold of an updated There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Let’s return the conn then from try. There is nothing we can do about catch though, it is a non local return. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is the issue I ran into with the Tesla PR where you may want to know something about the conn in an exception. If you reference it from there it is the original argument.
What is the suggestion here? I'm a little confused. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think it's to assign the result of |
||
result | ||
end | ||
end | ||
|
||
|
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.
tbh, I don't really understand the event name. I don't see the concept
:request
really in this library. Plug has an adapter concept, but nothing is explicitly calledplug_adapter
. Maybe[:plug, :adapter, :handler, :start]
?If I had my way, I'd go with
[:plug_cowboy, :handler, :start]
since that's a pretty literal mapping of the code that's being executed.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.
The question is if a
handler
is a requirement ofplug_adapter
or just an implementation naming thing here in this library. It would just need to be consistent across adapters. Does anyone know the details?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.
🤷 As long as it's a static name, I'll live with it