-
Notifications
You must be signed in to change notification settings - Fork 45
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
More telemetry events #133
base: master
Are you sure you want to change the base?
Conversation
As of OTP 18, the recommended way to measure elapsed time is not to use timer:now_diff/2, but to take two timestamps with erlang:monotonic_time/{0,1} and subtract them.
3da0467
to
e3d8a34
Compare
I think it might be a good idea to also include a |
src/shackle_server.erl
Outdated
shackle_telemetry:send(Client, iolist_size(Data)), | ||
shackle_events:send(Client, iolist_size(Data)), |
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.
In either case, it is not a good idea to calculate the Data size here, until we know we will use it. It is better to use macro in general and pass Data to telemetry/events function to let it calc size only if needed (if dynamic handlers exist).
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.
Great point!
I introduced a macro in shackle_events that will avoid computing these values and terms if there is no configured shackle_hooks handler.
@rkallos It's much better now.
and define them either for telemetry calls:
or for legacy shackle metrics:
The project can use some technique to define at compile time which hooks.hrl to use, allowing client's entirely custom solutions (for example, precompiled functions saved to persistent_term). |
A couple of changes for your consideration:
Request
values (understood by implementors ofshackle_client
) inshackle_queue
, and passing them toshackle_telemetry:reply/4
andshackle_telemetry:timeout/2
. I added this to get the HTTP status code and URL path frombuoy
.shackle_telemetry:connection_error/2
andshackle_telemetry:queued_time/2
.erlang:monotonic_time/{0,1}
to measure elapsed time, instead ofos:timestamp/0
andtimer:now_diff/2
. This is specifically called out in the Time and Time Correction in Erlang, though it mentionserlang:timestamp/0
. It does, however, recommend usingerlang:monotonic_time/0
and subtraction to measure elapsed time between events.I got rid of a couple of
?WARN
invocations because they can be pretty spammy. I'm not sure what the best approach is to handling these log messages, or whether they can be adequately replaced with metrics. I'd be happy to add them back if you want.