Repository navigation
Adds DTrace probes to slog messages with slog-dtrace - #489
Conversation
|
Example output: $ pfexec dtrace -Zqn 'slog*:::debug { printf("%s\n", copyinstr(arg0)); }'
{"ok":{"location":{"module":"nexus_client","file":"nexus-client/src/lib.rs","line":14},"level":"DEBUG","timestamp":"2021-12-08T06:14:09.487771566Z","message":"client request","kv":{"body":"Some(Body)","method":"POST","uri":"http://127.0.0.1:43081/metrics/
{"ok":{"location":{"module":"oximeter_producer","file":"oximeter/producer/src/lib.rs","line":102},"level":"DEBUG","timestamp":"2021-12-08T06:14:09.487803155Z","message":"registering metric server as a producer","kv":{}}}
{"ok":{"location":{"module":"nexus_client","file":"nexus-client/src/lib.rs","line":14},"level":"DEBUG","timestamp":"2021-12-08T06:14:09.488058003Z","message":"client request","kv":{"body":"Some(Body)","method":"POST","uri":"http://127.0.0.1:46687/metrics/
{"ok":{"location":{"module":"nexus_client","file":"nexus-client/src/lib.rs","line":14},"level":"DEBUG","timestamp":"2021-12-08T06:14:09.492857727Z","message":"client response","kv":{"result":"Ok(Response { url: Url { scheme: \"http\", cannot_be_a_base: fa
{"ok":{"location":{"module":"nexus_client","file":"nexus-client/src/lib.rs","line":14},"level":"DEBUG","timestamp":"2021-12-08T06:14:09.492910831Z","message":"client response","kv":{"result":"Ok(Response { url: Url { scheme: \"http\", cannot_be_a_base: fa
{"ok":{"location":{"module":"nexus_client","file":"nexus-client/src/lib.rs","line":14},"level":"DEBUG","timestamp":"2021-12-08T06:14:09.492943918Z","message":"client response","kv":{"result":"Ok(Response { url: Url { scheme: \"http\", cannot_be_a_base: fa
{"ok":{"location":{"module":"dropshot::server","file":"/home/bnaecker/.cargo/git/checkouts/dropshot-a4a923d29dccc492/ff33033/dropshot/src/server.rs","line":175},"level":"DEBUG","timestamp":"2021-12-08T06:14:09.596289488Z","message":"registered endpoint","
{"ok":{"location":{"module":"dropshot::server","file":"/home/bnaecker/.cargo/git/checkouts/dropshot-a4a923d29dccc492/ff33033/dropshot/src/server.rs","line":111},"level":"DEBUG","timestamp":"2021-12-08T06:14:09.596659707Z","message":"successfully registere
{"ok":{"location":{"module":"oximeter_producer","file":"oximeter/producer/src/lib.rs","line":71},"level":"DEBUG","timestamp":"2021-12-08T06:14:09.603413030Z","message":"registered DTrace probes","kv":{}}}
{"ok":{"location":{"module":"dropshot::server","file":"/home/bnaecker/.cargo/git/checkouts/dropshot-a4a923d29dccc492/ff33033/dropshot/src/server.rs","line":111},"level":"DEBUG","timestamp":"2021-12-08T06:14:09.603952435Z","message":"successfully registere
{"ok":{"location":{"module":"oximeter_producer","file":"oximeter/producer/src/lib.rs","line":94},"level":"DEBUG","timestamp":"2021-12-08T06:14:09.604015343Z","message":"Requested any available port, Dropshot server has been bound to [::1]:55109","kv":{}}}
{"ok":{"location":{"module":"oximeter_producer","file":"oximeter/producer/src/lib.rs","line":102},"level":"DEBUG","timestamp":"2021-12-08T06:14:09.604061242Z","message":"registering metric server as a producer","kv":{}}}
{"ok":{"location":{"module":"nexus_client","file":"nexus-client/src/lib.rs","line":14},"level":"DEBUG","timestamp":"2021-12-08T06:14:09.604308954Z","message":"client request","kv":{"body":"Some(Body)","method":"POST","uri":"http://127.0.0.1:50263/metrics/
{"ok":{"location":{"module":"nexus_client","file":"nexus-client/src/lib.rs","line":14},"level":"DEBUG","timestamp":"2021-12-08T06:14:09.604308954Z","message":"client request","kv":{"body":"Some(Body)","method":"POST","uri":"http://127.0.0.1:50263/metrics/
{"ok":{"location":{"module":"nexus_client","file":"nexus-client/src/lib.rs","line":14},"level":"DEBUG","timestamp":"2021-12-08T06:14:09.609240339Z","message":"client response","kv":{"result":"Ok(Response { url: Url { scheme: \"http\", cannot_be_a_base: faNote that the strings are cut off due to the default |
| let (drain, registration) = slog_dtrace::with_drain( | ||
| config |
There was a problem hiding this comment.
(No action)
This is kinda funny, the tuple looks like it's basically acting as a Result type. Like, the only point of "registration" is to propagate an error if we fail, right? Wouldn't it be more idiomatic to return Result<Drain>?
There was a problem hiding this comment.
Yeah, I get why it seems odd :) I wanted to return both values regardless of whether registration failed, rather than one or the other. Since slog-dtrace is a pretty general-purpose library, we thought it'd be best to leave it up to the consumer to decide how to handle registration failures. So we hand back both the new Drain and the result of registration -- callers can decide to panic or return their own Result.
There was a problem hiding this comment.
But isn't the registration object exclusively:
- Success (no value)
- Error (error value)
? What would a caller do with the registration object that would be different from interacting with a Result?
There was a problem hiding this comment.
They could ignore the error and still use the drain. For example, the slog_dtrace::with_drain function duplicates log messages to the provided Drain and a new Dtrace object. Callers could decide that they want to continue their application, only logging to the first drain and ignoring the fact that those messages won't show up via DTrace.
No description provided.