Skip to content

feat(metrics): Add equation support to tracemetrics#112609

Merged
wmak merged 2 commits intomasterfrom
wmak/feat/add-equation-support-to-tracemetrics
Apr 10, 2026
Merged

feat(metrics): Add equation support to tracemetrics#112609
wmak merged 2 commits intomasterfrom
wmak/feat/add-equation-support-to-tracemetrics

Conversation

@wmak
Copy link
Copy Markdown
Member

@wmak wmak commented Apr 9, 2026

  • This adds equation support to the tracemetrics dataset
  • I'm really not sure what the extra_conditions are doing here, they add a top level condition on the metric details, but we're already adding them per-aggregate anyways? I'm just going to leave this alone (but add equation support) for now and move on

- This adds equation support to the tracemetrics dataset
- I'm really not sure what the extra_conditions are doing here, they add
  a top level condition on the metric details, but we're already adding
  them per-aggregate anyways? I'm just going to leave this alone (but
  add equation support) for now and move on
@wmak wmak requested review from a team as code owners April 9, 2026 19:18
@github-actions github-actions bot added the Scope: Backend Automatically applied to PRs that change backend components label Apr 9, 2026
Comment on lines +57 to +60
for equation in equations:
_, _, terms = parse_arithmetic(equation)
for term in terms:
columns.add(term)
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.

Bug: The parse_arithmetic function is called with a hardcoded allowlist that omits trace-metric-specific functions like per_second, causing validation to fail for valid equations.
Severity: HIGH

Suggested Fix

When calling parse_arithmetic in src/sentry/search/eap/trace_metrics/config.py, provide an extended function_allowlist that includes the trace-metric-specific functions (per_second, per_minute, per_second_if, per_minute_if) in addition to the default ones.

Prompt for AI Agent
Review the code at the location below. A potential bug has been identified by an AI
agent.
Verify if this is a real issue. If it is, propose a fix; if not, explain why it's not
valid.

Location: src/sentry/search/eap/trace_metrics/config.py#L57-L60

Potential issue: The code for handling equations in trace metrics calls
`parse_arithmetic` to validate and extract function names. However, the underlying
`ArithmeticVisitor` uses a hardcoded `function_allowlist` that does not include
trace-metric-specific functions like `per_second`, `per_minute`, `per_second_if`, and
`per_minute_if`. As a result, any attempt to use these functions in an equation will
cause an `ArithmeticValidationError`, preventing the feature from working as intended
for these specific, but essential, functions. The provided tests do not cover these
functions, only using `count_if` which is already in the allowlist.

Did we get this right? 👍 / 👎 to inform future reviews.

Copy link
Copy Markdown
Contributor

@manessaraj manessaraj left a comment

Choose a reason for hiding this comment

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

Looks good

@wmak wmak merged commit 24a0acd into master Apr 10, 2026
56 checks passed
@wmak wmak deleted the wmak/feat/add-equation-support-to-tracemetrics branch April 10, 2026 16:08
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