Skip to content

Conversation

@k-fish
Copy link
Member

@k-fish k-fish commented Dec 12, 2025

Add TRACE_ITEM_METRIC to valid event types for performance alerts. Update entity subscription to use TraceMetrics module for trace metric alerts.

Additionally, this adds more thorough validation for EAP queries, specifically for trace_metrics as they have a unique aggregate syntax (instead of count(column) it's almost always count(column, <metric tuple>)) that we need to enforce. This should work on both sides of old and new alerts so we're forwards and backwards compatible during the workflow switch over.

Add TRACE_ITEM_METRIC to valid event types for performance alerts.
Update entity subscription to use TraceMetrics module for trace metric alerts.
@github-actions github-actions bot added the Scope: Backend Automatically applied to PRs that change backend components label Dec 12, 2025
return trace_metric

except (InvalidSearchQuery, Exception) as e:
raise serializers.ValidationError({"aggregate": f"Invalid trace metrics aggregate: {e}"})

Check warning

Code scanning / CodeQL

Information exposure through an exception Medium

Stack trace information
flows to this location and may be exposed to an external user.

Copilot Autofix

AI 27 days ago

To fix the problem, we should ensure that exception messages containing potentially sensitive information are not exposed to users. Instead, we should log the exception details for server-side debugging and return a generic message in the validation error. This requires:

  • Catching and logging the full exception details internally (using Python's logging facilities),
  • Returning a user-safe generic error message (e.g., "Invalid trace metrics aggregate"), rather than directly exposing str(e).
    Specifically, in validate_trace_metrics_aggregate, modify the except block to log the exception and use a generic error message in the response.
    Additionally, ensure that the logging import (import logging) is in the file and a logger is instantiated (logger = logging.getLogger(__name__)).
    All changes are within src/sentry/search/eap/trace_metrics/validator.py.

Suggested changeset 1
src/sentry/search/eap/trace_metrics/validator.py

Autofix patch

Autofix patch
Run the following command in your local git repository to apply this patch
cat << 'EOF' | git apply
diff --git a/src/sentry/search/eap/trace_metrics/validator.py b/src/sentry/search/eap/trace_metrics/validator.py
--- a/src/sentry/search/eap/trace_metrics/validator.py
+++ b/src/sentry/search/eap/trace_metrics/validator.py
@@ -1,7 +1,9 @@
 from datetime import datetime, timedelta, timezone
 
 from rest_framework import serializers
+import logging
 
+logger = logging.getLogger(__name__)
 from sentry.exceptions import InvalidSearchQuery
 from sentry.search.eap.resolver import SearchResolver
 from sentry.search.eap.trace_metrics.config import TraceMetricsSearchResolverConfig
@@ -63,4 +64,5 @@
         return trace_metric
 
     except (InvalidSearchQuery, Exception) as e:
-        raise serializers.ValidationError({"aggregate": f"Invalid trace metrics aggregate: {e}"})
+        logger.exception("Error validating trace metrics aggregate: %s", aggregate)
+        raise serializers.ValidationError({"aggregate": "Invalid trace metrics aggregate"})
EOF
@@ -1,7 +1,9 @@
from datetime import datetime, timedelta, timezone

from rest_framework import serializers
import logging

logger = logging.getLogger(__name__)
from sentry.exceptions import InvalidSearchQuery
from sentry.search.eap.resolver import SearchResolver
from sentry.search.eap.trace_metrics.config import TraceMetricsSearchResolverConfig
@@ -63,4 +64,5 @@
return trace_metric

except (InvalidSearchQuery, Exception) as e:
raise serializers.ValidationError({"aggregate": f"Invalid trace metrics aggregate: {e}"})
logger.exception("Error validating trace metrics aggregate: %s", aggregate)
raise serializers.ValidationError({"aggregate": "Invalid trace metrics aggregate"})
Copilot is powered by AI and may make mistakes. Always verify output.
@codecov
Copy link

codecov bot commented Dec 12, 2025

Codecov Report

❌ Patch coverage is 97.46835% with 2 lines in your changes missing coverage. Please review.
✅ All tests successful. No failed tests found.

Files with missing lines Patch % Lines
src/sentry/explore/utils.py 75.00% 1 Missing ⚠️
src/sentry/incidents/metric_issue_detector.py 93.33% 1 Missing ⚠️
Additional details and impacted files
@@             Coverage Diff             @@
##           master   #104901      +/-   ##
===========================================
- Coverage   80.64%    80.56%   -0.08%     
===========================================
  Files        9335      9343       +8     
  Lines      403011    402073     -938     
  Branches    25695     25695              
===========================================
- Hits       325001    323944    -1057     
- Misses      77544     77663     +119     
  Partials      466       466              

@getsantry
Copy link
Contributor

getsantry bot commented Jan 3, 2026

This pull request has gone three weeks without activity. In another week, I will close it.

But! If you comment or otherwise update it, I will reset the clock, and if you add the label WIP, I will leave it alone unless WIP is removed ... forever!


"A weed is but an unloved flower." ― Ella Wheeler Wilcox 🥀

@getsantry getsantry bot added the Stale label Jan 3, 2026
@k-fish k-fish marked this pull request as ready for review January 6, 2026 16:13
@k-fish k-fish requested review from a team as code owners January 6, 2026 16:13
status_code=404,
**data,
)
assert "The requested resource does not exist" in str(resp.data["detail"])
Copy link
Contributor

Choose a reason for hiding this comment

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

Test passes for wrong reason due to missing feature flag

The test test_create_alert_rule_trace_metrics_feature_flag_disabled claims to test trace metrics feature flag behavior but is missing organizations:incidents in its feature flags. The endpoint checks for incidents first and returns 404 if disabled, so this test gets a 404 from the incidents check rather than the trace metrics check. The test would still pass even if the trace metrics feature flag check was accidentally removed from production code, providing false confidence in the feature flag validation.

Fix in Cursor Fix in Web

@getsantry getsantry bot removed the Stale label Jan 7, 2026
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