Skip to content

Commit 3952e69

Browse files
committed
Amend dm and priority on asm events
1 parent 76b4871 commit 3952e69

File tree

11 files changed

+15
-11
lines changed

11 files changed

+15
-11
lines changed

Diff for: appsec/src/extension/configuration.h

+1
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ extern bool runtime_config_first_init;
6969
CONFIG(STRING, DD_APPSEC_HTTP_BLOCKED_TEMPLATE_HTML, "") \
7070
CONFIG(STRING, DD_APPSEC_HTTP_BLOCKED_TEMPLATE_JSON, "") \
7171
CONFIG(DOUBLE, DD_API_SECURITY_REQUEST_SAMPLE_RATE, "0.1", .ini_change = zai_config_system_ini_change) \
72+
CONFIG(BOOL, DD_EXPERIMENTAL_APPSEC_STANDALONE_ENABLED, "false") \
7273
CONFIG(BOOL, DD_API_SECURITY_ENABLED, "true", .ini_change = zai_config_system_ini_change)
7374
// clang-format on
7475

Diff for: appsec/src/extension/ddtrace.h

+1
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ enum dd_sampling_mechanism {
2020
DD_MECHANISM_REMOTE_RATE = 2,
2121
DD_MECHANISM_RULE = 3,
2222
DD_MECHANISM_MANUAL = 4,
23+
DD_MECHANISM_ASM = 5,
2324
};
2425

2526
typedef zend_object root_span_t;

Diff for: appsec/src/extension/tags.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -352,7 +352,7 @@ void dd_tags_add_tags(
352352

353353
if (_force_keep) {
354354
dd_trace_set_priority_sampling_on_span_zobj(
355-
span, PRIORITY_SAMPLING_USER_KEEP, DD_MECHANISM_MANUAL);
355+
span, PRIORITY_SAMPLING_USER_KEEP, get_DD_EXPERIMENTAL_APPSEC_STANDALONE_ENABLED() ? DD_MECHANISM_ASM: DD_MECHANISM_MANUAL);
356356
mlog(dd_log_debug, "Updated sampling priority to user_keep");
357357
}
358358

Diff for: appsec/tests/extension/client_init_record_span_tags.phpt

+1-2
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ Array
8686
(
8787
[_dd.appsec.json] => {"triggers":[{"found":"attack"},{"another":"attack"},{"yet another":"attack"}]}
8888
[_dd.p.appsec] => 1
89-
[_dd.p.dm] => -0
89+
[_dd.p.dm] => -5
9090
[_dd.p.tid] => %s
9191
[_dd.runtime_family] => php
9292
[appsec.event] => true
@@ -107,7 +107,6 @@ Array
107107
[metric_1] => 2
108108
[metric_2] => 10
109109
[_dd.appsec.enabled] => 1
110-
[_dd.agent_psr] => 1
111110
[_sampling_priority_v1] => 1
112111
[php.compilation.total_time_ms] => %f
113112
[php.memory.peak_usage_bytes] => %f

Diff for: appsec/tests/extension/rinit_record_span_tags.phpt

+1-2
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ Array
8181
(
8282
[_dd.appsec.json] => {"triggers":[{"found":"attack"},{"another":"attack"},{"yet another":"attack"}]}
8383
[_dd.p.appsec] => 1
84-
[_dd.p.dm] => -0
84+
[_dd.p.dm] => -5
8585
[_dd.p.tid] => %s
8686
[_dd.runtime_family] => php
8787
[appsec.event] => true
@@ -100,7 +100,6 @@ Array
100100
[%s] => %d
101101
[rshutdown_metric] => 2.1
102102
[_dd.appsec.enabled] => 1
103-
[_dd.agent_psr] => 1
104103
[_sampling_priority_v1] => 1
105104
[php.compilation.total_time_ms] => %f
106105
[php.memory.peak_usage_bytes] => %f

Diff for: config.m4

+1-1
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,7 @@ if test "$PHP_DDTRACE" != "no"; then
163163
DD_TRACE_PHP_SOURCES="$EXTRA_PHP_SOURCES \
164164
ext/ddtrace.c \
165165
ext/agent_info.c \
166+
ext/asm_event.c \
166167
ext/arrays.c \
167168
ext/auto_flush.c \
168169
ext/autoload_php_files.c \
@@ -188,7 +189,6 @@ if test "$PHP_DDTRACE" != "no"; then
188189
ext/integrations/exec_integration.c \
189190
ext/integrations/integrations.c \
190191
ext/ip_extraction.c \
191-
ext/ddappsec.c \
192192
ext/standalone_limiter.c \
193193
ext/live_debugger.c \
194194
ext/logging.c \

Diff for: config.w32

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ if (PHP_DDTRACE != 'no') {
1717

1818
var DDTRACE_EXT_SOURCES = "agent_info.c";
1919
DDTRACE_EXT_SOURCES += " arrays.c";
20+
DDTRACE_EXT_SOURCES += " asm_event.c";
2021
DDTRACE_EXT_SOURCES += " auto_flush.c";
2122
DDTRACE_EXT_SOURCES += " autoload_php_files.c";
2223
DDTRACE_EXT_SOURCES += " collect_backtrace.c";
@@ -36,7 +37,6 @@ if (PHP_DDTRACE != 'no') {
3637
DDTRACE_EXT_SOURCES += " handlers_internal.c";
3738
DDTRACE_EXT_SOURCES += " handlers_pcntl.c";
3839
DDTRACE_EXT_SOURCES += " ip_extraction.c";
39-
DDTRACE_EXT_SOURCES += " ddappsec.c";
4040
DDTRACE_EXT_SOURCES += " standalone_limiter.c";
4141
DDTRACE_EXT_SOURCES += " live_debugger.c";
4242
DDTRACE_EXT_SOURCES += " logging.c";

Diff for: ext/asm_event.c

+3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
#include "asm_event.h"
22
#include "ddtrace.h"
3+
#include "priority_sampling/priority_sampling.h"
34
#include "tracer_tag_propagation/tracer_tag_propagation.h"
45

56
ZEND_EXTERN_MODULE_GLOBALS(ddtrace);
@@ -22,6 +23,8 @@ DDTRACE_PUBLIC void ddtrace_emit_asm_event() {
2223
zval _1_zval;
2324
ZVAL_STR(&_1_zval, _1_zstr);
2425
ddtrace_add_propagated_tag(_dd_tag_p_appsec_zstr, &_1_zval);
26+
27+
ddtrace_set_priority_sampling_on_root(PRIORITY_SAMPLING_AUTO_KEEP, DD_MECHANISM_ASM);
2528
}
2629

2730
PHP_FUNCTION(DDTrace_Testing_emit_asm_event) {

Diff for: ext/priority_sampling/priority_sampling.h

+1
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ enum dd_sampling_mechanism {
1818
DD_MECHANISM_REMOTE_RATE = 2,
1919
DD_MECHANISM_RULE = 3,
2020
DD_MECHANISM_MANUAL = 4,
21+
DD_MECHANISM_ASM = 5,
2122
DD_MECHANISM_REMOTE_USER_RULE = 11,
2223
DD_MECHANISM_REMOTE_DYNAMIC_RULE = 12,
2324
};

Diff for: tests/ext/background-sender/agent_sampling-standalone-asm_02.phpt

+3-3
Original file line numberDiff line numberDiff line change
@@ -47,9 +47,9 @@ echo "This call also has the same sample rate: {$get_sampling()}\n";
4747
?>
4848
--EXPECTF--
4949
[ddtrace] [info] Flushing trace of size 1 to send-queue for http://request-replayer:80
50-
First call it is used as heartbeat: 1
50+
First call it is used as heartbeat: 2
5151
[ddtrace] [info] Flushing trace of size 1 to send-queue for http://request-replayer:80
52-
This call has the same sample rate: 1
52+
This call has the same sample rate: 2
5353
[ddtrace] [info] Flushing trace of size 1 to send-queue for http://request-replayer:80
54-
This call also has the same sample rate: 1
54+
This call also has the same sample rate: 2
5555
[ddtrace] [info] No finished traces to be sent to the agent

Diff for: tests/ext/integrations/curl/distributed_tracing_curl_propagate_asm_event.phpt

+1-1
Original file line numberDiff line numberDiff line change
@@ -37,4 +37,4 @@ dt_dump_headers_from_httpbin(query_headers(), ['x-datadog-tags']);
3737

3838
?>
3939
--EXPECT--
40-
x-datadog-tags: _dd.p.appsec=1,_dd.p.dm=-4
40+
x-datadog-tags: _dd.p.appsec=1,_dd.p.dm=-5

0 commit comments

Comments
 (0)