Skip to content

Use semconv-recommended bucket boundaries for db.client.operation.duration - #632

Merged
XSAM merged 2 commits into
XSAM:mainfrom
kitosforos:fix/db-client-duration-histogram-boundaries
Aug 12, 2026
Merged

XSAM merged 2 commits into
XSAM:mainfrom
kitosforos:fix/db-client-duration-histogram-boundaries

Conversation

@kitosforos

Copy link
Copy Markdown
Contributor

Fixes #631

Why

The db.client.operation.duration histogram is created without explicit bucket boundaries, so the OTel SDK falls back to its generic defaults:

0, 5, 10, 25, 50, 75, 100, 250, 500, 750, 1000, 2500, 5000, 7500, 10000

These were designed for millisecond values, but this metric's unit is seconds — typical database operations (1–50 ms) all land in the first bucket (le=5.0), so histogram_quantile returns the same constant value at every percentile (p50 = p95 = p99).

See open-telemetry/opentelemetry-specification#3525 for the OTel-wide background: the TC decided to keep the SDK defaults and expects instrumentation libraries to pass advisory boundaries instead.

What

Pass the bucket boundaries recommended by the OTel semantic conventions for db.client.operation.duration:

This metric SHOULD be specified with ExplicitBucketBoundaries of [ 0.001, 0.005, 0.01, 0.05, 0.1, 0.5, 1, 5, 10 ].

Before:

0, 5, 10, 25, 50, 75, 100, 250, 500, 750, 1000, 2500, 5000, 7500, 10000

After:

0.001, 0.005, 0.01, 0.05, 0.1, 0.5, 1, 5, 10

metric.WithExplicitBucketBoundaries comes from go.opentelemetry.io/otel/metric, already a dependency. Users can still override the boundaries with metric Views since these are advisory.

Also adds a test asserting the collected histogram uses the recommended boundaries, and updates the expected metric data in utils_test.go.

🤖 Generated with Claude Code

@kitosforos
kitosforos requested a review from XSAM as a code owner June 12, 2026 08:25
…ation

The duration histogram was created without explicit bucket boundaries,
falling back to the SDK defaults (0, 5, 10, 25, ... 10000) which are
meant for milliseconds. Since the metric unit is seconds, virtually all
database operations land in the first bucket, making percentile queries
useless.

Pass the boundaries recommended by the OTel semantic conventions for
db.client.operation.duration.

Co-Authored-By: Claude Fable 5 <[email protected]>
@kitosforos
kitosforos force-pushed the fix/db-client-duration-histogram-boundaries branch from 1681037 to 4a17a3c Compare June 12, 2026 08:26
@XSAM XSAM added this to the v0.44.0 milestone Jul 12, 2026
@XSAM
XSAM requested a balanced review from Copilot August 12, 2026 01:28

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

Configures database operation duration histograms with OTel-recommended boundaries for meaningful latency percentiles.

Changes:

  • Adds explicit duration bucket boundaries.
  • Updates metric expectations and adds a focused boundary test.
  • Documents the fix in the changelog.

Reviewed changes

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

File Description
instruments.go Configures recommended histogram boundaries.
instruments_test.go Verifies collected boundaries.
utils_test.go Updates expected histogram data.
CHANGELOG.md Records the corrected behavior.

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

@codecov

codecov Bot commented Aug 12, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 75.00000% with 1 line in your changes missing coverage. Please review.
✅ Project coverage is 85.6%. Comparing base (9648cf1) to head (e838504).

Files with missing lines Patch % Lines
instruments.go 75.0% 0 Missing and 1 partial ⚠️
Additional details and impacted files
@@          Coverage Diff          @@
##            main    #632   +/-   ##
=====================================
  Coverage   85.5%   85.6%           
=====================================
  Files         15      15           
  Lines        694     697    +3     
=====================================
+ Hits         594     597    +3     
  Misses        74      74           
  Partials      26      26           

☔ 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 commented Aug 12, 2026

Copy link
Copy Markdown
Owner

@kitosforos Thanks for your contribution!

@XSAM
XSAM merged commit 6dc0d5f into XSAM:main Aug 12, 2026
14 of 15 checks passed
@gaiaz-iusipov

Copy link
Copy Markdown
Contributor

The changelog entry was added incorrectly in this PR.

@XSAM

XSAM commented Aug 12, 2026

Copy link
Copy Markdown
Owner

The changelog entry was added incorrectly in this PR.

@gaiaz-iusipov Thanks for the notify. Time to enforce the changelog protection.

@XSAM XSAM mentioned this pull request Aug 12, 2026
XSAM added a commit that referenced this pull request Aug 12, 2026
XSAM added a commit that referenced this pull request Aug 12, 2026
Per #632 (comment)

This PR adds a new action in CI to protect released sections in the
changelog from being changed. It compares the released sections in the
changelog from the base branch to the current PR. It fails if a change
happens.

Apply "Unlock Released Changelog" to bypass this check when doing a new
release.

Prior art: open-telemetry/opentelemetry-go#5560
@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
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.

db.client.operation.duration histogram uses wrong default bucket boundaries (all observations fall into first bucket)

4 participants