-
Notifications
You must be signed in to change notification settings - Fork 182
feat: publish Linux OTel contexts #4077
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 all commits
8c942a0
f57acd4
29841a6
e719b9a
8d01de4
7023e5d
735982f
27c0cc2
e864a7b
e39966e
c86eefe
4257abe
c1ff52f
abb0c0a
13a50e0
cf39a70
8b77de3
921538e
80e8d94
15bcf4d
7033be3
c8aee2f
9f2fb86
792764c
427ffc0
ea477ac
d7b9b46
f4c37b5
9e2fde0
3aaa413
931734a
0bb8ecb
733a699
9528b71
68faa07
6399e80
b43537e
2c1a93d
995a137
a2df873
c2fa65a
9305698
8880610
d7e1a9d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -90,6 +90,72 @@ pub extern "C" fn datadog_format_runtime_id(buf: &mut [u8; 36]) { | |
| unsafe { datadog_runtime_id.as_hyphenated().encode_lower(buf) }; | ||
| } | ||
|
|
||
| #[cfg(target_os = "linux")] | ||
| fn char_slice_string(value: CharSlice<'_>) -> String { | ||
| value.to_utf8_lossy().into_owned() | ||
| } | ||
|
|
||
| #[cfg(target_os = "linux")] | ||
| fn hostname() -> String { | ||
| let max_len = unsafe { libc::sysconf(libc::_SC_HOST_NAME_MAX) }; | ||
| let max_len = usize::try_from(max_len).unwrap_or(255); | ||
| let mut buffer = vec![0; max_len.saturating_add(1)]; | ||
|
|
||
| if unsafe { libc::gethostname(buffer.as_mut_ptr().cast(), buffer.len()) } != 0 { | ||
| return String::new(); | ||
| } | ||
|
|
||
| let len = buffer | ||
| .iter() | ||
| .position(|&byte| byte == 0) | ||
| .unwrap_or(buffer.len()); | ||
| String::from_utf8_lossy(&buffer[..len]).into_owned() | ||
| } | ||
|
|
||
| /// Publish or update dd-trace-php's standard Linux OTel Process Context. | ||
| #[cfg(target_os = "linux")] | ||
| #[no_mangle] | ||
| pub extern "C" fn datadog_publish_otel_process_context(process_tags: CharSlice<'_>) -> bool { | ||
| use libdd_library_config::otel_process_ctx; | ||
| use libdd_library_config::tracer_metadata::{ThreadLocalMetadata, TracerMetadata}; | ||
|
|
||
| let metadata = TracerMetadata { | ||
| // Safety: the runtime ID is only mutated from single-threaded contexts. | ||
| runtime_id: Some(unsafe { datadog_runtime_id.as_hyphenated().to_string() }), | ||
| tracer_language: "php".to_owned(), | ||
| tracer_version: include_str!("../VERSION").trim().to_owned(), | ||
| hostname: hostname(), | ||
| process_tags: Some(char_slice_string(process_tags)), | ||
| container_id: get_container_id().map(str::to_owned), | ||
| threadlocal_metadata: Some(ThreadLocalMetadata { | ||
| attribute_keys: vec![ | ||
| "service.name".to_owned(), | ||
| "deployment.environment.name".to_owned(), | ||
| "service.version".to_owned(), | ||
| "thread.id".to_owned(), | ||
| ], | ||
| ..Default::default() | ||
| }), | ||
| ..Default::default() | ||
| }; | ||
|
|
||
| let mut context = metadata.to_otel_process_ctx(); | ||
| // TracerMetadata emits empty resource attributes for absent optional fields to advertise | ||
| // support. These values can vary independently on every PHP request, so their values and | ||
| // resource keys must be omitted from the process-wide context. The keys remain discoverable | ||
| // through threadlocal.attribute_key_map. | ||
| if let Some(resource) = context.resource.as_mut() { | ||
| resource.attributes.retain(|attribute| { | ||
| !matches!( | ||
| attribute.key.as_str(), | ||
| "service.name" | "service.version" | "deployment.environment.name" | ||
| ) | ||
| }); | ||
| } | ||
|
Comment on lines
+143
to
+154
Contributor
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. would be better to change libdatadog not to add these when it's not provided |
||
|
|
||
| otel_process_ctx::publish(&context).is_ok() | ||
| } | ||
|
|
||
| #[must_use] | ||
| #[no_mangle] | ||
| pub extern "C" fn ddtrace_get_container_id() -> CharSlice<'static> { | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,46 @@ | ||
| ddtrace_close_all_spans_and_flush | ||
| datadog_get_formatted_session_id | ||
| ddtrace_get_profiling_context | ||
| ddtrace_get_root_span | ||
| datadog_process_tags_get_serialized | ||
| datadog_get_sidecar_queue_id | ||
| ddtrace_get_priority_sampling_on_span_zobj | ||
| ddtrace_set_priority_sampling_on_span_zobj | ||
| ddtrace_add_propagated_tag_on_span_zobj | ||
| datadog_runtime_id | ||
| ddtrace_user_req_add_listeners | ||
| ddtrace_ip_extraction_find | ||
| datadog_set_all_thread_vm_interrupt | ||
| datadog_get_telemetry_rc_info | ||
| datadog_metric_register_buffer | ||
| datadog_metric_add_point | ||
| ddtrace_emit_asm_event | ||
| datadog_loaded_by_ssi | ||
| datadog_ssi_forced_injection_enabled | ||
| ddtrace_guess_endpoint_from_url | ||
| ddog_remote_config_reader_for_path | ||
| ddog_remote_config_read | ||
| ddog_remote_config_reader_drop | ||
| get_module | ||
| ddog_crashtracker_entry_point | ||
| ddog_daemon_entry_point | ||
| ddog_set_rc_notify_fn | ||
| ddog_remote_config_path | ||
| ddog_remote_config_path_free | ||
| ddog_library_configurator_new | ||
| ddog_library_configurator_with_local_path | ||
| ddog_library_configurator_with_fleet_path | ||
| ddog_library_configurator_with_detect_process_info | ||
| ddog_library_configurator_get | ||
| ddog_library_config_source_to_string | ||
| ddog_library_config_drop | ||
| ddog_Error_message | ||
| ddog_Error_drop | ||
| ddog_library_configurator_drop | ||
| ddog_sidecar_enqueue_telemetry_log | ||
| ddog_sidecar_enqueue_telemetry_point | ||
| ddog_sidecar_enqueue_telemetry_metric | ||
| ddog_sidecar_connect | ||
| ddog_sidecar_ping | ||
| ddog_sidecar_transport_drop | ||
| otel_thread_ctx_v1 |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -469,7 +469,11 @@ void datadog_sidecar_handle_fork(void) { | |
| return; | ||
| } | ||
|
|
||
| datadog_force_new_instance_id(); | ||
| if (datadog_sidecar_instance_id) { | ||
| ddog_sidecar_instanceId_drop(datadog_sidecar_instance_id); | ||
| datadog_sidecar_instance_id = NULL; | ||
| } | ||
| dd_set_resettable_sidecar_globals(); | ||
|
Comment on lines
+472
to
+476
Contributor
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. After this, |
||
|
|
||
| // After fork only one thread (the one that called fork) survives, so we only | ||
| // need to drop and reconnect the current thread's transport. | ||
|
|
||
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.
I don't think this will build on mac os as is, as it appears to include linux only sources.
And the linux part doesn't add
-mtls-dialect=gnu2.But not critical as I promised the cmake ddtrace build would not be a maintenance burden :p