From 646eeecb1bcc92500297c65735110937b4d239a2 Mon Sep 17 00:00:00 2001 From: Bob Weinand Date: Fri, 21 Jun 2024 12:28:07 +0200 Subject: [PATCH] Fix global priority sampling The global priority sampling was not recognized as explicit sampling and thus ignored. Signed-off-by: Bob Weinand --- ext/serializer.c | 4 +++- .../manual_global_override.phpt | 18 ++++++++++++++++++ 2 files changed, 21 insertions(+), 1 deletion(-) create mode 100644 tests/ext/priority_sampling/manual_global_override.phpt diff --git a/ext/serializer.c b/ext/serializer.c index 0fe39347ebe..1864a253cd2 100644 --- a/ext/serializer.c +++ b/ext/serializer.c @@ -958,7 +958,9 @@ void ddtrace_set_root_span_properties(ddtrace_root_span_data *span) { if (DDTRACE_G(propagated_priority_sampling) != DDTRACE_PRIORITY_SAMPLING_UNSET) { ZVAL_LONG(&span->property_propagated_sampling_priority, DDTRACE_G(propagated_priority_sampling)); } - ZVAL_LONG(&span->property_sampling_priority, DDTRACE_G(default_priority_sampling)); + if (DDTRACE_G(default_priority_sampling) != DDTRACE_PRIORITY_SAMPLING_UNKNOWN) { + ddtrace_set_priority_sampling_on_span(span, DDTRACE_G(default_priority_sampling), DD_MECHANISM_MANUAL); + } ddtrace_integration *web_integration = &ddtrace_integrations[DDTRACE_INTEGRATION_WEB]; if (get_DD_TRACE_ANALYTICS_ENABLED() || web_integration->is_analytics_enabled()) { diff --git a/tests/ext/priority_sampling/manual_global_override.phpt b/tests/ext/priority_sampling/manual_global_override.phpt new file mode 100644 index 00000000000..8546cb333ea --- /dev/null +++ b/tests/ext/priority_sampling/manual_global_override.phpt @@ -0,0 +1,18 @@ +--TEST-- +Global explicitly set priority sampling must be respected +--ENV-- +DD_TRACE_SAMPLE_RATE=0 +DD_TRACE_GENERATE_ROOT_SPAN=0 +--FILE-- +meta["_dd.p.dm"]}\n"; +?> +--EXPECT-- +Sampling: 1 +_dd.p.dm = -4