Skip to content

Commit a9f5c51

Browse files
committed
refactor(tracing): simplify comments and enhance event filtering logic
1 parent 7791655 commit a9f5c51

File tree

2 files changed

+16
-23
lines changed

2 files changed

+16
-23
lines changed

bookapp/src/tracing_config.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ pub fn init_tracing() -> (
8282
}
8383
}
8484

85-
// Add service context - use hardcoded value to avoid lifetime issues
85+
// Add service context
8686
event
8787
.tags
8888
.insert("service".to_string(), "bookapp".to_string());
@@ -190,6 +190,8 @@ pub fn init_tracing() -> (
190190
sentry::integrations::tracing::layer().event_filter(|md| match *md.level() {
191191
tracing::Level::ERROR => sentry::integrations::tracing::EventFilter::Event,
192192
tracing::Level::WARN => sentry::integrations::tracing::EventFilter::Breadcrumb,
193+
tracing::Level::INFO => sentry::integrations::tracing::EventFilter::Log,
194+
tracing::Level::DEBUG => sentry::integrations::tracing::EventFilter::Ignore,
193195
_ => sentry::integrations::tracing::EventFilter::Ignore,
194196
});
195197

tests/src/telemetry_test.rs

Lines changed: 13 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -302,10 +302,8 @@ async fn query_tempo_for_trace(
302302
if let Ok(tempo_response) =
303303
serde_json::from_str::<TempoResponse>(&response_text)
304304
{
305-
if let Some(batch) = tempo_response
306-
.batches
307-
.iter()
308-
.find(|batch| {
305+
if let Some(batch) =
306+
tempo_response.batches.iter().find(|batch| {
309307
batch.resource.attributes.iter().any(|kv| {
310308
kv.key == "service.name"
311309
&& kv.value.string_value
@@ -315,8 +313,7 @@ async fn query_tempo_for_trace(
315313
})
316314
})
317315
{
318-
if let Some(scope_span) = batch.scope_spans.first()
319-
{
316+
if let Some(scope_span) = batch.scope_spans.first() {
320317
if scope_span.spans.iter().any(|s| {
321318
s.name == config.expected_span_name
322319
&& s.kind == "SPAN_KIND_SERVER"
@@ -529,7 +526,7 @@ async fn test_root_endpoint_generates_telemetry() -> TestResult<()> {
529526
let (trace_id, http_client) = execute_traced_request(&config).await?;
530527
wait_for_trace_propagation(&config).await;
531528

532-
// Test all telemetry systems now that trace ID extraction works
529+
// Test all telemetry systems
533530
verify_telemetry_in_all_systems(&http_client, &trace_id, &config).await?;
534531

535532
println!("✅ Test completed successfully!");
@@ -639,23 +636,17 @@ async fn query_tempo_for_trace_with_error_status(
639636
if let Ok(tempo_response) =
640637
serde_json::from_str::<TempoResponse>(&response_text)
641638
{
642-
if let Some(batch) = tempo_response
643-
.batches
644-
.iter()
645-
.find(|batch| {
646-
batch.resource.attributes.iter().any(|kv| {
647-
kv.key == "service.name"
648-
&& kv.value.string_value
649-
== Some(config.expected_service_name.clone())
650-
})
639+
if let Some(batch) = tempo_response.batches.iter().find(|batch| {
640+
batch.resource.attributes.iter().any(|kv| {
641+
kv.key == "service.name"
642+
&& kv.value.string_value
643+
== Some(config.expected_service_name.clone())
651644
})
652-
{
645+
}) {
653646
if let Some(scope_span) = batch.scope_spans.first() {
654-
if scope_span
655-
.spans
656-
.iter()
657-
.any(|s| s.status.code == Some("STATUS_CODE_ERROR".to_string()))
658-
{
647+
if scope_span.spans.iter().any(|s| {
648+
s.status.code == Some("STATUS_CODE_ERROR".to_string())
649+
}) {
659650
println!("Found trace with error status.");
660651
return Ok(());
661652
}

0 commit comments

Comments
 (0)