Skip to content

Commit 0414b72

Browse files
authored
fix(tracing): actually use span on permissioning (#48)
We were not actually entering the span, so the logs show up pretty empty.
1 parent 6ae1e33 commit 0414b72

File tree

2 files changed

+21
-7
lines changed

2 files changed

+21
-7
lines changed

src/perms/builders.rs

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ fn now() -> u64 {
2020
}
2121

2222
/// Possible errors when permissioning a builder.
23-
#[derive(Debug, thiserror::Error, Clone, Copy, PartialEq, Eq)]
23+
#[derive(Debug, thiserror::Error, Clone, PartialEq, Eq)]
2424
pub enum BuilderPermissionError {
2525
/// Action attempt too early.
2626
#[error("action attempt too early")]
@@ -31,8 +31,10 @@ pub enum BuilderPermissionError {
3131
ActionAttemptTooLate,
3232

3333
/// Builder not permissioned for this slot.
34-
#[error("builder not permissioned for this slot")]
35-
NotPermissioned,
34+
#[error(
35+
"builder not permissioned for this slot: requesting builder {0}, permissioned builder {1}"
36+
)]
37+
NotPermissioned(String, String),
3638
}
3739

3840
/// An individual builder.
@@ -178,7 +180,10 @@ impl Builders {
178180
permissioned_builder = %self.current_builder().sub,
179181
"Builder not permissioned for this slot"
180182
);
181-
return Err(BuilderPermissionError::NotPermissioned);
183+
return Err(BuilderPermissionError::NotPermissioned(
184+
sub.to_owned(),
185+
self.current_builder().sub.to_owned(),
186+
));
182187
}
183188

184189
Ok(())

src/perms/middleware.rs

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -160,25 +160,32 @@ where
160160
"builder::permissioning",
161161
builder = tracing::field::Empty,
162162
permissioned_builder = this.builders.current_builder().sub(),
163+
requesting_builder = tracing::field::Empty,
163164
current_slot = this.builders.calc().current_slot(),
165+
current_timepoint_within_slot =
166+
this.builders.calc().current_timepoint_within_slot(),
164167
permissioning_error = tracing::field::Empty,
165168
);
166169

170+
let guard = span.enter();
171+
167172
info!("builder permissioning check started");
168173

169174
// Check if the sub is in the header.
170175
let sub = match validate_header_sub(req.headers().get("x-jwt-claim-sub")) {
171176
Ok(sub) => sub,
172177
Err(err) => {
173-
info!(api_err = %err.1.message, "permission denied");
174178
span.record("permissioning_error", err.1.message);
179+
info!(api_err = %err.1.message, "permission denied");
175180
return Ok(err.into_response());
176181
}
177182
};
178183

184+
span.record("requesting_builder", sub);
185+
179186
if let Err(err) = this.builders.is_builder_permissioned(sub) {
180-
info!(api_err = %err, "permission denied");
181187
span.record("permissioning_error", err.to_string());
188+
info!(api_err = %err, "permission denied");
182189

183190
let hint = builder_permissioning_hint(&err);
184191

@@ -187,6 +194,8 @@ where
187194

188195
info!("builder permissioned successfully");
189196

197+
drop(guard);
198+
190199
this.inner.call(req).await
191200
})
192201
}
@@ -218,7 +227,7 @@ const fn builder_permissioning_hint(
218227
crate::perms::BuilderPermissionError::ActionAttemptTooLate => {
219228
Some("Action attempted too late in the slot.")
220229
}
221-
crate::perms::BuilderPermissionError::NotPermissioned => {
230+
crate::perms::BuilderPermissionError::NotPermissioned(_, _) => {
222231
Some("Builder is not permissioned for this slot.")
223232
}
224233
}

0 commit comments

Comments
 (0)