-
Notifications
You must be signed in to change notification settings - Fork 266
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2511 from calebschoepp/otel-logging
feat(telemetry): Add a compatibility layer that emits app logs as tracing events.
- Loading branch information
Showing
7 changed files
with
188 additions
and
68 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains 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 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 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,25 @@ | ||
use std::{ascii::escape_default, sync::OnceLock}; | ||
|
||
use crate::env; | ||
|
||
/// Takes a Spin application log and emits it as a tracing event. | ||
/// | ||
/// This acts as a compatibility layer to easily get Spin app logs as events in our OTel traces. | ||
pub fn app_log_to_tracing_event(buf: &[u8]) { | ||
static CELL: OnceLock<bool> = OnceLock::new(); | ||
if *CELL.get_or_init(env::spin_disable_log_to_tracing) { | ||
return; | ||
} | ||
|
||
if let Ok(s) = std::str::from_utf8(buf) { | ||
tracing::info!(app_log = s); | ||
} else { | ||
tracing::info!( | ||
app_log_non_utf8 = buf | ||
.iter() | ||
.take(50) | ||
.map(|&x| escape_default(x).to_string()) | ||
.collect::<String>() | ||
); | ||
} | ||
} |
This file contains 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 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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.