Skip to content

Commit 013c45b

Browse files
Use Spin telemetry crate
- Ensures compatibility with containerd-shim-spin which already inits a tracing subscriber - Bumps to latest Spin dependencies Signed-off-by: Kate Goldenring <[email protected]>
1 parent d48a8d7 commit 013c45b

File tree

3 files changed

+19
-14
lines changed

3 files changed

+19
-14
lines changed

Cargo.toml

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,12 @@ anyhow = "1.0.68"
1010
clap = { version = "3.1.15", features = ["derive", "env"] }
1111
futures = "0.3.25"
1212
serde = "1.0.188"
13-
spin-app = { git = "https://github.com/fermyon/spin", tag = "v2.4.0" }
14-
spin-core = { git = "https://github.com/fermyon/spin", tag = "v2.4.0" }
15-
spin-expressions = { git = "https://github.com/fermyon/spin", tag = "v2.4.0" }
16-
spin-trigger = { git = "https://github.com/fermyon/spin", tag = "v2.4.0" }
13+
spin-app = { git = "https://github.com/fermyon/spin", tag = "v2.5.1" }
14+
spin-core = { git = "https://github.com/fermyon/spin", tag = "v2.5.1" }
15+
spin-expressions = { git = "https://github.com/fermyon/spin", tag = "v2.5.1" }
16+
spin-trigger = { git = "https://github.com/fermyon/spin", tag = "v2.5.1" }
17+
spin-telemetry = { git = "https://github.com/fermyon/spin", tag = "v2.5.1" }
1718
tokio = { version = "1.37", features = ["full"] }
18-
tracing = { version = "0.1", features = ["log"] }
19-
tracing-subscriber = { version = "0.3.7", features = ["env-filter"] }
2019
paho-mqtt = { version = "0.12.3", default-features = false, features = [
2120
"vendored-ssl",
2221
] }

src/lib.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -211,8 +211,7 @@ impl MqttTrigger {
211211
msg.payload().to_vec(),
212212
msg.topic().to_owned(),
213213
)
214-
.await
215-
.map_err(|err| tracing::error!("{err}"));
214+
.await?;
216215
}
217216
Ok(None) => {
218217
// Todo: Figure out what this case is

src/main.rs

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,19 @@ type Command = TriggerExecutorCommand<MqttTrigger>;
77

88
#[tokio::main]
99
async fn main() -> Result<(), anyhow::Error> {
10-
tracing_subscriber::fmt()
11-
.with_writer(std::io::stderr)
12-
.with_env_filter(tracing_subscriber::EnvFilter::from_default_env())
13-
.with_ansi(std::io::stderr().is_terminal())
14-
.init();
15-
10+
let _telemetry_guard = spin_telemetry::init(build_info())?;
1611
let trigger = Command::parse();
1712
trigger.run().await
1813
}
14+
15+
/// Returns build information of the parent Spin process, similar to: 0.1.0 (2be4034 2022-03-31).
16+
fn build_info() -> String {
17+
let spin_version = env_var("SPIN_VERSION");
18+
let spin_commit_sha = env_var("SPIN_COMMIT_SHA");
19+
let spin_commit_date = env_var("SPIN_COMMIT_DATE");
20+
format!("{spin_version} ({spin_commit_sha} {spin_commit_date})")
21+
}
22+
23+
fn env_var(name: &str) -> String {
24+
std::env::var(name).unwrap_or_else(|_| "unknown".to_string())
25+
}

0 commit comments

Comments
 (0)