Skip to content

perf: add ErrorTypeAttribute to eliminate extra slice allocation - #643

Merged
XSAM merged 8 commits into
XSAM:mainfrom
gaiaz-iusipov:error-type-attribute
Aug 12, 2026
Merged

XSAM merged 8 commits into
XSAM:mainfrom
gaiaz-iusipov:error-type-attribute

Conversation

@gaiaz-iusipov

@gaiaz-iusipov gaiaz-iusipov commented Aug 2, 2026 •

Copy link
Copy Markdown
Contributor
goos: darwin
goarch: arm64
pkg: github.com/XSAM/otelsql
cpu: Apple M3 Max
                                                      │   old.txt   │              new.txt               │
                                                      │   sec/op    │   sec/op     vs base               │
RecordMetric/InstrumentAttributesGetter/with_error-14   953.3n ± 1%   911.0n ± 1%  -4.43% (p=0.002 n=10)

                                                      │   old.txt    │               new.txt               │
                                                      │     B/op     │     B/op      vs base               │
RecordMetric/InstrumentAttributesGetter/with_error-14   2.688Ki ± 0%   2.625Ki ± 0%  -2.33% (p=0.000 n=10)

                                                      │  old.txt   │              new.txt               │
                                                      │ allocs/op  │ allocs/op   vs base                │
RecordMetric/InstrumentAttributesGetter/with_error-14   4.000 ± 0%   3.000 ± 0%  -25.00% (p=0.000 n=10)

@gaiaz-iusipov
gaiaz-iusipov requested a review from XSAM as a code owner August 2, 2026 15:27
@codecov

codecov Bot commented Aug 2, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 85.7%. Comparing base (e00160c) to head (9b40a60).

Additional details and impacted files
@@           Coverage Diff           @@
##            main    #643     +/-   ##
=======================================
+ Coverage   85.6%   85.7%   +0.1%     
=======================================
  Files         15      15             
  Lines        697     690      -7     
=======================================
- Hits         597     592      -5     
+ Misses        74      73      -1     
+ Partials      26      25      -1     

☔ 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.

@gaiaz-iusipov

Copy link
Copy Markdown
Contributor Author

How about removing this check in this PR?

if value == "" {
    return semconv.ErrorTypeOther
}

Since, as far as I can tell, it's unreachable.

@XSAM

XSAM commented Aug 12, 2026

Copy link
Copy Markdown
Owner

Hey @gaiaz-iusipov, thanks for the PR. Could you please post your benchstat old.txt new.txt results to show the optimized allocation?

@gaiaz-iusipov

Copy link
Copy Markdown
Contributor Author

@XSAM I added the benchmark and also fixed the changelog, since an entry was added to the wrong section today.

@XSAM
XSAM requested a balanced review from Copilot August 12, 2026 17:08

Copilot AI 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.

Pull request overview

Optimizes error metric attribute creation by eliminating an intermediate slice allocation.

Changes:

  • Return a single error-type attribute and append it directly.
  • Add benchmark coverage for error recording.
  • Update tests and unreleased changelog entries.

Reviewed changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated no comments.

Show a summary per file
File Description
utils.go Appends the error attribute directly.
utils_bench_test.go Benchmarks error metric recording.
internal/semconv/attributes.go Replaces slice-returning error conversion.
internal/semconv/attributes_test.go Updates tests for the singular attribute API.
CHANGELOG.md Documents the optimization and corrects release placement.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

@XSAM XSAM left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

LGTM. @gaiaz-iusipov, thanks for your contribution!

@XSAM
XSAM merged commit 101adfe into XSAM:main Aug 12, 2026
15 checks passed
@XSAM XSAM added this to the v0.44.0 milestone Aug 12, 2026
@gaiaz-iusipov
gaiaz-iusipov deleted the error-type-attribute branch August 13, 2026 15:56
@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.

3 participants