Skip to content

Commit fcb97ab

Browse files
committed
feat: update request ID handling and stats row creation to use SmolStr references
1 parent c6db2db commit fcb97ab

3 files changed

Lines changed: 11 additions & 11 deletions

File tree

crates/http-service/src/lib.rs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -144,8 +144,8 @@ where
144144
let request_id = remote_traceparent(&req);
145145
async move {
146146
self_
147-
.handle_request(&request_id, req)
148-
.instrument(tracing::debug_span!("http", request_id))
147+
.handle_request(request_id.clone(), req)
148+
.instrument(tracing::debug_span!("http", ?request_id))
149149
.await
150150
}
151151
});
@@ -228,7 +228,7 @@ where
228228
/// handle HTTP request.
229229
async fn handle_request<B>(
230230
&self,
231-
request_id: &str,
231+
request_id: SmolStr,
232232
mut request: hyper::Request<B>,
233233
) -> Result<hyper::Response<HyperOutgoingBody>>
234234
where
@@ -312,7 +312,7 @@ where
312312

313313
let stats = self
314314
.context
315-
.new_stats_row(request_id.to_smolstr(), app_name.clone(), &cfg);
315+
.new_stats_row(&request_id, &app_name, &cfg);
316316

317317
let response = match executor.execute(request, stats.clone()).await {
318318
Ok(mut response) => {
@@ -332,7 +332,7 @@ where
332332
let (status_code, fail_reason, msg) = map_err(error);
333333
stats.status_code(status_code);
334334
stats.fail_reason(fail_reason as u32);
335-
tracing::debug!(?fail_reason, request_id, "stats");
335+
tracing::debug!(?fail_reason, ?request_id, "stats");
336336

337337
#[cfg(feature = "metrics")]
338338
metrics::metrics(
@@ -426,12 +426,12 @@ fn map_err(error: Error) -> (u16, AppResult, HyperOutgoingBody) {
426426
(status_code, fail_reason, msg)
427427
}
428428

429-
fn remote_traceparent(req: &hyper::Request<hyper::body::Incoming>) -> String {
429+
fn remote_traceparent(req: &hyper::Request<hyper::body::Incoming>) -> SmolStr {
430430
req.headers()
431431
.get(TRACEPARENT)
432432
.and_then(|v| v.to_str().ok())
433-
.map(|s| s.to_string())
434-
.unwrap_or(nanoid::nanoid!())
433+
.map(|s| s.to_smolstr())
434+
.unwrap_or(nanoid::nanoid!().to_smolstr())
435435
}
436436

437437
/// Creates an HTTP 500 response.

crates/runtime/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -409,7 +409,7 @@ pub trait ContextT {
409409

410410
fn make_key_value_store(&self, stores: &Vec<KvStoreOption>) -> KeyValueStore;
411411

412-
fn new_stats_row(&self, request_id: SmolStr, app: SmolStr, cfg: &App) -> Arc<dyn StatsVisitor>;
412+
fn new_stats_row(&self, request_id: &SmolStr, app: &SmolStr, cfg: &App) -> Arc<dyn StatsVisitor>;
413413
}
414414

415415
pub trait ExecutorCache {

src/context.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -88,8 +88,8 @@ impl ContextT for Context {
8888

8989
fn new_stats_row(
9090
&self,
91-
_request_id: SmolStr,
92-
_app: SmolStr,
91+
_request_id: &SmolStr,
92+
_app: &SmolStr,
9393
_cfg: &App,
9494
) -> Arc<dyn StatsVisitor> {
9595
Arc::new(StatsStub::default())

0 commit comments

Comments
 (0)