Skip to content

Adds DTrace probes to slog messages with slog-dtrace - #489

Merged
bnaecker merged 1 commit into
mainfrom
add-slog-dtrace
Dec 8, 2021
Merged

bnaecker merged 1 commit into
mainfrom
add-slog-dtrace

Conversation

@bnaecker

@bnaecker bnaecker commented Dec 8, 2021

Copy link
Copy Markdown
Collaborator

No description provided.

@bnaecker

bnaecker commented Dec 8, 2021 •

Copy link
Copy Markdown
Collaborator Author

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: fa

Note that the strings are cut off due to the default strsize DTrace option of 256.

Comment thread nexus/src/lib.rs
Comment on lines +168 to +169
let (drain, registration) = slog_dtrace::with_drain(
config

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

(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>?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

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.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

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?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

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.

@bnaecker
bnaecker merged commit 5519e93 into main Dec 8, 2021
@bnaecker
bnaecker deleted the add-slog-dtrace branch December 8, 2021 16:08
@bnaecker bnaecker mentioned this pull request Dec 8, 2021
6 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants