Skip to content

Commit b403607

Browse files
committed
feat(outbound-redis): Trace outbound-redis host component
Signed-off-by: Caleb Schoepp <[email protected]>
1 parent 68dc711 commit b403607

File tree

2 files changed

+17
-0
lines changed

2 files changed

+17
-0
lines changed

crates/outbound-redis/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-redis/src/lib.rs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ use spin_world::v2::redis::{
99
};
1010

1111
pub use host_component::OutboundRedisComponent;
12+
use tracing::{instrument, Level};
1213

1314
struct RedisResults(Vec<RedisResult>);
1415

@@ -70,8 +71,12 @@ impl OutboundRedis {
7071

7172
impl v2::Host for OutboundRedis {}
7273

74+
// TODO: #[instrument(err)] is only reporting the outer error (if the guest traps), we want to mark
75+
// the span as failed if the inner result is an error too.
76+
7377
#[async_trait]
7478
impl v2::HostConnection for OutboundRedis {
79+
#[instrument(name = "spin_outbound_redis.open_connection", skip(self), err(level = Level::INFO), fields(otel.kind = "client", db.system = "redis"))]
7580
async fn open(&mut self, address: String) -> Result<Result<Resource<RedisConnection>, Error>> {
7681
if !self.is_address_allowed(&address) {
7782
return Ok(Err(Error::InvalidAddress));
@@ -80,6 +85,7 @@ impl v2::HostConnection for OutboundRedis {
8085
self.establish_connection(address).await
8186
}
8287

88+
#[instrument(name = "spin_outbound_redis.publish", skip(self, connection, payload), err(level = Level::INFO), fields(otel.kind = "client", db.system = "redis", otel.name = format!("PUBLISH {}", channel)))]
8389
async fn publish(
8490
&mut self,
8591
connection: Resource<RedisConnection>,
@@ -96,6 +102,7 @@ impl v2::HostConnection for OutboundRedis {
96102
.await)
97103
}
98104

105+
#[instrument(name = "spin_outbound_redis.get", skip(self, connection), err(level = Level::INFO), fields(otel.kind = "client", db.system = "redis", otel.name = format!("GET {}", key)))]
99106
async fn get(
100107
&mut self,
101108
connection: Resource<RedisConnection>,
@@ -109,6 +116,7 @@ impl v2::HostConnection for OutboundRedis {
109116
.await)
110117
}
111118

119+
#[instrument(name = "spin_outbound_redis.set", skip(self, connection, value), err(level = Level::INFO), fields(otel.kind = "client", db.system = "redis", otel.name = format!("SET {}", key)))]
112120
async fn set(
113121
&mut self,
114122
connection: Resource<RedisConnection>,
@@ -123,6 +131,7 @@ impl v2::HostConnection for OutboundRedis {
123131
.await)
124132
}
125133

134+
#[instrument(name = "spin_outbound_redis.incr", skip(self, connection), err(level = Level::INFO), fields(otel.kind = "client", db.system = "redis", otel.name = format!("INCRBY {} 1", key)))]
126135
async fn incr(
127136
&mut self,
128137
connection: Resource<RedisConnection>,
@@ -136,6 +145,7 @@ impl v2::HostConnection for OutboundRedis {
136145
.await)
137146
}
138147

148+
#[instrument(name = "spin_outbound_redis.del", skip(self, connection), err(level = Level::INFO), fields(otel.kind = "client", db.system = "redis", otel.name = format!("DEL {}", keys.join(" "))))]
139149
async fn del(
140150
&mut self,
141151
connection: Resource<RedisConnection>,
@@ -149,6 +159,7 @@ impl v2::HostConnection for OutboundRedis {
149159
.await)
150160
}
151161

162+
#[instrument(name = "spin_outbound_redis.sadd", skip(self, connection, values), err(level = Level::INFO), fields(otel.kind = "client", db.system = "redis", otel.name = format!("SADD {} {}", key, values.join(" "))))]
152163
async fn sadd(
153164
&mut self,
154165
connection: Resource<RedisConnection>,
@@ -169,6 +180,7 @@ impl v2::HostConnection for OutboundRedis {
169180
.await)
170181
}
171182

183+
#[instrument(name = "spin_outbound_redis.smembers", skip(self, connection), err(level = Level::INFO), fields(otel.kind = "client", db.system = "redis", otel.name = format!("SMEMBERS {}", key)))]
172184
async fn smembers(
173185
&mut self,
174186
connection: Resource<RedisConnection>,
@@ -182,6 +194,7 @@ impl v2::HostConnection for OutboundRedis {
182194
.await)
183195
}
184196

197+
#[instrument(name = "spin_outbound_redis.srem", skip(self, connection, values), err(level = Level::INFO), fields(otel.kind = "client", db.system = "redis", otel.name = format!("SREM {} {}", key, values.join(" "))))]
185198
async fn srem(
186199
&mut self,
187200
connection: Resource<RedisConnection>,
@@ -196,6 +209,7 @@ impl v2::HostConnection for OutboundRedis {
196209
.await)
197210
}
198211

212+
#[instrument(name = "spin_outbound_redis.execute", skip(self, connection), err(level = Level::INFO), fields(otel.kind = "client", db.system = "redis", otel.name = format!("{}", command)))]
199213
async fn execute(
200214
&mut self,
201215
connection: Resource<RedisConnection>,

0 commit comments

Comments
 (0)