Skip to content

fix(otel): recognize db spans that use the stable OpenTelemetry database attributes - #5692

Closed
michielvandermeer wants to merge 1 commit into
getsentry:mainfrom
michielvandermeer:fix/otel-stable-db-attributes
Closed

michielvandermeer wants to merge 1 commit into
getsentry:mainfrom
michielvandermeer:fix/otel-stable-db-attributes

Conversation

@michielvandermeer

Copy link
Copy Markdown

Description

SentrySpanProcessor treats a span as a database span only when it has db.system, and takes the query from db.statement. The stable OpenTelemetry database conventions (v1.33.0) renamed these to db.system.name (v1.30.0) and db.query.text (v1.26.0). Instrumentation that follows them, such as Npgsql 10, sends only the new names. The processor then skips its database branch, so every Npgsql query reaches Sentry with op postgresql and description postgresql. The SQL appears nowhere in the trace view, and the spans never show in Queries insights.

ParseOtelSpanDescription now reads the new names first and falls back to the old ones, through two helpers in OpenTelemetryExtensions (HasDbSystemAttribute, DbQueryTextAttribute). This is the same pattern HttpMethodAttribute and UrlFullAttribute already use. Relay already understands db.system.name in span data, and the processor already copies every attribute into the span's data, so recognizing the span here is the only missing piece.

Notes for review:

  • Spans that carry only db.system and db.statement take the same path as before. The new tests cover both the old and the new names. With the SentrySpanProcessor.cs change reverted, only the two new-name cases fail.
  • Spans that send only the new names change op from the activity's operation name (for Npgsql, postgresql) to db, and their description to the query. A span that sends both old and new names now takes its description from db.query.text.
  • I ran Sentry.OpenTelemetry.Tests on net10.0 (49 passed). The net8.0 and net9.0 targets build, but I don't have those runtimes installed, so CI covers them.

Issues

No issue tracks this. #5435 touches the same database branch of SentrySpanProcessor.

Reminders

🤖 Generated with Claude Code

…ase attributes

The span processor read only db.system and db.statement. Instrumentation that
follows the stable database conventions (semconv v1.33.0, e.g. Npgsql 10) sends
db.system.name and db.query.text instead, so its query spans kept the activity's
operation name as op and description and never showed their SQL. Read the stable
names first and fall back to the old ones, as the HTTP attributes already do.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@michielvandermeer
michielvandermeer marked this pull request as ready for review October 7, 2026 22:53
@github-actions github-actions Bot added the risk: medium PR risk score: medium label Oct 7, 2026
@jamescrosswell

Copy link
Copy Markdown
Collaborator

Hi @michielvandermeer - thanks for the PR. However we've marked the Sentry.OpenTelemetry as obsolete:

We'd recommend you migrate to Sentry.OpenTelemetry.Exporter instead as that's where all future OTEL development will happen.

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

Labels

risk: medium PR risk score: medium

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants