Skip to content

fix(heatmaps): very small y-axis values turning into engineering notation and throwing errors#116421

Merged
nikkikapadia merged 4 commits into
masterfrom
nikki/fix/heat-map-tooltip-formatting-error
May 28, 2026
Merged

fix(heatmaps): very small y-axis values turning into engineering notation and throwing errors#116421
nikkikapadia merged 4 commits into
masterfrom
nikki/fix/heat-map-tooltip-formatting-error

Conversation

@nikkikapadia
Copy link
Copy Markdown
Member

@nikkikapadia nikkikapadia commented May 28, 2026

I was having an issue with the heat maps endpoint for certain metrics. Seems like some of these metrics have very small numbers for their bounds and python was converting them to engineering notation (ex. 1.24e-4) when string formatting the query. We want to keep the decimal notation because that's what the queries will correctly take in and parse out.
Example:
image

anyways to fix it i've created a function to pre-format these strings so that they don't convert to eng notation.

@github-actions github-actions Bot added the Scope: Backend Automatically applied to PRs that change backend components label May 28, 2026
@nikkikapadia nikkikapadia marked this pull request as ready for review May 28, 2026 19:35
@nikkikapadia nikkikapadia requested review from a team as code owners May 28, 2026 19:35
Copy link
Copy Markdown
Member

@wmak wmak left a comment

Choose a reason for hiding this comment

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

small nits, but lgtm

HEATMAP_DATASETS = {TraceMetrics}


def _format_long_float(value: float) -> str:
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

nit: probably doesn't need to be a private function like this, I'd probably just make it a class method on the Endpoint Class

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

good point

Comment on lines +29 to +31
# Python's default float-to-string uses scientific notation for very small
# values (e.g. 8.527e-06), which the search query parser does not support.
# Fixed-point with 20 decimal places produces a plain decimal string the parser can handle.
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Suggested change
# Python's default float-to-string uses scientific notation for very small
# values (e.g. 8.527e-06), which the search query parser does not support.
# Fixed-point with 20 decimal places produces a plain decimal string the parser can handle.
"""
Python's default float-to-string uses scientific notation for very small
values (e.g. 8.527e-06), which the search query parser does not support.
Fixed-point with 20 decimal places produces a plain decimal string the parser can handle.
"""

Comment thread src/sentry/api/endpoints/organization_events_heatmap.py
Comment thread src/sentry/api/endpoints/organization_events_heatmap.py
Comment thread src/sentry/api/endpoints/organization_events_heatmap.py
Copy link
Copy Markdown
Contributor

@cursor cursor Bot left a comment

Choose a reason for hiding this comment

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

Cursor Bugbot has reviewed your changes and found 1 potential issue.

Fix All in Cursor

❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.

Reviewed by Cursor Bugbot for commit f72abe6. Configure here.

Fixed-point with 20 decimal places produces a plain decimal string the parser can handle.
"""
if "e" in str(value) or "E" in str(value):
return f"{value:.20f}".rstrip("0").rstrip(".")
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Precision loss silently rounds sub-1e-20 values to zero

Low Severity

_format_long_float uses :.20f formatting, which only provides 20 decimal places. For values smaller than ~5×10⁻²¹, the formatted result rounds to all zeros (0.00000000000000000000), and after rstrip("0").rstrip(".") the function silently returns '0' instead of the actual value. This would produce incorrect bucket boundaries in the query without any error signal.

Fix in Cursor Fix in Web

Reviewed by Cursor Bugbot for commit f72abe6. Configure here.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

welp echarts won't process decimals over 20 places anyways so

@nikkikapadia nikkikapadia merged commit 20d069b into master May 28, 2026
63 checks passed
@nikkikapadia nikkikapadia deleted the nikki/fix/heat-map-tooltip-formatting-error branch May 28, 2026 20:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Scope: Backend Automatically applied to PRs that change backend components

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants