Skip to content

Commit f73705c

Browse files
committed
fix(dynamic-sampling): Rename project_id to avoid built-in column collision
In Sentry Explore Logs, `project_id` resolves to the built-in `sentry.project_id` column (the DSN project, always 1) instead of the custom attribute from the log `extra` dict. This made it impossible to filter or group by the actual dynamic sampling project ID. Rename `project_id` to `dynamic_sampling_project_id` in all three logger.info calls, consistent with what was already done for the metrics tags in 8c290f5. Also switch the debug metrics from gauge to distribution for better aggregation support.
1 parent d85a9f2 commit f73705c

2 files changed

Lines changed: 12 additions & 12 deletions

File tree

src/sentry/dynamic_sampling/per_org/calculations.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ def compare_rebalanced_projects_with_cache(
116116
"dynamic_sampling.per_org.project_balancing_comparison",
117117
extra={
118118
"org_id": config.organization.id,
119-
"project_id": project_id,
119+
"dynamic_sampling_project_id": project_id,
120120
"generic_metrics_sample_rate": generic_metrics_sample_rate,
121121
"eap_sample_rate": eap_sample_rate,
122122
"relative_deviation": get_relative_deviation(
@@ -149,27 +149,27 @@ def _emit_project_balancing_debug_metrics(
149149
eap_volume_without_extrapolation: float | None,
150150
) -> None:
151151
tags = {"org_id": str(org_id), "dynamic_sampling_project_id": str(project_id)}
152-
metrics.gauge(
152+
metrics.distribution(
153153
f"{PROJECT_BALANCING_DEBUG_METRIC_PREFIX}.eap_sample_rate",
154154
eap_sample_rate,
155155
sample_rate=1.0,
156156
tags=tags,
157157
)
158158
if generic_metrics_sample_rate is not None:
159-
metrics.gauge(
159+
metrics.distribution(
160160
f"{PROJECT_BALANCING_DEBUG_METRIC_PREFIX}.generic_metrics_sample_rate",
161161
generic_metrics_sample_rate,
162162
sample_rate=1.0,
163163
tags=tags,
164164
)
165-
metrics.gauge(
165+
metrics.distribution(
166166
f"{PROJECT_BALANCING_DEBUG_METRIC_PREFIX}.eap_volume",
167167
eap_volume,
168168
sample_rate=1.0,
169169
tags=tags,
170170
)
171171
if eap_volume_without_extrapolation is not None:
172-
metrics.gauge(
172+
metrics.distribution(
173173
f"{PROJECT_BALANCING_DEBUG_METRIC_PREFIX}.eap_volume_without_extrapolation",
174174
eap_volume_without_extrapolation,
175175
sample_rate=1.0,
@@ -294,7 +294,7 @@ def compare_rebalanced_transactions_with_cache(
294294
"dynamic_sampling.per_org.transaction_balancing_implicit_comparison",
295295
extra={
296296
"org_id": config.organization.id,
297-
"project_id": project_id,
297+
"dynamic_sampling_project_id": project_id,
298298
"generic_metrics_implicit_rate": generic_metrics_implicit_rate,
299299
"eap_implicit_rate": eap_implicit_rate,
300300
"relative_deviation": get_relative_deviation(
@@ -315,7 +315,7 @@ def compare_rebalanced_transactions_with_cache(
315315
"dynamic_sampling.per_org.transaction_balancing_comparison",
316316
extra={
317317
"org_id": config.organization.id,
318-
"project_id": project_id,
318+
"dynamic_sampling_project_id": project_id,
319319
"transaction": transaction,
320320
"generic_metrics_sample_rate": generic_metrics_rate,
321321
"eap_sample_rate": item.new_sample_rate,

tests/sentry/dynamic_sampling/per_org/test_calculations.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ def test_compare_rebalanced_projects_with_cache_logs_per_project(self) -> None:
102102
assert [call.kwargs["extra"] for call in logger_info.call_args_list] == [
103103
{
104104
"org_id": org.id,
105-
"project_id": project_with_volume.id,
105+
"dynamic_sampling_project_id": project_with_volume.id,
106106
"generic_metrics_sample_rate": 0.2,
107107
"eap_sample_rate": 0.25,
108108
"relative_deviation": pytest.approx(0.2),
@@ -112,7 +112,7 @@ def test_compare_rebalanced_projects_with_cache_logs_per_project(self) -> None:
112112
},
113113
{
114114
"org_id": org.id,
115-
"project_id": project_without_volume.id,
115+
"dynamic_sampling_project_id": project_without_volume.id,
116116
"generic_metrics_sample_rate": 0.96,
117117
"eap_sample_rate": 1.0,
118118
"relative_deviation": pytest.approx(0.04),
@@ -288,15 +288,15 @@ def test_compare_rebalanced_transactions_with_cache_logs_per_transaction(self) -
288288
assert extras == [
289289
{
290290
"org_id": org.id,
291-
"project_id": project.id,
291+
"dynamic_sampling_project_id": project.id,
292292
"generic_metrics_implicit_rate": 0.45,
293293
"eap_implicit_rate": 0.5,
294294
"relative_deviation": pytest.approx(0.1),
295295
"is_equal": False,
296296
},
297297
{
298298
"org_id": org.id,
299-
"project_id": project.id,
299+
"dynamic_sampling_project_id": project.id,
300300
"transaction": "checkout",
301301
"generic_metrics_sample_rate": 0.2,
302302
"eap_sample_rate": 0.25,
@@ -305,7 +305,7 @@ def test_compare_rebalanced_transactions_with_cache_logs_per_transaction(self) -
305305
},
306306
{
307307
"org_id": org.id,
308-
"project_id": project.id,
308+
"dynamic_sampling_project_id": project.id,
309309
"transaction": "cart",
310310
"generic_metrics_sample_rate": 1.0,
311311
"eap_sample_rate": 0.96,

0 commit comments

Comments
 (0)