Skip to content

fix(tracing): actually use span on permissioning #48

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Jul 2, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 9 additions & 4 deletions src/perms/builders.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ fn now() -> u64 {
}

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

/// Builder not permissioned for this slot.
#[error("builder not permissioned for this slot")]
NotPermissioned,
#[error(
"builder not permissioned for this slot: requesting builder {0}, permissioned builder {1}"
)]
NotPermissioned(String, String),
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@prestwich you ended up being right here that the messages on this error should've been made more useful. This was merged but we can keep working on this on a new PR.

}

/// An individual builder.
Expand Down Expand Up @@ -178,7 +180,10 @@ impl Builders {
permissioned_builder = %self.current_builder().sub,
"Builder not permissioned for this slot"
);
return Err(BuilderPermissionError::NotPermissioned);
return Err(BuilderPermissionError::NotPermissioned(
sub.to_owned(),
self.current_builder().sub.to_owned(),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

subs are not secrets right @rswanson

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

correct

));
}

Ok(())
Expand Down
15 changes: 12 additions & 3 deletions src/perms/middleware.rs
Original file line number Diff line number Diff line change
Expand Up @@ -160,25 +160,32 @@ where
"builder::permissioning",
builder = tracing::field::Empty,
permissioned_builder = this.builders.current_builder().sub(),
requesting_builder = tracing::field::Empty,
current_slot = this.builders.calc().current_slot(),
current_timepoint_within_slot =
this.builders.calc().current_timepoint_within_slot(),
permissioning_error = tracing::field::Empty,
);

let guard = span.enter();

info!("builder permissioning check started");

// Check if the sub is in the header.
let sub = match validate_header_sub(req.headers().get("x-jwt-claim-sub")) {
Ok(sub) => sub,
Err(err) => {
info!(api_err = %err.1.message, "permission denied");
span.record("permissioning_error", err.1.message);
info!(api_err = %err.1.message, "permission denied");
return Ok(err.into_response());
}
};

span.record("requesting_builder", sub);

if let Err(err) = this.builders.is_builder_permissioned(sub) {
info!(api_err = %err, "permission denied");
span.record("permissioning_error", err.to_string());
info!(api_err = %err, "permission denied");

let hint = builder_permissioning_hint(&err);

Expand All @@ -187,6 +194,8 @@ where

info!("builder permissioned successfully");

drop(guard);

this.inner.call(req).await
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should we instrument this future with the perms span?

})
}
Expand Down Expand Up @@ -218,7 +227,7 @@ const fn builder_permissioning_hint(
crate::perms::BuilderPermissionError::ActionAttemptTooLate => {
Some("Action attempted too late in the slot.")
}
crate::perms::BuilderPermissionError::NotPermissioned => {
crate::perms::BuilderPermissionError::NotPermissioned(_, _) => {
Some("Builder is not permissioned for this slot.")
}
}
Expand Down