-
Notifications
You must be signed in to change notification settings - Fork 147
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Set _dd.base_service when overriding service name for a span #2275
Conversation
Just for the record, the API you are targeting is mostly the "legacy API". A common way to change the service name would be directly editing the DDTrace\SpanData object (i.e. a simple span object defined directly in C). E.g. (snippet from CurlIntegration): \DDTrace\trace_function('curl_exec', [
'posthook' => function (SpanData $span, $args, $retval) use ($integration) {
$span->name = $span->resource = 'curl_exec';
$span->type = Type::HTTP_CLIENT;
$span->service = 'curl';
// ...
},
]); What you want to do is most likely checking the service of the root span during serialization (in ext/serializer.c) and then dynamically add _dd.base_service = , if the service is not equal to the root spans service. |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
ext/serializer.c
Outdated
ZVAL_COPY(&prop_root_service_as_string, new_root_name); | ||
} | ||
|
||
if (strcasecmp(Z_STRVAL(prop_service_as_string), Z_STRVAL(prop_root_service_as_string)) != 0) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if (strcasecmp(Z_STRVAL(prop_service_as_string), Z_STRVAL(prop_root_service_as_string)) != 0) { | |
if (zend_string_equals(Z_STR(prop_service_as_string), Z_STR(prop_root_service_as_string))) { |
zend_string_equals is aware of the lengths directly and also does a pointer equality comparison (which likely will match if both are equal).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍 modified the suggestion a bit by using zend_string_equals_ci
instead of zend_string_equals
to keep the behavior consistent with strcasecmp
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, missed that it wasn't strcmp :-)
ext/serializer.c
Outdated
|
||
if (strcasecmp(Z_STRVAL(prop_service_as_string), Z_STRVAL(prop_root_service_as_string)) != 0) { | ||
zend_array *meta = ddtrace_property_array(&span->property_meta); | ||
zend_hash_str_add_new(meta, ZEND_STRL("_dd.base_service"), &prop_root_service_as_string); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
zend_hash_str_add_new(meta, ZEND_STRL("_dd.base_service"), &prop_root_service_as_string); | |
zend_hash_str_update(meta, ZEND_STRL("_dd.base_service"), &prop_root_service_as_string); |
Don't use _add_new
if you cannot be sure that there's no user-input you could overwrite. If there's already a manually added meta key from PHP code named _dd.base_service, it'll leak. And just _add
needs to be checked for success or failure to potentially free the value.
ext/serializer.c
Outdated
zval *prop_root_service = &span->root->property_service; | ||
ZVAL_DEREF(prop_root_service); | ||
zval prop_root_service_as_string; | ||
ddtrace_convert_to_string(&prop_root_service_as_string, prop_root_service); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
zval *prop_root_service = &span->root->property_service; | |
ZVAL_DEREF(prop_root_service); | |
zval prop_root_service_as_string; | |
ddtrace_convert_to_string(&prop_root_service_as_string, prop_root_service); | |
zval prop_root_service_as_string; | |
ddtrace_convert_to_string(&prop_root_service_as_string, &span->root->property_service); |
ddtrace_convert_to_string is able to handle refs directly
Generally such code just inserting into meta should be probably moved into |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good to me now :-)
} | ||
|
||
if (!zend_string_equals_ci(Z_STR(prop_service_as_string), Z_STR(prop_root_service_as_string))) { | ||
add_assoc_str(meta, "_dd.base_service", Z_STR(prop_root_service_as_string)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Wait, this needs a refcount increase, or the release below needs to be moved into an else.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
Snapshots difference summaryThe following differences have been observed in committed snapshots. It is meant to help the reviewer. |
Description
Add
_dd.base_service
to child spans when child service name is updated manually. AIT-8051Integration tests have been changed to by default have
DD_TRACE_GENERATE_ROOT_SPAN=0
, to minimize the amount of tests that would have needed to be modified to add by adding the_dd.base_service
tagReadiness checklist
Reviewer checklist