Skip to content

fix(otel): cents-scale bucket boundaries for session.cost.total histogram#59

Open
TestardR wants to merge 1 commit into
DEVtheOPS:mainfrom
TestardR:fix/cost-histogram-buckets
Open

fix(otel): cents-scale bucket boundaries for session.cost.total histogram#59
TestardR wants to merge 1 commit into
DEVtheOPS:mainfrom
TestardR:fix/cost-histogram-buckets

Conversation

@TestardR
Copy link
Copy Markdown

@TestardR TestardR commented May 25, 2026

Problem

opencode.session.cost.total is a Histogram registered without explicit bucket boundaries, so the OTel JS SDK applies defaults [0, 5, 10, 25, 50, 75, 100, 250, 500, 750, 1000, 2500, 5000, 7500, 10000] (USD-scale).

Real-world session costs are typically under $1, so every observation lands in the le=5 bucket. P50/P95 panels return 0 because the histogram can't resolve sub-$5 percentiles.

Fix

Add advice.explicitBucketBoundaries with cents-scale boundaries: [0.01, 0.05, 0.10, 0.25, 0.50, 1.00, 2.50, 5.00, 10.00, 25.00].

Evidence

ClickHouse bucket distribution against a live SigNoz (all 267 samples in le=5):

bucket | count
-------+------
0      | 0
5      | 267
10     | 267
25     | 267
...
inf    | 267

Bucket change affects new data only; existing histograms keep their old boundaries.


Companion PR: #58

Summary by CodeRabbit

  • New Features
    • Enhanced session cost tracking with improved cost bucket granularity for more precise reporting.

Review Change Stack

…istogram

The session.cost.total histogram was using OTel SDK default bucket boundaries

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

which are USD-scale. Since typical opencode session costs are sub-dollar, 100%

of samples land in the le=5 bucket and P50/P95 panels in SigNoz return empty.

Add advice.explicitBucketBoundaries with cents-scale boundaries:

[0.01, 0.05, 0.10, 0.25, 0.50, 1.00, 2.50, 5.00, 10.00, 25.00]

These cover the realistic distribution of per-session costs and produce

meaningful percentile values in downstream observability tooling.
@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented May 25, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 9010f1c2-6fd8-421b-aa46-6efab7552772

📥 Commits

Reviewing files that changed from the base of the PR and between e50a9ed and b5d4185.

📒 Files selected for processing (1)
  • src/otel.ts

📝 Walkthrough

Walkthrough

The PR updates the observability telemetry configuration by adding explicit bucket boundaries to the sessionCostGauge histogram instrument. The histogram now publishes cost-per-session metrics using a predefined set of USD cost buckets (0.01 through 25.00) for improved metric granularity.

Changes

Session cost histogram configuration

Layer / File(s) Summary
Configure explicit USD cost bucket boundaries
src/otel.ts
The sessionCostGauge histogram instrument's advice.explicitBucketBoundaries is set with fixed USD cost thresholds (0.01–25.00) to define histogram bucket boundaries for cost-per-session metric export.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~5 minutes

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately summarizes the main change: adding cents-scale bucket boundaries to the session.cost.total histogram in the OpenTelemetry configuration.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

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.

1 participant