Skip to content
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
6 changes: 5 additions & 1 deletion examples/telemetry/test.hurl
Original file line number Diff line number Diff line change
Expand Up @@ -40,4 +40,8 @@ body contains "\"service.name\""
body contains "\"sqlpage\""
body contains "\"nginx\""
body contains "\"name\":\"GET /\""
body contains "\"db.query\""
body contains "\"name\":\"SELECT\""
body contains "\"kind\":\"SPAN_KIND_CLIENT\""
body contains "\"db.query.text\""
body contains "\"db.system.name\""
body contains "\"db.operation.name\""
20 changes: 20 additions & 0 deletions src/webserver/database/execute_queries.rs
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,8 @@ fn create_db_query_span(
let operation_name = sql.split_whitespace().next().unwrap_or("").to_uppercase();
let span = tracing::info_span!(
"db.query",
"otel.kind" = "client",
"otel.name" = %operation_name,

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Avoid naming CTE database spans as WITH

For any page whose SQL statement starts with a CTE (WITH ... SELECT ...), including in-repo SQLPage pages such as examples/official-site/search.sql, the existing operation_name heuristic is just the first token, so this new OpenTelemetry override exports the span name as WITH rather than the actual operation. Since backends group and search database spans by the exported span name, CTE-backed SELECT/INSERT/etc. queries become misclassified once this replaces the stable db.query name; derive the operation from the parsed statement or keep a fallback name when the first token is WITH.

Useful? React with 👍 / 👎.

{ otel::DB_QUERY_TEXT } = sql,
{ otel::DB_SYSTEM_NAME } = db_system_name,
{ otel::DB_OPERATION_NAME } = operation_name,
Expand Down Expand Up @@ -892,6 +894,24 @@ mod tests {
.expect("closed span fields")
}

#[test]
fn db_query_span_uses_otel_database_client_semantics() {
let fields = with_recorded_span_fields(|| {
let (span, operation_name) =
create_db_query_span("select * from users", Path::new("index.sql"), 7, "sqlite");
assert_eq!(operation_name, "SELECT");
drop(span);
});

assert_eq!(fields["otel.kind"], "client");
assert_eq!(fields["otel.name"], "SELECT");
assert_eq!(fields[otel::DB_QUERY_TEXT], "select * from users");
assert_eq!(fields[otel::DB_SYSTEM_NAME], "sqlite");
assert_eq!(fields[otel::DB_OPERATION_NAME], "SELECT");
assert_eq!(fields[otel::CODE_FILE_PATH], "index.sql");
assert_eq!(fields[otel::CODE_LINE_NUMBER], "7");
}

#[test]
fn db_query_success_records_ok_status_and_row_count() {
let fields = with_recorded_span_fields(|| {
Expand Down
Loading