Skip to content

Add SpanOptions.RowsChildOfQuery to make sql.rows spans children of query spans - #652

Merged
XSAM merged 2 commits into
mainfrom
branch/otelsql-issue-561-66f73e
Sep 5, 2026
Merged

XSAM merged 2 commits into
mainfrom
branch/otelsql-issue-561-66f73e

Conversation

@XSAM

@XSAM XSAM commented Sep 5, 2026

Copy link
Copy Markdown
Owner

Summary

Fixes #561.

When multiple queries run concurrently under the same parent span, sql.conn.query and sql.rows spans are emitted as siblings with no way to tell which rows span belongs to which query. As discussed in the issue, this adds an opt-in option to propagate the query span's context into the rows span.

  • Add SpanOptions.RowsChildOfQuery. When set, the sql.rows span is created from the query span's context, so it becomes a child of the sql.conn.query or sql.stmt.query span that produced it.
  • When the query span is not created (OmitConnQuery, or SpanFilter returns false), the rows span falls back to the caller's span as its parent, same as today.
  • Default is false, so existing behavior is unchanged.

The doc comment notes the trade-off raised in #108: the rows span starts right before the query span ends, so the child appears after its parent on the timeline.

Test plan

  • TestOtConn_QueryContext and TestOtStmt_QueryContext now run with RowsChildOfQuery on and off, and assert the rows span's parent in each case (query span, dummy parent span, or no parent).
  • TestRowsContext unit test for the context selection.
  • make lint license-check and go test -race ./... pass.

🤖 Generated with Claude Code

…uery spans

When multiple queries run concurrently under the same parent span, the
sql.conn.query and sql.rows spans are emitted as siblings and cannot be
correlated with each other. Add an opt-in SpanOptions.RowsChildOfQuery
that creates the sql.rows span from the query span's context so it
becomes a child of the sql.conn.query or sql.stmt.query span that
produced it. When the query span is omitted or filtered out, the rows
span falls back to the caller's span as its parent.

Fixes #561
@XSAM
XSAM force-pushed the branch/otelsql-issue-561-66f73e branch from 7a315d6 to 03eddef Compare September 5, 2026 05:45
@codecov

codecov Bot commented Sep 5, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 89.5%. Comparing base (dd18659) to head (8e94951).

Additional details and impacted files
@@          Coverage Diff          @@
##            main    #652   +/-   ##
=====================================
  Coverage   89.4%   89.5%           
=====================================
  Files         15      15           
  Lines        579     582    +3     
=====================================
+ Hits         518     521    +3     
  Misses        61      61           

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@XSAM
XSAM merged commit f1fb0b8 into main Sep 5, 2026
24 checks passed
@XSAM
XSAM deleted the branch/otelsql-issue-561-66f73e branch September 5, 2026 06:07
@XSAM XSAM mentioned this pull request Sep 6, 2026
XSAM added a commit that referenced this pull request Sep 6, 2026
This release is the last to support [Go 1.25].
The next release will require at least [Go 1.26].

### Added

- Support testing of [Go 1.27]. (#650)
- Add `WithSpanErrorAttributesGetter` option to set additional
attributes (e.g., `db.response.status_code`) on spans when an operation
returns an error. (#651)
- Add `SpanOptions.RowsChildOfQuery` to create `sql.rows` spans as
children of the `sql.conn.query` or `sql.stmt.query` span that produced
them, so concurrent queries can be correlated with their result
iteration. (#652)
- Support `driver.RowsColumnScanner` on [Go 1.27]. (#649)

### Changed

- Replace `ErrorTypeAttributes` with `ErrorTypeAttribute` to avoid
allocating an additional slice. (#643)
- Upgrade OTel to `v1.46.0`. (#644)

### Fixed

- `db.client.operation.duration` histogram now uses the explicit bucket
boundaries recommended by the OTel Semantic Conventions (`0.001` to `10`
seconds) instead of the SDK defaults, which placed virtually all
database operations in the first bucket. (#632)

[Go 1.26]: https://go.dev/doc/go1.26
[Go 1.25]: https://go.dev/doc/go1.25
[Go 1.27]: https://go.dev/doc/go1.27
XSAM added a commit to boekkooi-impossiblecloud/XSAM-otelsql that referenced this pull request Nov 14, 2026
Resolve conflicts with XSAM#643, XSAM#649, XSAM#651 and XSAM#652:
- recordSpanError takes *config (needed for SpanErrorAttributesGetter)
- otRows keeps pointer receivers and durationMetric, wrapped by
  wrapRowsColumnScanner
- durationMetric uses ErrorTypeAttribute instead of ErrorTypeAttributes

Co-Authored-By: Claude Fable 5.2 <[email protected]>
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.

sql.rows span don't correlate to sql.conn.query

1 participant