Skip to content

Emit database query spans as OpenTelemetry clients#1334

Merged
lovasoa merged 2 commits into
mainfrom
otel-client-db-spans
Jun 21, 2026
Merged

Emit database query spans as OpenTelemetry clients#1334
lovasoa merged 2 commits into
mainfrom
otel-client-db-spans

Conversation

@lovasoa

@lovasoa lovasoa commented Jun 21, 2026

Copy link
Copy Markdown
Collaborator

Summary

  • Mark SQLPage database query spans as OpenTelemetry client spans with otel.kind = "client".
  • Set otel.name to the SQL operation name, matching the existing db.operation.name value.
  • Keep the existing standard database attributes such as db.query.text, db.system.name, and db.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 --all
  • cargo test db_query_span_uses_otel_database_client_semantics
  • cargo clippy --all-targets --all-features -- -D warnings
  • cargo test

@lovasoa lovasoa marked this pull request as ready for review June 21, 2026 17:52
@lovasoa lovasoa merged commit df306ac into main Jun 21, 2026
51 checks passed
@lovasoa lovasoa deleted the otel-client-db-spans branch June 21, 2026 17:52

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 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,

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 👍 / 👎.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant