Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(spans): Improve span data http method extraction #2396

Merged
merged 4 commits into from
Aug 10, 2023
Merged
Show file tree
Hide file tree
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
15 changes: 10 additions & 5 deletions relay-general/src/store/normalize/span/tag_extraction.rs
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,11 @@ fn extract_shared_tags(event: &Event) -> BTreeMap<SpanTagKey, Value> {
}

/// Writes fields into [`Span::data`].
///
/// Generating new span data fields is based on a combination of looking at
/// [span operations](https://develop.sentry.dev/sdk/performance/span-operations/) and
/// existing [span data](https://develop.sentry.dev/sdk/performance/span-data-conventions/) fields,
/// and rely on Sentry conventions and heuristics.
pub(crate) fn extract_tags(span: &Span, config: &Config) -> BTreeMap<SpanTagKey, Value> {
let mut span_tags: BTreeMap<SpanTagKey, Value> = BTreeMap::new();
if let Some(unsanitized_span_op) = span.op.value() {
Expand Down Expand Up @@ -200,15 +205,15 @@ pub(crate) fn extract_tags(span: &Span, config: &Config) -> BTreeMap<SpanTagKey,
.and_then(|data| data.get("description.scrubbed"))
.and_then(|value| value.as_str());

// TODO(iker): we're relying on the existance of `http.method`
// or `db.operation`. This is not guaranteed, and we'll need to
// parse the span description in that case.
let action = match (span_module, span_op.as_str(), scrubbed_description) {
(Some("http"), _, _) => span
.data
.value()
// TODO(iker): some SDKs extract this as method
.and_then(|v| v.get("http.method"))
.and_then(|v| {
v.get("http.request.method")
.or(v.get("http.method"))
.or(v.get("method"))
})
.and_then(|method| method.as_str())
.map(|s| s.to_uppercase()),
(_, "db.redis", Some(desc)) => {
Expand Down
34 changes: 29 additions & 5 deletions relay-server/src/metrics_extraction/spans/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,30 @@ mod tests {
"http.method": "GET"
}
},
{
"description": "POST http://domain.tld/hi",
"op": "http.client",
"parent_span_id": "8f5a2b8768cafb4e",
"span_id": "bd429c44b67a3eb4",
"start_timestamp": 1597976300.0000000,
"timestamp": 1597976302.0000000,
"trace_id": "ff62a8b040f340bda5d830223def1d81",
"data": {
"http.request.method": "POST"
}
},
{
"description": "PUT http://domain.tld/hi",
"op": "http.client",
"parent_span_id": "8f5a2b8768cafb4e",
"span_id": "bd429c44b67a3eb4",
"start_timestamp": 1597976300.0000000,
"timestamp": 1597976302.0000000,
"trace_id": "ff62a8b040f340bda5d830223def1d81",
"data": {
"method": "PUT"
}
},
{
"description": "GET /hi/this/is/just/the/path",
"op": "http.client",
Expand Down Expand Up @@ -280,7 +304,7 @@ mod tests {
"trace_id": "ff62a8b040f340bda5d830223def1d81",
"status": "ok",
"data": {
"db.system": "MyDatabase",
"db.system": "postgresql",
"db.operation": "SELECT"
}
},
Expand All @@ -304,7 +328,7 @@ mod tests {
"trace_id": "ff62a8b040f340bda5d830223def1d81",
"status": "ok",
"data": {
"db.system": "MyDatabase",
"db.system": "postgresql",
"db.operation": "INSERT"
}
},
Expand All @@ -318,7 +342,7 @@ mod tests {
"trace_id": "ff62a8b040f340bda5d830223def1d81",
"status": "ok",
"data": {
"db.system": "MyDatabase",
"db.system": "postgresql",
"db.operation": "INSERT"
}
},
Expand All @@ -342,7 +366,7 @@ mod tests {
"trace_id": "ff62a8b040f340bda5d830223def1d81",
"status": "ok",
"data": {
"db.system": "MyDatabase",
"db.system": "postgresql",
"db.operation": "SELECT"
}
},
Expand All @@ -356,7 +380,7 @@ mod tests {
"trace_id": "ff62a8b040f340bda5d830223def1d81",
"status": "ok",
"data": {
"db.system": "MyDatabase",
"db.system": "postgresql",
"db.operation": "SELECT"
}
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,88 @@ expression: metrics
"transaction.op": "myop",
},
},
Metric {
name: "d:spans/exclusive_time@millisecond",
value: Distribution(
2000.0,
),
timestamp: UnixTimestamp(1597976302),
tags: {
"environment": "fake_environment",
"http.status_code": "500",
"span.action": "POST",
"span.category": "http",
"span.description": "POST http://domain.tld",
"span.domain": "domain.tld",
"span.group": "25faf23529f71d3e",
"span.module": "http",
"span.op": "http.client",
"transaction": "gEt /api/:version/users/",
"transaction.method": "POST",
"transaction.op": "myop",
},
},
Metric {
name: "d:spans/exclusive_time_light@millisecond",
value: Distribution(
2000.0,
),
timestamp: UnixTimestamp(1597976302),
tags: {
"environment": "fake_environment",
"http.status_code": "500",
"span.action": "POST",
"span.category": "http",
"span.description": "POST http://domain.tld",
"span.domain": "domain.tld",
"span.group": "25faf23529f71d3e",
"span.module": "http",
"span.op": "http.client",
"transaction.method": "POST",
"transaction.op": "myop",
},
},
Metric {
name: "d:spans/exclusive_time@millisecond",
value: Distribution(
2000.0,
),
timestamp: UnixTimestamp(1597976302),
tags: {
"environment": "fake_environment",
"http.status_code": "500",
"span.action": "PUT",
"span.category": "http",
"span.description": "PUT http://domain.tld",
"span.domain": "domain.tld",
"span.group": "488f09b46e5978be",
"span.module": "http",
"span.op": "http.client",
"transaction": "gEt /api/:version/users/",
"transaction.method": "POST",
"transaction.op": "myop",
},
},
Metric {
name: "d:spans/exclusive_time_light@millisecond",
value: Distribution(
2000.0,
),
timestamp: UnixTimestamp(1597976302),
tags: {
"environment": "fake_environment",
"http.status_code": "500",
"span.action": "PUT",
"span.category": "http",
"span.description": "PUT http://domain.tld",
"span.domain": "domain.tld",
"span.group": "488f09b46e5978be",
"span.module": "http",
"span.op": "http.client",
"transaction.method": "POST",
"transaction.op": "myop",
},
},
Metric {
name: "d:spans/exclusive_time@millisecond",
value: Distribution(
Expand Down Expand Up @@ -399,7 +481,7 @@ expression: metrics
"span.module": "db",
"span.op": "db.sql.query",
"span.status": "ok",
"span.system": "mydatabase",
"span.system": "postgresql",
"transaction": "gEt /api/:version/users/",
"transaction.method": "POST",
"transaction.op": "myop",
Expand All @@ -422,7 +504,7 @@ expression: metrics
"span.module": "db",
"span.op": "db.sql.query",
"span.status": "ok",
"span.system": "mydatabase",
"span.system": "postgresql",
"transaction.method": "POST",
"transaction.op": "myop",
},
Expand Down Expand Up @@ -485,7 +567,7 @@ expression: metrics
"span.module": "db",
"span.op": "db.sql.query",
"span.status": "ok",
"span.system": "mydatabase",
"span.system": "postgresql",
"transaction": "gEt /api/:version/users/",
"transaction.method": "POST",
"transaction.op": "myop",
Expand All @@ -506,7 +588,7 @@ expression: metrics
"span.module": "db",
"span.op": "db.sql.query",
"span.status": "ok",
"span.system": "mydatabase",
"span.system": "postgresql",
"transaction.method": "POST",
"transaction.op": "myop",
},
Expand All @@ -526,7 +608,7 @@ expression: metrics
"span.module": "db",
"span.op": "db.sql.query",
"span.status": "ok",
"span.system": "mydatabase",
"span.system": "postgresql",
"transaction": "gEt /api/:version/users/",
"transaction.method": "POST",
"transaction.op": "myop",
Expand All @@ -547,7 +629,7 @@ expression: metrics
"span.module": "db",
"span.op": "db.sql.query",
"span.status": "ok",
"span.system": "mydatabase",
"span.system": "postgresql",
"transaction.method": "POST",
"transaction.op": "myop",
},
Expand Down Expand Up @@ -608,7 +690,7 @@ expression: metrics
"span.module": "db",
"span.op": "db.sql.query",
"span.status": "ok",
"span.system": "mydatabase",
"span.system": "postgresql",
"transaction": "gEt /api/:version/users/",
"transaction.method": "POST",
"transaction.op": "myop",
Expand All @@ -631,7 +713,7 @@ expression: metrics
"span.module": "db",
"span.op": "db.sql.query",
"span.status": "ok",
"span.system": "mydatabase",
"span.system": "postgresql",
"transaction.method": "POST",
"transaction.op": "myop",
},
Expand All @@ -653,7 +735,7 @@ expression: metrics
"span.module": "db",
"span.op": "db",
"span.status": "ok",
"span.system": "mydatabase",
"span.system": "postgresql",
"transaction": "gEt /api/:version/users/",
"transaction.method": "POST",
"transaction.op": "myop",
Expand All @@ -676,7 +758,7 @@ expression: metrics
"span.module": "db",
"span.op": "db",
"span.status": "ok",
"span.system": "mydatabase",
"span.system": "postgresql",
"transaction.method": "POST",
"transaction.op": "myop",
},
Expand Down
Loading