Skip to content

Commit 56c99bd

Browse files
committed
Finish fixing system tests
1 parent e70d1a0 commit 56c99bd

File tree

4 files changed

+42
-17
lines changed

4 files changed

+42
-17
lines changed

ext/distributed_tracing_headers.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -493,7 +493,7 @@ void ddtrace_apply_distributed_tracing_result(ddtrace_distributed_tracing_result
493493
result->meta_tags.pDestructor = NULL; // we moved values directly
494494
zend_hash_destroy(&result->meta_tags);
495495

496-
if (result->priority_sampling != DDTRACE_PRIORITY_SAMPLING_UNKNOWN && !get_DD_EXPERIMENTAL_APPSEC_STANDALONE_ENABLED()) {
496+
if (result->priority_sampling != DDTRACE_PRIORITY_SAMPLING_UNKNOWN) {
497497
bool reset_decision_maker = result->conflicting_sampling_priority || !zend_hash_str_exists(root_meta, ZEND_STRL("_dd.p.dm"));
498498
if (reset_decision_maker) {
499499
if (result->priority_sampling > 0) {

ext/handlers_http.h

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,37 @@ static inline void ddtrace_inject_distributed_headers_config(zend_array *array,
138138
ddtrace_trace_id trace_id = ddtrace_peek_trace_id();
139139
uint64_t span_id = ddtrace_peek_span_id();
140140

141+
zval tags;
142+
array_init(&tags);
143+
ddtrace_get_propagated_tags(Z_ARR(tags));
144+
zval *ddtrace_has_appsec_propagation_tag = zend_hash_str_find(Z_ARR(tags), ZEND_STRL("_dd.p.appsec"));
145+
146+
zend_array *root_meta = &DDTRACE_G(root_span_tags_preset);
147+
ddtrace_root_span_data *root_span = DDTRACE_G(active_stack)->root_span;
148+
if (root_span) {
149+
root_meta = ddtrace_property_array(&root_span->property_meta);
150+
}
151+
zval *ddtrace_has_asm_avent = zend_hash_str_find(root_meta, ZEND_STRL("_dd.p.appsec"));
152+
153+
if (get_DD_EXPERIMENTAL_APPSEC_STANDALONE_ENABLED() && ddtrace_has_asm_avent == NULL) {
154+
if (ddtrace_has_appsec_propagation_tag != NULL) {
155+
if (send_datadog) {
156+
ADD_HEADER("x-datadog-sampling-priority", ZEND_LONG_FMT, sampling_priority);
157+
}
158+
if (trace_id.low || trace_id.high) {
159+
if (send_datadog) {
160+
ADD_HEADER("x-datadog-trace-id", "%" PRIu64, trace_id.low);
161+
}
162+
if (span_id) {
163+
if (send_datadog) {
164+
ADD_HEADER("x-datadog-parent-id", "%" PRIu64, span_id);
165+
}
166+
}
167+
}
168+
}
169+
return;
170+
}
171+
141172
if (sampling_priority != DDTRACE_PRIORITY_SAMPLING_UNKNOWN) {
142173
if (send_datadog) {
143174
ADD_HEADER("x-datadog-sampling-priority", ZEND_LONG_FMT, sampling_priority);

ext/random.c

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -118,16 +118,6 @@ ddtrace_trace_id ddtrace_peek_trace_id(void) {
118118
return pspan ? SPANDATA(pspan)->root->trace_id : DDTRACE_G(distributed_trace_id);
119119
}
120120

121-
bool ddtrace_has_asm_avent(void) {
122-
ddtrace_span_properties *pspan = DDTRACE_G(active_stack) ? DDTRACE_G(active_stack)->active : NULL;
123-
if(!pspan) {
124-
return false;
125-
}
126-
zend_array *meta = ddtrace_property_array(&pspan->property_meta);
127-
128-
return zend_hash_str_exists(meta, ZEND_STRL("_dd.p.appsec"));
129-
}
130-
131121
int ddtrace_conv10_trace_id(ddtrace_trace_id id, uint8_t reverse[DD_TRACE_MAX_ID_LEN]) {
132122
reverse[0] = 0;
133123
int i = 0;

ext/serializer.c

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1691,11 +1691,11 @@ void ddtrace_serialize_span_to_array(ddtrace_span_data *span, zval *array) {
16911691
zend_hash_str_del(meta, ZEND_STRL("operation.name"));
16921692
}
16931693

1694-
// zval *asm_event = NULL;
1695-
// if (get_global_DD_EXPERIMENTAL_APPSEC_STANDALONE_ENABLED()) {
1696-
// asm_event = zend_hash_str_find(meta, ZEND_STRL("_dd.p.appsec"));
1697-
// }
1698-
// 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;
1694+
zval *asm_event = NULL;
1695+
if (get_global_DD_EXPERIMENTAL_APPSEC_STANDALONE_ENABLED()) {
1696+
asm_event = zend_hash_str_find(meta, ZEND_STRL("_dd.p.appsec"));
1697+
}
1698+
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;
16991699

17001700
_serialize_meta(el, span, Z_TYPE_P(prop_service) > IS_NULL ? Z_STR(prop_service_as_string) : ZSTR_EMPTY_ALLOC());
17011701

@@ -1711,7 +1711,11 @@ void ddtrace_serialize_span_to_array(ddtrace_span_data *span, zval *array) {
17111711

17121712
if (is_root_span) {
17131713
if (Z_TYPE_P(&span->root->property_sampling_priority) != IS_UNDEF) {
1714-
add_assoc_double(&metrics_zv, "_sampling_priority_v1", zval_get_long(&span->root->property_sampling_priority));
1714+
long sampling_priority = zval_get_long(&span->root->property_sampling_priority);
1715+
if (get_global_DD_EXPERIMENTAL_APPSEC_STANDALONE_ENABLED() && !is_standalone_appsec_span) {
1716+
sampling_priority = MIN(PRIORITY_SAMPLING_AUTO_KEEP, sampling_priority);
1717+
}
1718+
add_assoc_double(&metrics_zv, "_sampling_priority_v1", sampling_priority);
17151719
}
17161720
if(get_global_DD_EXPERIMENTAL_APPSEC_STANDALONE_ENABLED()) {
17171721
add_assoc_long(&metrics_zv, "_dd.apm.enabled", 0);

0 commit comments

Comments
 (0)