Skip to content

Commit

Permalink
feat(spans): Ignore more spans for the DB module (#2522)
Browse files Browse the repository at this point in the history
  • Loading branch information
phacops committed Sep 20, 2023
1 parent a022a11 commit 1965fdb
Show file tree
Hide file tree
Showing 4 changed files with 84 additions and 29 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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.
Expand Down
14 changes: 6 additions & 8 deletions relay-dynamic-config/src/defaults.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
56 changes: 35 additions & 21 deletions relay-server/src/actors/processor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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},
};
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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));
}
}

Expand Down
37 changes: 37 additions & 0 deletions relay-server/src/metrics_extraction/event.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
}
]
}
Expand Down

0 comments on commit 1965fdb

Please sign in to comment.