Skip to content
Merged
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
3 changes: 3 additions & 0 deletions common/src/db/pagination_cache.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ use actix_web::{HttpResponse, ResponseError, body::BoxBody};
use moka::future::Cache;
use opentelemetry::{global, metrics::Counter};
use std::{sync::Arc, time::Duration};
use tracing::instrument;

use crate::error::ErrorInformation;

Expand Down Expand Up @@ -57,6 +58,7 @@ impl PaginationCache {
}

/// Return a cached total count, computing it at most once for concurrent requests with the same key.
#[instrument(skip(self, compute), fields(cache_hit = true))]
pub async fn cached_total(
&self,
key: String,
Expand All @@ -67,6 +69,7 @@ impl PaginationCache {
self.cache
.try_get_with(key, async {
misses.add(1, &[]);
tracing::Span::current().record("cache_hit", false);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

suggestion (bug_risk): Be cautious relying on Span::current() inside the try_get_with async closure.

Because try_get_with controls how the async closure is scheduled, it may run on a different task where the #[instrument] span is no longer current, making this record call a no-op or updating the wrong span. If you need reliable instrumentation, capture the span at the start of cached_total (e.g. let span = tracing::Span::current();) and call span.record("cache_hit", false); inside the closure instead of using Span::current() there.

compute().await
})
.await
Expand Down
Loading