@@ -8,6 +8,7 @@ use spin_core::{async_trait, wasmtime::component::Resource};
8
8
use spin_world:: v2:: mqtt:: { self as v2, Connection as MqttConnection , Error , Qos } ;
9
9
10
10
pub use host_component:: OutboundMqttComponent ;
11
+ use tracing:: { instrument, Level } ;
11
12
12
13
pub struct OutboundMqtt {
13
14
allowed_hosts : spin_outbound_networking:: AllowedHostsConfig ,
@@ -59,6 +60,7 @@ impl v2::Host for OutboundMqtt {}
59
60
60
61
#[ async_trait]
61
62
impl v2:: HostConnection for OutboundMqtt {
63
+ #[ instrument( name = "spin_outbound_mqtt.open_connection" , skip( self , password) , err( level = Level :: INFO ) , fields( otel. kind = "client" ) ) ]
62
64
async fn open (
63
65
& mut self ,
64
66
address : String ,
@@ -80,6 +82,14 @@ impl v2::HostConnection for OutboundMqtt {
80
82
. await
81
83
}
82
84
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" ) ) ]
83
93
async fn publish (
84
94
& mut self ,
85
95
connection : Resource < MqttConnection > ,
0 commit comments