Repository navigation
Add WithSpanErrorAttributesGetter to set error attributes on spans - #651
Merged
Merged
Conversation
Semantic conventions define db.response.status_code as a span attribute, but the only place the driver error is visible is after the operation completes, and the existing AttributesGetter runs at span creation with no error. Metrics already have InstrumentErrorAttributesGetter for this purpose; spans had no equivalent hook. Add SpanErrorAttributesGetter, invoked from recordSpanError for every non-nil error on a recording span, with the returned attributes set on the span. It shares the func(error) []attribute.KeyValue shape with the metrics getter so one function can serve both signals. The getter runs regardless of SpanOptions.RecordError and DisableErrSkip so response details can be attached even when the error is not recorded as a span error. recordSpanError now takes the full config instead of SpanOptions, and no longer calls RecordError when the error is nil. Closes #377 Co-Authored-By: Claude Fable 5.1 <[email protected]>
Co-Authored-By: Claude Fable 5.1 <[email protected]>
XSAM
marked this pull request as ready for review
September 5, 2026 00:33
…377-a3be31 # Conflicts: # CHANGELOG.md
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #651 +/- ##
=====================================
Coverage 89.4% 89.4%
=====================================
Files 15 15
Lines 576 579 +3
=====================================
+ Hits 515 518 +3
Misses 61 61 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
The .tools cache was keyed only on the tools module hash, so bumping the
CI Go version reused a golangci-lint binary built by the previous Go.
Its embedded type checker then failed on the newer standard library
("method must have no type parameters" in math/rand/v2), breaking the
lint job on main and every PR. The compatibility matrix also shared one
cache across three Go versions. Keying the cache on the installed Go
version forces a rebuild whenever the toolchain changes.
Co-Authored-By: Claude Fable 5.1 <[email protected]>
Merged
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]>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #377
What changed
SpanErrorAttributesGettertype andWithSpanErrorAttributesGetteroption. The getter receives the error returned by the driver and its attributes are set on the span.recordSpanErrornow takes the fullconfiginstead ofSpanOptions, calls the getter for every non-nil error on a recording span, and no longer invokesSpanOptions.RecordErrorwhen the error is nil.RecordError/DisableErrSkip, nil span, and non-recording span.Why
Semantic conventions define
db.response.status_codeas a span attribute, but the only place a driver status code is visible indatabase/sqlis the returned error. The existingAttributesGetterruns at span creation with no error, andSpanOptions.RecordErrorsees the error but has no access to the span. Metrics already haveInstrumentErrorAttributesGetterfor exactly this purpose; spans had no equivalent hook.Reviewer notes
func(error) []attribute.KeyValueshape withInstrumentErrorAttributesGetter, so one function can be passed to both options.RecordErrorandDisableErrSkip, matching how the metrics getter ignoresDisableSkipErrMeasurement. A response status code is still useful on a span even when the error is deliberately not recorded as a span error. This is documented on the option.configby value torecordSpanErrorcopies a larger struct thanSpanOptionsdid. Happy to switch to a pointer if preferred.🤖 Generated with Claude Code