-
Notifications
You must be signed in to change notification settings - Fork 4
[telemetry] Add structured logging with span-based tracing #453
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
Merged
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
c7cc5cc
[telemetry] Add structured logging with span-based tracing
0xsiddharthks d3e36fa
[telemetry] Trim verbose docs and inline comments from hashi-telemetry
0xsiddharthks 5d6963f
[telemetry] Fold hashi-telemetry into a module under hashi-types
0xsiddharthks e4a9c97
[ci] Drop verbose comment on RUST_LOG_JSON env var
0xsiddharthks 01b316b
[telemetry] Drop no-op TelemetryGuard and lift hashi-localnet init to…
0xsiddharthks cf300ec
[telemetry] Write fmt layer output to stderr instead of stdout
0xsiddharthks File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -10,6 +10,7 @@ permissions: | |
|
|
||
| env: | ||
| RUSTFLAGS: -Dwarnings | ||
| RUST_LOG_JSON: "0" | ||
|
|
||
| jobs: | ||
| test: | ||
|
|
||
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -6,4 +6,5 @@ pub mod committee; | |
| pub mod guardian; | ||
| pub mod move_types; | ||
| pub mod proto; | ||
| pub mod telemetry; | ||
| pub mod utils; | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,102 @@ | ||
| // Copyright (c) Mysten Labs, Inc. | ||
| // SPDX-License-Identifier: Apache-2.0 | ||
|
|
||
| //! Shared `tracing` subscriber initialization for all hashi binaries. | ||
|
|
||
| use std::io::IsTerminal; | ||
| use std::io::stderr; | ||
|
|
||
| use tracing::level_filters::LevelFilter; | ||
| use tracing_subscriber::EnvFilter; | ||
| use tracing_subscriber::Layer; | ||
| use tracing_subscriber::layer::SubscriberExt; | ||
| use tracing_subscriber::util::SubscriberInitExt; | ||
|
|
||
| pub struct TelemetryConfig { | ||
| default_level: LevelFilter, | ||
| json: Option<bool>, | ||
| file_line: bool, | ||
| target: bool, | ||
| } | ||
|
|
||
| impl Default for TelemetryConfig { | ||
| fn default() -> Self { | ||
| Self::new() | ||
| } | ||
| } | ||
|
|
||
| impl TelemetryConfig { | ||
| pub fn new() -> Self { | ||
| Self { | ||
| default_level: LevelFilter::INFO, | ||
| json: None, | ||
| file_line: false, | ||
| target: true, | ||
| } | ||
| } | ||
|
|
||
| pub fn with_default_level(mut self, level: LevelFilter) -> Self { | ||
| self.default_level = level; | ||
| self | ||
| } | ||
|
|
||
| pub fn with_json(mut self, json: bool) -> Self { | ||
| self.json = Some(json); | ||
| self | ||
| } | ||
|
|
||
| pub fn with_file_line(mut self, enabled: bool) -> Self { | ||
| self.file_line = enabled; | ||
| self | ||
| } | ||
|
|
||
| pub fn with_target(mut self, enabled: bool) -> Self { | ||
| self.target = enabled; | ||
| self | ||
| } | ||
|
|
||
| /// `RUST_LOG_JSON=0`/`false`/`no` forces TTY; any other value forces JSON. | ||
| pub fn with_env(mut self) -> Self { | ||
| if let Ok(value) = std::env::var("RUST_LOG_JSON") { | ||
| self.json = match value.trim().to_ascii_lowercase().as_str() { | ||
| "0" | "false" | "no" => Some(false), | ||
| _ => Some(true), | ||
| }; | ||
| } | ||
| self | ||
| } | ||
|
|
||
| pub fn init(self) { | ||
| let use_json = match self.json { | ||
| Some(true) => true, | ||
| Some(false) => false, | ||
| None => !stderr().is_terminal(), | ||
| }; | ||
|
|
||
| let env_filter = EnvFilter::builder() | ||
| .with_default_directive(self.default_level.into()) | ||
| .from_env_lossy(); | ||
|
|
||
| if use_json { | ||
| let fmt_layer = tracing_subscriber::fmt::layer() | ||
| .with_writer(stderr) | ||
| .with_file(true) | ||
| .with_line_number(true) | ||
| .with_target(self.target) | ||
| .json() | ||
| .with_filter(env_filter); | ||
|
|
||
| tracing_subscriber::registry().with(fmt_layer).init(); | ||
| } else { | ||
| let fmt_layer = tracing_subscriber::fmt::layer() | ||
| .with_writer(stderr) | ||
| .with_file(self.file_line) | ||
| .with_line_number(self.file_line) | ||
| .with_target(self.target) | ||
| .with_ansi(stderr().is_terminal()) | ||
| .with_filter(env_filter); | ||
|
|
||
| tracing_subscriber::registry().with(fmt_layer).init(); | ||
| } | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.