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.
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.
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:
Requestvalues (understood by implementors ofshackle_client) inshackle_queue, and passing them toshackle_telemetry:reply/4andshackle_telemetry:timeout/2. I added this to get the HTTP status code and URL path frombuoy.shackle_telemetry:connection_error/2andshackle_telemetry:queued_time/2.erlang:monotonic_time/{0,1}to measure elapsed time, instead ofos:timestamp/0andtimer: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/0and subtraction to measure elapsed time between events.I got rid of a couple of
?WARNinvocations 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.