-
Notifications
You must be signed in to change notification settings - Fork 182
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
Changes from all commits
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 |
|---|---|---|
|
|
@@ -153,6 +153,31 @@ void datadog_sidecar_update_process_tags(void) { | |
| } | ||
|
|
||
| ddog_sidecar_session_set_process_tags(&DATADOG_G(sidecar), process_tags); | ||
|
|
||
| // Session-bound, process-stable: the tracer's auto-resolved default name. | ||
| zend_string *default_svc = datadog_default_service_name(); | ||
| if (default_svc) { | ||
| const char *normalized = ddog_normalize_process_tag_value(dd_zend_string_to_CharSlice(default_svc)); | ||
| if (normalized) { | ||
| datadog_ffi_try("Failed updating sidecar default service name", | ||
| ddog_sidecar_session_set_default_service_name(&DATADOG_G(sidecar), | ||
| (ddog_CharSlice){ .ptr = normalized, .len = strlen(normalized) })); | ||
| ddog_free_normalized_tag_value(normalized); | ||
| } | ||
| zend_string_release(default_svc); | ||
| } | ||
|
|
||
| datadog_sidecar_refresh_user_service_defined(); | ||
| } | ||
|
|
||
| void datadog_sidecar_refresh_user_service_defined(void) { | ||
| if (!DATADOG_G(sidecar)) { | ||
| return; | ||
| } | ||
| zend_string *dd_service = get_DD_SERVICE(); | ||
| bool is_defined = dd_service && ZSTR_LEN(dd_service) > 0; | ||
| datadog_ffi_try("Failed updating sidecar user-service-defined flag", | ||
| ddog_sidecar_session_set_user_service_defined(&DATADOG_G(sidecar), is_defined)); | ||
| } | ||
|
|
||
| static void datadog_sidecar_setup_thread_mode(void); | ||
|
|
@@ -799,6 +824,10 @@ void datadog_sidecar_rinit(void) { | |
| } | ||
|
|
||
| ddtrace_sidecar_submit_span_data_direct_defaults(&DATADOG_G(sidecar), NULL); | ||
|
|
||
| if (get_global_DD_EXPERIMENTAL_PROPAGATE_PROCESS_TAGS_ENABLED()) { | ||
| datadog_sidecar_refresh_user_service_defined(); | ||
|
Leiyks marked this conversation as resolved.
|
||
| } | ||
|
Comment on lines
+828
to
+830
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.
Refreshing the Useful? React with 👍 / 👎. |
||
| } | ||
|
|
||
| void datadog_sidecar_rshutdown(void) { | ||
|
|
||
| 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.
This only sends the new
default_service_namefromdatadog_sidecar_update_process_tags(), which is called from the one-time first-RINIT path and the explicit reload path. Fresh sidecar sessions created later bydd_sidecar_on_reconnect()/datadog_sidecar_ensure_active()rundd_sidecar_post_connect()and resend UST, but never call this setter, so after a sidecar restart or a late worker-thread connection the sidecar has no default service name and its telemetry/runtime-info process tags losesvc.auto:<default>until process tags are manually reloaded.Useful? React with 👍 / 👎.