diff --git a/CHANGELOG.md b/CHANGELOG.md index e9a0247a9b..8b795fdd43 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,11 @@ # Changelog +## Unreleased + +**Internal**: + +- Exclude more spans fron metrics extraction. ([#2522](https://github.com/getsentry/relay/pull/2522)) + ## 23.9.1 - No documented changes. diff --git a/relay-dynamic-config/src/defaults.rs b/relay-dynamic-config/src/defaults.rs index c3e0a4f6d2..6d9b5a6450 100644 --- a/relay-dynamic-config/src/defaults.rs +++ b/relay-dynamic-config/src/defaults.rs @@ -46,14 +46,12 @@ pub fn add_span_metrics(project_config: &mut ProjectConfig) { RuleCondition::Not(NotCondition { inner: Box::new(RuleCondition::Glob(GlobCondition { name: span_op_field_name.into(), - value: GlobPatterns::new(vec!["db*clickhouse".into()]), - })), - }), - RuleCondition::Not(NotCondition { - inner: Box::new(RuleCondition::Eq(EqCondition { - name: span_op_field_name.into(), - value: Value::String("db.redis".into()), - options: Default::default(), + value: GlobPatterns::new(vec![ + "*activerecord*".into(), + "*clickhouse*".into(), + "*mongodb*".into(), + "*redis*".into(), + ]), })), }), RuleCondition::Not(NotCondition { diff --git a/relay-server/src/actors/processor.rs b/relay-server/src/actors/processor.rs index cf1e720b1a..b2e98b7626 100644 --- a/relay-server/src/actors/processor.rs +++ b/relay-server/src/actors/processor.rs @@ -55,7 +55,7 @@ use { crate::actors::project_cache::UpdateRateLimits, crate::utils::{EnvelopeLimiter, MetricsLimiter}, relay_event_normalization::{span, StoreConfig, StoreProcessor}, - relay_event_schema::protocol::ProfileContext, + relay_event_schema::protocol::{ProfileContext, Span}, relay_quotas::{RateLimitingError, RedisRateLimiter}, symbolic_unreal::{Unreal4Error, Unreal4ErrorKind}, }; @@ -2236,11 +2236,31 @@ impl EnvelopeProcessorService { Ok(()) } + #[cfg(feature = "processing")] + fn is_span_allowed(&self, span: &Span) -> bool { + let Some(op) = span.op.value() else { + return false; + }; + let Some(description) = span.description.value() else { + return false; + }; + let system: &str = span + .data + .value() + .and_then(|v| v.get("span.system")) + .and_then(|system| system.as_str()) + .unwrap_or_default(); + op.starts_with("db") + && !(op.contains("clickhouse") + || op.contains("mongodb") + || op.contains("redis") + || op.contains("activerecord")) + && !(op == "db.sql.query" && !(description.contains(r#""$"#) || system == "mongodb")) + } + #[cfg(feature = "processing")] fn extract_spans(&self, state: &mut ProcessEnvelopeState) { // For now, drop any spans submitted by the SDK. - - use relay_event_schema::protocol::Span; state.managed_envelope.retain_items(|item| match item.ty() { ItemType::Span => ItemAction::DropSilently, _ => ItemAction::Keep, @@ -2286,25 +2306,19 @@ impl EnvelopeProcessorService { // Add child spans as envelope items. if let Some(child_spans) = event.spans.value() { for span in child_spans { - if let Some(inner_span) = span.value() { - // HACK: filter spans based on module until we figure out grouping. - let Some(span_op) = inner_span.op.value() else { - continue; - }; - let Some(span_description) = inner_span.description.value() else { - continue; - }; - if all_modules_enabled - || span_op.starts_with("db") && !span_description.contains(r#""$"#) - { - // HACK: clone the span to set the segment_id. This should happen - // as part of normalization once standalone spans reach wider adoption. - let mut new_span = inner_span.clone(); - new_span.segment_id = transaction_span.segment_id.clone(); - new_span.is_segment = Annotated::new(false); - add_span(Annotated::new(new_span)); - } + let Some(inner_span) = span.value() else { + continue; + }; + // HACK: filter spans based on module until we figure out grouping. + if !all_modules_enabled && !self.is_span_allowed(inner_span) { + continue; } + // HACK: clone the span to set the segment_id. This should happen + // as part of normalization once standalone spans reach wider adoption. + let mut new_span = inner_span.clone(); + new_span.segment_id = transaction_span.segment_id.clone(); + new_span.is_segment = Annotated::new(false); + add_span(Annotated::new(new_span)); } } diff --git a/relay-server/src/metrics_extraction/event.rs b/relay-server/src/metrics_extraction/event.rs index 01489ac91d..2c1620b19a 100644 --- a/relay-server/src/metrics_extraction/event.rs +++ b/relay-server/src/metrics_extraction/event.rs @@ -859,6 +859,43 @@ mod tests { "data": { "db.system": "MyDatabase" } + }, + { + "description": "things.count({\"$and\":[{\"services\":{\"$exists\":true}},{\"test_id\":38}]})", + "op": "db.mongodb.find", + "parent_span_id": "8f5a2b8768cafb4e", + "span_id": "bb7af8b99e95af5f", + "start_timestamp": 1597976300.0000000, + "timestamp": 1597976302.0000000, + "trace_id": "ff62a8b040f340bda5d830223def1d81", + "status": "ok", + "data": {} + }, + { + "description": "DELETE FROM table WHERE conditions", + "op": "db.sql.activerecord", + "parent_span_id": "8f5a2b8768cafb4e", + "span_id": "bb7af8b99e95af5f", + "start_timestamp": 1597976300.0000000, + "timestamp": 1597976302.0000000, + "trace_id": "ff62a8b040f340bda5d830223def1d81", + "status": "ok", + "data": { + "db.system": "MyDatabase" + } + }, + { + "description": "SAVEPOINT save_this_one", + "op": "db.redis.command", + "parent_span_id": "8f5a2b8768cafb4e", + "span_id": "bb7af8b99e95af5f", + "start_timestamp": 1597976300.0000000, + "timestamp": 1597976302.0000000, + "trace_id": "ff62a8b040f340bda5d830223def1d81", + "status": "ok", + "data": { + "db.system": "redis" + } } ] }