Skip to content

Commit 4c416ae

Browse files
committed
feat(outbound-mqtt): Trace outbound-mqtt host component
Signed-off-by: Caleb Schoepp <[email protected]>
1 parent d08b9c7 commit 4c416ae

File tree

3 files changed

+14
-0
lines changed

3 files changed

+14
-0
lines changed

crates/outbound-mqtt/Cargo.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,3 +18,6 @@ spin-outbound-networking = { path = "../outbound-networking" }
1818
table = { path = "../table" }
1919
tokio = { version = "1", features = ["sync"] }
2020
tracing = { workspace = true }
21+
22+
[lints]
23+
workspace = true

crates/outbound-mqtt/src/lib.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ use spin_core::{async_trait, wasmtime::component::Resource};
88
use spin_world::v2::mqtt::{self as v2, Connection as MqttConnection, Error, Qos};
99

1010
pub use host_component::OutboundMqttComponent;
11+
use tracing::{instrument, Level};
1112

1213
pub struct OutboundMqtt {
1314
allowed_hosts: spin_outbound_networking::AllowedHostsConfig,
@@ -59,6 +60,7 @@ impl v2::Host for OutboundMqtt {}
5960

6061
#[async_trait]
6162
impl v2::HostConnection for OutboundMqtt {
63+
#[instrument(name = "spin_outbound_mqtt.open_connection", skip(self, password), err(level = Level::INFO), fields(otel.kind = "client"))]
6264
async fn open(
6365
&mut self,
6466
address: String,
@@ -80,6 +82,14 @@ impl v2::HostConnection for OutboundMqtt {
8082
.await
8183
}
8284

85+
/// Publish a message to the MQTT broker.
86+
///
87+
/// OTEL trace propagation is not directly supported in MQTT V3. You will need to embed the
88+
/// current trace context into the payload yourself.
89+
/// https://w3c.github.io/trace-context-mqtt/#mqtt-v3-recommendation.
90+
#[instrument(name = "spin_outbound_mqtt.publish", skip(self, connection, payload), err(level = Level::INFO),
91+
fields(otel.kind = "producer", otel.name = format!("{} publish", topic), messaging.operation = "publish",
92+
messaging.system = "mqtt"))]
8393
async fn publish(
8494
&mut self,
8595
connection: Resource<MqttConnection>,

examples/spin-timer/Cargo.lock

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)