Skip to content

Commit

Permalink
Replace DD_EXPERIMENTAL_APPSEC_STANDALONE_ENABLED with DD_APM_TRACING…
Browse files Browse the repository at this point in the history
…_ENABLED
  • Loading branch information
estringana committed Feb 11, 2025
1 parent c199419 commit 479b78f
Show file tree
Hide file tree
Showing 18 changed files with 24 additions and 27 deletions.
2 changes: 1 addition & 1 deletion appsec/src/extension/configuration.h
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ extern bool runtime_config_first_init;
CONFIG(STRING, DD_APPSEC_HTTP_BLOCKED_TEMPLATE_HTML, "") \
CONFIG(STRING, DD_APPSEC_HTTP_BLOCKED_TEMPLATE_JSON, "") \
CONFIG(DOUBLE, DD_API_SECURITY_REQUEST_SAMPLE_RATE, "0.1", .ini_change = zai_config_system_ini_change) \
CONFIG(BOOL, DD_EXPERIMENTAL_APPSEC_STANDALONE_ENABLED, "false") \
CONFIG(BOOL, DD_APM_TRACING_ENABLED, "true") \
CONFIG(BOOL, DD_API_SECURITY_ENABLED, "true", .ini_change = zai_config_system_ini_change)
// clang-format on

Expand Down
6 changes: 3 additions & 3 deletions appsec/src/extension/tags.c
Original file line number Diff line number Diff line change
Expand Up @@ -406,9 +406,9 @@ void dd_tags_add_tags(
if (_force_keep) {
dd_trace_set_priority_sampling_on_span_zobj(span,
PRIORITY_SAMPLING_USER_KEEP,
get_DD_EXPERIMENTAL_APPSEC_STANDALONE_ENABLED()
? DD_MECHANISM_ASM
: DD_MECHANISM_MANUAL);
get_DD_APM_TRACING_ENABLED()
? DD_MECHANISM_MANUAL
: DD_MECHANISM_ASM);
mlog(dd_log_debug, "Updated sampling priority to user_keep");
}

Expand Down
2 changes: 1 addition & 1 deletion ext/asm_event.c
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ DDTRACE_PUBLIC void ddtrace_emit_asm_event() {
ZVAL_STR(&_1_zval, _1_zstr);
ddtrace_add_propagated_tag(_dd_tag_p_appsec_zstr, &_1_zval);

if (get_DD_EXPERIMENTAL_APPSEC_STANDALONE_ENABLED()) {
if (!get_DD_APM_TRACING_ENABLED()) {
ddtrace_set_priority_sampling_on_root(PRIORITY_SAMPLING_USER_KEEP, DD_MECHANISM_ASM);
}
}
Expand Down
4 changes: 2 additions & 2 deletions ext/auto_flush.c
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ ZEND_RESULT_CODE ddtrace_flush_tracer(bool force_on_startup, bool collect_cycles
return SUCCESS;
}

if (get_DD_EXPERIMENTAL_APPSEC_STANDALONE_ENABLED()) {
if (!get_global_DD_APM_TRACING_ENABLED()) {
if (!DDTRACE_G(asm_event_emitted) && !trace_contains_appsec_event(&trace) && !ddtrace_standalone_limiter_allow()) {
zval *root_span = zend_hash_index_find(Z_ARR(trace), 0);
if (!root_span || Z_TYPE_P(root_span) != IS_ARRAY) {
Expand Down Expand Up @@ -111,7 +111,7 @@ ZEND_RESULT_CODE ddtrace_flush_tracer(bool force_on_startup, bool collect_cycles
.tracer_version = DDOG_CHARSLICE_C_BARE(PHP_DDTRACE_VERSION),
.lang_version = dd_zend_string_to_CharSlice(ddtrace_php_version),
.client_computed_top_level = false,
.client_computed_stats = get_global_DD_EXPERIMENTAL_APPSEC_STANDALONE_ENABLED(),
.client_computed_stats = !get_global_DD_APM_TRACING_ENABLED(),
};
size_t size_hint = written;
zend_long n_requests = get_global_DD_TRACE_AGENT_FLUSH_AFTER_N_REQUESTS();
Expand Down
2 changes: 1 addition & 1 deletion ext/coms.c
Original file line number Diff line number Diff line change
Expand Up @@ -695,7 +695,7 @@ static struct curl_slist *dd_agent_headers_alloc(void) {
dd_append_header(&list, "Datadog-Meta-Lang-Interpreter", sapi_module.name);
dd_append_header(&list, "Datadog-Meta-Lang-Version", ZSTR_VAL(ddtrace_php_version));
dd_append_header(&list, "Datadog-Meta-Tracer-Version", PHP_DDTRACE_VERSION);
if (get_global_DD_EXPERIMENTAL_APPSEC_STANDALONE_ENABLED()) {
if (!get_global_DD_APM_TRACING_ENABLED()) {
dd_append_header(&list, "Datadog-Client-Computed-Stats", "true");
}

Expand Down
2 changes: 1 addition & 1 deletion ext/configuration.h
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,7 @@ enum ddtrace_sampling_rules_format {
CONFIG(BOOL, DD_REMOTE_CONFIG_ENABLED, "true", .ini_change = zai_config_system_ini_change) \
CONFIG(BOOL, DD_DYNAMIC_INSTRUMENTATION_ENABLED, "false", .ini_change = zai_config_system_ini_change) \
CONFIG(SET, DD_DYNAMIC_INSTRUMENTATION_REDACTED_IDENTIFIERS, "", .ini_change = zai_config_system_ini_change) \
CONFIG(BOOL, DD_EXPERIMENTAL_APPSEC_STANDALONE_ENABLED, "false") \
CONFIG(BOOL, DD_APM_TRACING_ENABLED, "true") \
CONFIG(SET, DD_DYNAMIC_INSTRUMENTATION_REDACTED_TYPES, "", .ini_change = zai_config_system_ini_change) \
DD_INTEGRATIONS

Expand Down
4 changes: 2 additions & 2 deletions ext/handlers_http.h
Original file line number Diff line number Diff line change
Expand Up @@ -136,11 +136,11 @@ static inline void ddtrace_inject_distributed_headers_config(zend_array *array,
bool send_b3single = zend_hash_str_exists(inject, ZEND_STRL("b3 single header"));

zend_long sampling_priority = ddtrace_fetch_priority_sampling_from_root();
if (get_DD_EXPERIMENTAL_APPSEC_STANDALONE_ENABLED() && DDTRACE_G(asm_event_emitted) == true) {
if (!get_DD_APM_TRACING_ENABLED() && DDTRACE_G(asm_event_emitted) == true) {
sampling_priority = PRIORITY_SAMPLING_USER_KEEP;
}

if (get_DD_EXPERIMENTAL_APPSEC_STANDALONE_ENABLED() && DDTRACE_G(asm_event_emitted) == false &&
if (!get_DD_APM_TRACING_ENABLED() && DDTRACE_G(asm_event_emitted) == false &&
ddtrace_propagated_tags_get_tag(DD_TAG_P_APPSEC) == NULL) {
return;
}
Expand Down
3 changes: 0 additions & 3 deletions ext/limiter/limiter.c
Original file line number Diff line number Diff line change
Expand Up @@ -61,9 +61,6 @@ bool ddtrace_limiter_active() {
}

bool ddtrace_limiter_allow() {
if (get_global_DD_EXPERIMENTAL_APPSEC_STANDALONE_ENABLED()) {
return true;
}
ZEND_ASSERT(dd_limiter);

uint64_t timeval = zend_hrtime();
Expand Down
4 changes: 2 additions & 2 deletions ext/priority_sampling/priority_sampling.c
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ static ddtrace_rule_result dd_match_rules(ddtrace_span_data *span, bool eval_roo
}

zval *rule;
if (!get_global_DD_EXPERIMENTAL_APPSEC_STANDALONE_ENABLED()) { // APPSEC_STANDALONE enabled, override sampling rules to be empty
if (get_global_DD_APM_TRACING_ENABLED()) {
ZEND_HASH_FOREACH_VAL(get_DD_TRACE_SAMPLING_RULES(), rule) {
if (++index >= skip_at) {
break;
Expand Down Expand Up @@ -288,7 +288,7 @@ static void dd_decide_on_sampling(ddtrace_root_span_data *span) {
bool limited = false;
if (result.mechanism != DD_MECHANISM_MANUAL && ddtrace_limiter_active() && sampling) {
if (span->trace_is_limited == DD_TRACE_LIMIT_UNCHECKED) {
span->trace_is_limited = ddtrace_limiter_allow() ? DD_TRACE_UNLIMITED : DD_TRACE_LIMITED;
span->trace_is_limited = !get_global_DD_APM_TRACING_ENABLED() || ddtrace_limiter_allow() ? DD_TRACE_UNLIMITED : DD_TRACE_LIMITED;
}
limited = span->trace_is_limited == DD_TRACE_LIMITED;
}
Expand Down
6 changes: 3 additions & 3 deletions ext/serializer.c
Original file line number Diff line number Diff line change
Expand Up @@ -1700,7 +1700,7 @@ void ddtrace_serialize_span_to_array(ddtrace_span_data *span, zval *array) {
}

zval *asm_event = NULL;
if (get_global_DD_EXPERIMENTAL_APPSEC_STANDALONE_ENABLED()) {
if (!get_global_DD_APM_TRACING_ENABLED()) {
asm_event = zend_hash_str_find(meta, ZEND_STRL(DD_TAG_P_APPSEC));
}
bool is_standalone_appsec_span = asm_event ? Z_TYPE_P(asm_event) == IS_STRING && strncmp(Z_STRVAL_P(asm_event), "1", sizeof("1") - 1) == 0 : 0;
Expand All @@ -1720,12 +1720,12 @@ void ddtrace_serialize_span_to_array(ddtrace_span_data *span, zval *array) {
if (is_root_span) {
if (Z_TYPE_P(&span->root->property_sampling_priority) != IS_UNDEF) {
long sampling_priority = zval_get_long(&span->root->property_sampling_priority);
if (get_global_DD_EXPERIMENTAL_APPSEC_STANDALONE_ENABLED() && !is_standalone_appsec_span) {
if (!get_global_DD_APM_TRACING_ENABLED() && !is_standalone_appsec_span) {
sampling_priority = MIN(PRIORITY_SAMPLING_AUTO_KEEP, sampling_priority);
}
add_assoc_double(&metrics_zv, "_sampling_priority_v1", sampling_priority);
}
if(get_global_DD_EXPERIMENTAL_APPSEC_STANDALONE_ENABLED()) {
if(!get_global_DD_APM_TRACING_ENABLED()) {
add_assoc_long(&metrics_zv, "_dd.apm.enabled", 0);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ DD_TRACE_AGENT_FLUSH_INTERVAL=333
DD_TRACE_GENERATE_ROOT_SPAN=0
DD_INSTRUMENTATION_TELEMETRY_ENABLED=0
DD_TRACE_SIDECAR_TRACE_SENDER=0
DD_EXPERIMENTAL_APPSEC_STANDALONE_ENABLED=1
DD_APM_TRACING_ENABLED=0
--INI--
datadog.trace.agent_test_session_token=background-sender/agent_samplingc
--FILE--
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ DD_TRACE_AGENT_FLUSH_INTERVAL=333
DD_TRACE_GENERATE_ROOT_SPAN=0
DD_INSTRUMENTATION_TELEMETRY_ENABLED=0
DD_TRACE_SIDECAR_TRACE_SENDER=0
DD_EXPERIMENTAL_APPSEC_STANDALONE_ENABLED=1
DD_APM_TRACING_ENABLED=0
--INI--
datadog.trace.agent_test_session_token=background-sender/agent_samplingb
--FILE--
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ DD_TRACE_AGENT_FLUSH_INTERVAL=333
DD_TRACE_GENERATE_ROOT_SPAN=0
DD_INSTRUMENTATION_TELEMETRY_ENABLED=0
DD_TRACE_SIDECAR_TRACE_SENDER=0
DD_EXPERIMENTAL_APPSEC_STANDALONE_ENABLED=1
DD_APM_TRACING_ENABLED=0
HTTP_X_DATADOG_TRACE_ID=42
HTTP_X_DATADOG_PARENT_ID=10
HTTP_X_DATADOG_ORIGIN=datadog
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ HTTP_X_DATADOG_ORIGIN=datadog
HTTP_X_DATADOG_SAMPLING_PRIORITY=3
HTTP_X_DATADOG_TAGS=_dd.p.custom_tag=inherited,_dd.p.dropped,_dd.p.other_tag=also,_dd.p.drop
DD_TRACE_GENERATE_ROOT_SPAN=0
DD_EXPERIMENTAL_APPSEC_STANDALONE_ENABLED=1
DD_APM_TRACING_ENABLED=0
--FILE--
<?php

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ HTTP_X_DATADOG_ORIGIN=datadog
HTTP_X_DATADOG_SAMPLING_PRIORITY=3
HTTP_X_DATADOG_TAGS=_dd.p.appsec=1
DD_TRACE_GENERATE_ROOT_SPAN=0
DD_EXPERIMENTAL_APPSEC_STANDALONE_ENABLED=1
DD_APM_TRACING_ENABLED=0
--FILE--
<?php

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ Distributed tracing header tags propagate asm events with curl_exec()
--ENV--
DD_TRACE_TRACED_INTERNAL_FUNCTIONS=curl_exec
HTTP_X_DATADOG_TRACE_ID=42
DD_EXPERIMENTAL_APPSEC_STANDALONE_ENABLED=1
DD_APM_TRACING_ENABLED=0
--FILE--
<?php

Expand Down
2 changes: 1 addition & 1 deletion tests/ext/limiter/003-limiter-with-asm-standalone.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ DD_TRACE_AUTO_FLUSH_ENABLED=0
DD_TRACE_GENERATE_ROOT_SPAN=0
DD_TRACE_RATE_LIMIT=10
DD_TRACE_SAMPLE_RATE=1
DD_EXPERIMENTAL_APPSEC_STANDALONE_ENABLED=1
DD_APM_TRACING_ENABLED=0
--FILE--
<?php
$spans = [];
Expand Down
2 changes: 1 addition & 1 deletion tests/ext/priority_sampling/asm-standalone.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ priority_sampling is ignored when asm standalone is enabled
--ENV--
DD_TRACE_SAMPLING_RULES=[{"sample_rate": 0.3}]
DD_TRACE_GENERATE_ROOT_SPAN=1
DD_EXPERIMENTAL_APPSEC_STANDALONE_ENABLED=1
DD_APM_TRACING_ENABLED=0
--FILE--
<?php
$root = \DDTrace\root_span();
Expand Down

0 comments on commit 479b78f

Please sign in to comment.