Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(metrics): Add an option to extrapolate tx and span metrics #73911

Merged
merged 6 commits into from
Jul 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions src/sentry/options/defaults.py
Original file line number Diff line number Diff line change
Expand Up @@ -1471,6 +1471,18 @@
flags=FLAG_AUTOMATOR_MODIFIABLE,
)

register(
"sentry-metrics.extrapolation.enable_transactions",
default=False,
flags=FLAG_AUTOMATOR_MODIFIABLE,
)

register(
"sentry-metrics.extrapolation.enable_spans",
default=False,
flags=FLAG_AUTOMATOR_MODIFIABLE,
)

register(
"sentry-metrics.extrapolation.duplication-limit",
default=0,
Expand Down
16 changes: 15 additions & 1 deletion src/sentry/relay/config/metric_extraction.py
Original file line number Diff line number Diff line change
Expand Up @@ -149,10 +149,24 @@ def get_extrapolation_config(project: Project) -> MetricExtrapolationConfig | No
# Extrapolation applies to extracted metrics. This enables extrapolation for
# the entire `custom` namespace, but this does not extrapolate old custom
# metrics sent from the SDK directly.
return {
config: MetricExtrapolationConfig = {
"include": ["?:custom/*"],
"exclude": [],
}

if options.get("sentry-metrics.extrapolation.enable_transactions"):
config["include"] += ["?:transactions/*"]
config["exclude"] += [
"c:transactions/usage@none", # stats
"c:transactions/count_per_root_project@none", # dynamic sampling
]

if options.get("sentry-metrics.extrapolation.enable_spans"):
config["include"] += ["?:spans/*"]
config["exclude"] += ["c:spans/usage@none"] # stats

return config


def get_on_demand_metric_specs(
timeout: TimeChecker, project: Project
Expand Down
41 changes: 41 additions & 0 deletions tests/sentry/relay/config/test_metric_extraction.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

import pytest
from django.utils import timezone
from sentry_relay.processing import normalize_project_config

from sentry.incidents.models.alert_rule import AlertRule, AlertRuleProjects
from sentry.models.dashboard_widget import DashboardWidgetQuery, DashboardWidgetQueryOnDemand
Expand Down Expand Up @@ -2239,3 +2240,43 @@ def test_get_metric_extraction_config_span_attributes_above_max_limit(

assert config
assert len(config["metrics"]) == 1


@django_db_all
@override_options(
{
"sentry-metrics.extrapolation.enable_transactions": True,
"sentry-metrics.extrapolation.enable_spans": True,
}
)
def test_get_metric_extrapolation_config(default_project: Project) -> None:
default_project.update_option("sentry:extrapolate_metrics", True)

# Create a dummy extraction rule to ensure there is at least one
# metric. Otherwise, the spec will be empty.
attr_config = {
"spanAttribute": "span.duration",
"aggregates": ["count"],
"unit": "none",
"tags": [],
"conditions": [{"id": 1, "value": "bar:baz"}],
}
SpanAttributeExtractionRuleConfig.from_dict(attr_config, 1, default_project)

with Feature(
["organizations:metrics-extrapolation", "organizations:custom-metrics-extraction-rule"]
):
config = get_metric_extraction_config(TimeChecker(timedelta(seconds=0)), default_project)

assert config and config["extrapolate"]

# Generate boilerplate around minimal project config:
project_config = {
"allowedDomains": ["*"],
"piiConfig": None,
"trustedRelays": [],
"metricExtraction": config,
}

normalized = normalize_project_config(project_config)["metricExtraction"]["extrapolate"]
assert normalized == config["extrapolate"]
Loading