Emit database query spans as OpenTelemetry clients#1334
Conversation
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 2351110a58
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| let span = tracing::info_span!( | ||
| "db.query", | ||
| "otel.kind" = "client", | ||
| "otel.name" = %operation_name, |
There was a problem hiding this comment.
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 👍 / 👎.
Summary
otel.kind = "client".otel.nameto the SQL operation name, matching the existingdb.operation.namevalue.db.query.text,db.system.name, anddb.operation.name.Rationale
SQLPage manually creates spans around executed SQL queries. Those spans already carry standard database attributes, but without client span semantics they can be interpreted as generic internal work by OpenTelemetry consumers. This change keeps the instrumentation vendor-neutral while making the database spans clearer and easier for collectors/backends to classify as outbound database calls.
No vendor-specific attributes are added.
Validation
cargo fmt --allcargo test db_query_span_uses_otel_database_client_semanticscargo clippy --all-targets --all-features -- -D warningscargo test