Skip to content

Commit fc7182b

Browse files
authored
fix: propagate sub info to inner future (#106)
1 parent cf742ca commit fc7182b

File tree

1 file changed

+16
-11
lines changed

1 file changed

+16
-11
lines changed

src/perms/middleware.rs

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ use std::{
2121
sync::{Arc, LazyLock},
2222
};
2323
use tower::{Layer, Service};
24-
use tracing::info;
24+
use tracing::{debug, info, info_span, Instrument};
2525
use tracing_opentelemetry::OpenTelemetrySpanExt;
2626

2727
const ATTEMPTS: &str = "init4.perms.attempts";
@@ -187,18 +187,18 @@ where
187187
LazyLock::force(&DESCRIBE);
188188

189189
Box::pin(async move {
190+
let current_slot = this.builders.calc().current_slot();
190191
let span = tracing::info_span!(
191192
"builder::permissioning",
192-
builder = tracing::field::Empty,
193+
otel.status_code = tracing::field::Empty,
193194
permissioned_builder = this.builders.current_builder().sub(),
194195
requesting_builder = tracing::field::Empty,
195-
current_slot = this.builders.calc().current_slot(),
196+
current_slot,
196197
current_timepoint_within_slot = this
197198
.builders
198199
.calc()
199200
.current_point_within_slot()
200201
.expect("host chain has started"),
201-
otel.status_code = tracing::field::Empty
202202
);
203203

204204
let guard = span.enter();
@@ -213,7 +213,7 @@ where
213213
description: Cow::Owned(err.1.message.to_string()),
214214
});
215215
info!(api_err = %err.1.message, "permission denied");
216-
counter!("init4.perms.missing_header").increment(1);
216+
counter!(MISSING_HEADER).increment(1);
217217
return Ok(err.into_response());
218218
}
219219
};
@@ -227,17 +227,22 @@ where
227227

228228
let hint = builder_permissioning_hint(&err);
229229

230-
counter!("init4.perms.permission_denied", "builder" => sub.to_string())
231-
.increment(1);
230+
counter!(
231+
PERMISSION_DENIED,
232+
"builder" => sub.to_string())
233+
.increment(1);
232234

233235
return Ok(ApiError::permission_denied(hint).into_response());
234236
}
235-
236-
drop(guard);
237-
info!("builder permissioned successfully");
237+
debug!("builder permissioned successfully");
238238
counter!(SUCCESS, "builder" => sub.to_string()).increment(1);
239+
drop(guard);
240+
241+
// Create a new span for the inner service call.
242+
let span = info_span!("authentication", builder = sub, current_slot);
243+
let _ = sub; // drops the borrow so we can move req below
239244

240-
this.inner.call(req).await
245+
this.inner.call(req).instrument(span).await
241246
})
242247
}
243248
}

0 commit comments

Comments
 (0)