Skip to content

Commit

Permalink
Use Spin telemetry crate
Browse files Browse the repository at this point in the history
- Ensures compatibility with containerd-shim-spin which already inits a tracing subscriber
- Bumps to latest Spin dependencies

Signed-off-by: Kate Goldenring <[email protected]>
  • Loading branch information
kate-goldenring committed Jul 29, 2024
1 parent d48a8d7 commit 013c45b
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 14 deletions.
11 changes: 5 additions & 6 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,12 @@ anyhow = "1.0.68"
clap = { version = "3.1.15", features = ["derive", "env"] }
futures = "0.3.25"
serde = "1.0.188"
spin-app = { git = "https://github.com/fermyon/spin", tag = "v2.4.0" }
spin-core = { git = "https://github.com/fermyon/spin", tag = "v2.4.0" }
spin-expressions = { git = "https://github.com/fermyon/spin", tag = "v2.4.0" }
spin-trigger = { git = "https://github.com/fermyon/spin", tag = "v2.4.0" }
spin-app = { git = "https://github.com/fermyon/spin", tag = "v2.5.1" }
spin-core = { git = "https://github.com/fermyon/spin", tag = "v2.5.1" }
spin-expressions = { git = "https://github.com/fermyon/spin", tag = "v2.5.1" }
spin-trigger = { git = "https://github.com/fermyon/spin", tag = "v2.5.1" }
spin-telemetry = { git = "https://github.com/fermyon/spin", tag = "v2.5.1" }
tokio = { version = "1.37", features = ["full"] }
tracing = { version = "0.1", features = ["log"] }
tracing-subscriber = { version = "0.3.7", features = ["env-filter"] }
paho-mqtt = { version = "0.12.3", default-features = false, features = [
"vendored-ssl",
] }
Expand Down
3 changes: 1 addition & 2 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -211,8 +211,7 @@ impl MqttTrigger {
msg.payload().to_vec(),
msg.topic().to_owned(),
)
.await
.map_err(|err| tracing::error!("{err}"));
.await?;
}
Ok(None) => {
// Todo: Figure out what this case is
Expand Down
19 changes: 13 additions & 6 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,19 @@ type Command = TriggerExecutorCommand<MqttTrigger>;

#[tokio::main]
async fn main() -> Result<(), anyhow::Error> {
tracing_subscriber::fmt()
.with_writer(std::io::stderr)
.with_env_filter(tracing_subscriber::EnvFilter::from_default_env())
.with_ansi(std::io::stderr().is_terminal())
.init();

let _telemetry_guard = spin_telemetry::init(build_info())?;
let trigger = Command::parse();
trigger.run().await
}

/// Returns build information of the parent Spin process, similar to: 0.1.0 (2be4034 2022-03-31).
fn build_info() -> String {
let spin_version = env_var("SPIN_VERSION");
let spin_commit_sha = env_var("SPIN_COMMIT_SHA");
let spin_commit_date = env_var("SPIN_COMMIT_DATE");
format!("{spin_version} ({spin_commit_sha} {spin_commit_date})")
}

fn env_var(name: &str) -> String {
std::env::var(name).unwrap_or_else(|_| "unknown".to_string())
}

0 comments on commit 013c45b

Please sign in to comment.