-
Notifications
You must be signed in to change notification settings - Fork 180
feat(process-tags): signal service name source via svc.user/svc.auto #3921
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
base: master
Are you sure you want to change the base?
Changes from 5 commits
64040f8
602e778
cdf7e03
a210c1c
9a57ed0
84b004e
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -7,6 +7,7 @@ | |
| #include "ddtrace_export.h" | ||
| #include "dogstatsd.h" | ||
| #include "logging.h" | ||
| #include "serializer.h" | ||
| #include <components-rs/common.h> | ||
| #include <components-rs/ddtrace.h> | ||
| #include <components-rs/sidecar.h> | ||
|
|
@@ -149,6 +150,27 @@ void ddtrace_sidecar_update_process_tags(void) { | |
| } | ||
|
|
||
| ddog_sidecar_session_set_process_tags(&DDTRACE_G(sidecar), process_tags); | ||
|
|
||
| zend_string *dd_service = get_DD_SERVICE(); | ||
| if (dd_service && ZSTR_LEN(dd_service) > 0) { | ||
|
Comment on lines
+154
to
+155
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. DD_SERVICE is dynamic per request, not per session. Some request may have it, another not. You probably can store ddtrace_default_service_name() on the sidecar as session bound (at which point setting that one via ddog_sidecar_session_set_config is enough), but the DD_SERVICE may or may not exist for any particular request, and change between requests. You may have to submit that one alongside with ddog_sidecar_set_universal_service_tags(). ... let's talk about that?! |
||
| ddtrace_ffi_try("Failed updating sidecar default service name", | ||
| ddog_sidecar_session_set_default_service_name(&DDTRACE_G(sidecar), | ||
| DDOG_CHARSLICE_C(""))); | ||
| } else { | ||
| zend_string *default_svc = ddtrace_default_service_name(); | ||
| if (default_svc) { | ||
| const char *normalized = ddog_normalize_process_tag_value((ddog_CharSlice){ | ||
| .ptr = ZSTR_VAL(default_svc), .len = ZSTR_LEN(default_svc) | ||
| }); | ||
| if (normalized) { | ||
| ddtrace_ffi_try("Failed updating sidecar default service name", | ||
| ddog_sidecar_session_set_default_service_name(&DDTRACE_G(sidecar), | ||
| (ddog_CharSlice){ .ptr = normalized, .len = strlen(normalized) })); | ||
| ddog_free_normalized_tag_value(normalized); | ||
| } | ||
| zend_string_release(default_svc); | ||
| } | ||
| } | ||
| } | ||
|
|
||
| static ddog_SidecarTransport *dd_sidecar_connection_factory_ex(bool is_fork); | ||
|
|
@@ -498,6 +520,8 @@ void ddtrace_sidecar_handle_fork(void) { | |
|
|
||
| if (DDTRACE_G(sidecar)) { | ||
| ddtrace_sidecar_for_signal = DDTRACE_G(sidecar); | ||
| // Fresh post-fork session has no svc.* source — re-push it. | ||
| ddtrace_sidecar_update_process_tags(); | ||
| } | ||
| #endif | ||
| } | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,13 @@ | ||
| <?php | ||
|
|
||
| namespace App; | ||
|
|
||
| class SetServiceController | ||
| { | ||
| public function render() | ||
| { | ||
| ini_set('datadog.service', 'request-svc'); | ||
| header('Content-type: text/plain; charset=utf-8'); | ||
| echo 'service set'; | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,23 @@ | ||
| --TEST-- | ||
| Process tags include svc.auto:<default> when DD_SERVICE is unset (CLI) | ||
| --ENV-- | ||
| DD_EXPERIMENTAL_PROPAGATE_PROCESS_TAGS_ENABLED=1 | ||
| DD_TRACE_GENERATE_ROOT_SPAN=0 | ||
| DD_TRACE_AUTO_FLUSH_ENABLED=0 | ||
| --FILE-- | ||
| <?php | ||
| $span = \DDTrace\start_span(); | ||
| $span->name = 'op'; | ||
| \DDTrace\close_span(); | ||
|
|
||
| $spans = dd_trace_serialize_closed_spans(); | ||
| $processTags = $spans[0]['meta']['_dd.tags.process']; | ||
|
|
||
| echo "has svc.user: " . (strpos($processTags, 'svc.user') !== false ? 'YES' : 'NO') . "\n"; | ||
| echo "has svc.auto: " . (strpos($processTags, 'svc.auto:') !== false ? 'YES' : 'NO') . "\n"; | ||
| echo "auto value matches script: " . (strpos($processTags, 'svc.auto:svc_auto_tag_cli.php') !== false ? 'YES' : 'NO') . "\n"; | ||
| ?> | ||
| --EXPECT-- | ||
| has svc.user: NO | ||
| has svc.auto: YES | ||
| auto value matches script: YES |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,24 @@ | ||
| --TEST-- | ||
| OTEL_SERVICE_NAME counts as user-defined (emits svc.user:true) | ||
| --ENV-- | ||
| DD_EXPERIMENTAL_PROPAGATE_PROCESS_TAGS_ENABLED=1 | ||
| OTEL_SERVICE_NAME=otel-app | ||
| DD_TRACE_GENERATE_ROOT_SPAN=0 | ||
| DD_TRACE_AUTO_FLUSH_ENABLED=0 | ||
| --FILE-- | ||
| <?php | ||
| $span = \DDTrace\start_span(); | ||
| $span->name = 'op'; | ||
| \DDTrace\close_span(); | ||
|
|
||
| $spans = dd_trace_serialize_closed_spans(); | ||
| $processTags = $spans[0]['meta']['_dd.tags.process']; | ||
|
|
||
| echo "DD_SERVICE resolved to: " . ini_get('datadog.service') . "\n"; | ||
| echo "has svc.user:true: " . (strpos($processTags, 'svc.user:true') !== false ? 'YES' : 'NO') . "\n"; | ||
| echo "has svc.auto: : " . (strpos($processTags, 'svc.auto:') !== false ? 'YES' : 'NO') . "\n"; | ||
| ?> | ||
| --EXPECT-- | ||
| DD_SERVICE resolved to: otel-app | ||
| has svc.user:true: YES | ||
| has svc.auto: : NO |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,37 @@ | ||
| --TEST-- | ||
| Changing datadog.service at runtime recomputes svc.user/svc.auto process tags per-span | ||
| --ENV-- | ||
| DD_EXPERIMENTAL_PROPAGATE_PROCESS_TAGS_ENABLED=1 | ||
| DD_TRACE_GENERATE_ROOT_SPAN=0 | ||
| DD_TRACE_AUTO_FLUSH_ENABLED=0 | ||
| --FILE-- | ||
| <?php | ||
| function assert_tags($label) { | ||
| $spans = dd_trace_serialize_closed_spans(); | ||
| $tags = $spans[0]['meta']['_dd.tags.process']; | ||
| $hasUser = strpos($tags, 'svc.user:true') !== false; | ||
| $hasAuto = strpos($tags, 'svc.auto:') !== false; | ||
| echo "$label svc.user=" . ($hasUser ? 'YES' : 'NO') . " svc.auto=" . ($hasAuto ? 'YES' : 'NO') . "\n"; | ||
| } | ||
|
|
||
| $span1 = \DDTrace\start_span(); | ||
| $span1->name = 'before'; | ||
| \DDTrace\close_span(); | ||
| assert_tags('BEFORE '); | ||
|
|
||
| ini_set('datadog.service', 'changed-svc'); | ||
| $span2 = \DDTrace\start_span(); | ||
| $span2->name = 'after_set'; | ||
| \DDTrace\close_span(); | ||
| assert_tags('AFTER '); | ||
|
|
||
| ini_restore('datadog.service'); | ||
| $span3 = \DDTrace\start_span(); | ||
| $span3->name = 'after_restore'; | ||
| \DDTrace\close_span(); | ||
| assert_tags('REVERTED'); | ||
| ?> | ||
| --EXPECT-- | ||
| BEFORE svc.user=NO svc.auto=YES | ||
| AFTER svc.user=YES svc.auto=NO | ||
| REVERTED svc.user=NO svc.auto=YES |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,22 @@ | ||
| --TEST-- | ||
| Process tags include svc.user:true when DD_SERVICE is set | ||
| --ENV-- | ||
| DD_EXPERIMENTAL_PROPAGATE_PROCESS_TAGS_ENABLED=1 | ||
| DD_SERVICE=my-app | ||
| DD_TRACE_GENERATE_ROOT_SPAN=0 | ||
| DD_TRACE_AUTO_FLUSH_ENABLED=0 | ||
| --FILE-- | ||
| <?php | ||
| $span = \DDTrace\start_span(); | ||
| $span->name = 'op'; | ||
| \DDTrace\close_span(); | ||
|
|
||
| $spans = dd_trace_serialize_closed_spans(); | ||
| $processTags = $spans[0]['meta']['_dd.tags.process']; | ||
|
|
||
| echo "has svc.user:true: " . (strpos($processTags, 'svc.user:true') !== false ? 'YES' : 'NO') . "\n"; | ||
| echo "has svc.auto: : " . (strpos($processTags, 'svc.auto:') !== false ? 'YES' : 'NO') . "\n"; | ||
| ?> | ||
| --EXPECT-- | ||
| has svc.user:true: YES | ||
| has svc.auto: : NO |
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.
simpler