Skip to content

Commit

Permalink
Finish fixing system tests
Browse files Browse the repository at this point in the history
  • Loading branch information
estringana committed Nov 12, 2024
1 parent e70d1a0 commit 56c99bd
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 17 deletions.
2 changes: 1 addition & 1 deletion ext/distributed_tracing_headers.c
Original file line number Diff line number Diff line change
Expand Up @@ -493,7 +493,7 @@ void ddtrace_apply_distributed_tracing_result(ddtrace_distributed_tracing_result
result->meta_tags.pDestructor = NULL; // we moved values directly
zend_hash_destroy(&result->meta_tags);

if (result->priority_sampling != DDTRACE_PRIORITY_SAMPLING_UNKNOWN && !get_DD_EXPERIMENTAL_APPSEC_STANDALONE_ENABLED()) {
if (result->priority_sampling != DDTRACE_PRIORITY_SAMPLING_UNKNOWN) {
bool reset_decision_maker = result->conflicting_sampling_priority || !zend_hash_str_exists(root_meta, ZEND_STRL("_dd.p.dm"));
if (reset_decision_maker) {
if (result->priority_sampling > 0) {
Expand Down
31 changes: 31 additions & 0 deletions ext/handlers_http.h
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,37 @@ static inline void ddtrace_inject_distributed_headers_config(zend_array *array,
ddtrace_trace_id trace_id = ddtrace_peek_trace_id();
uint64_t span_id = ddtrace_peek_span_id();

zval tags;
array_init(&tags);
ddtrace_get_propagated_tags(Z_ARR(tags));
zval *ddtrace_has_appsec_propagation_tag = zend_hash_str_find(Z_ARR(tags), ZEND_STRL("_dd.p.appsec"));

zend_array *root_meta = &DDTRACE_G(root_span_tags_preset);
ddtrace_root_span_data *root_span = DDTRACE_G(active_stack)->root_span;
if (root_span) {
root_meta = ddtrace_property_array(&root_span->property_meta);
}
zval *ddtrace_has_asm_avent = zend_hash_str_find(root_meta, ZEND_STRL("_dd.p.appsec"));

if (get_DD_EXPERIMENTAL_APPSEC_STANDALONE_ENABLED() && ddtrace_has_asm_avent == NULL) {
if (ddtrace_has_appsec_propagation_tag != NULL) {
if (send_datadog) {
ADD_HEADER("x-datadog-sampling-priority", ZEND_LONG_FMT, sampling_priority);
}
if (trace_id.low || trace_id.high) {
if (send_datadog) {
ADD_HEADER("x-datadog-trace-id", "%" PRIu64, trace_id.low);
}
if (span_id) {
if (send_datadog) {
ADD_HEADER("x-datadog-parent-id", "%" PRIu64, span_id);
}
}
}
}
return;
}

if (sampling_priority != DDTRACE_PRIORITY_SAMPLING_UNKNOWN) {
if (send_datadog) {
ADD_HEADER("x-datadog-sampling-priority", ZEND_LONG_FMT, sampling_priority);
Expand Down
10 changes: 0 additions & 10 deletions ext/random.c
Original file line number Diff line number Diff line change
Expand Up @@ -118,16 +118,6 @@ ddtrace_trace_id ddtrace_peek_trace_id(void) {
return pspan ? SPANDATA(pspan)->root->trace_id : DDTRACE_G(distributed_trace_id);
}

bool ddtrace_has_asm_avent(void) {
ddtrace_span_properties *pspan = DDTRACE_G(active_stack) ? DDTRACE_G(active_stack)->active : NULL;
if(!pspan) {
return false;
}
zend_array *meta = ddtrace_property_array(&pspan->property_meta);

return zend_hash_str_exists(meta, ZEND_STRL("_dd.p.appsec"));
}

int ddtrace_conv10_trace_id(ddtrace_trace_id id, uint8_t reverse[DD_TRACE_MAX_ID_LEN]) {
reverse[0] = 0;
int i = 0;
Expand Down
16 changes: 10 additions & 6 deletions ext/serializer.c
Original file line number Diff line number Diff line change
Expand Up @@ -1691,11 +1691,11 @@ void ddtrace_serialize_span_to_array(ddtrace_span_data *span, zval *array) {
zend_hash_str_del(meta, ZEND_STRL("operation.name"));
}

// zval *asm_event = NULL;
// if (get_global_DD_EXPERIMENTAL_APPSEC_STANDALONE_ENABLED()) {
// asm_event = zend_hash_str_find(meta, ZEND_STRL("_dd.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;
zval *asm_event = NULL;
if (get_global_DD_EXPERIMENTAL_APPSEC_STANDALONE_ENABLED()) {
asm_event = zend_hash_str_find(meta, ZEND_STRL("_dd.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;

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

Expand All @@ -1711,7 +1711,11 @@ 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) {
add_assoc_double(&metrics_zv, "_sampling_priority_v1", zval_get_long(&span->root->property_sampling_priority));
long sampling_priority = zval_get_long(&span->root->property_sampling_priority);
if (get_global_DD_EXPERIMENTAL_APPSEC_STANDALONE_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()) {
add_assoc_long(&metrics_zv, "_dd.apm.enabled", 0);
Expand Down

0 comments on commit 56c99bd

Please sign in to comment.