Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1,228 changes: 338 additions & 890 deletions Cargo.lock

Large diffs are not rendered by default.

9 changes: 8 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,14 @@ $(BUILD_DIR)/run-tests.php: $(if $(ASSUME_COMPILED),, $(BUILD_DIR)/configure)
$(if $(ASSUME_COMPILED), cp $(shell dirname $(shell realpath $(shell which phpize)))/../lib/php/build/run-tests.php $(BUILD_DIR)/run-tests.php)
sed -i 's/\bdl(/(bool)(/' $(BUILD_DIR)/run-tests.php # this dl() stuff in run-tests.php is for --EXTENSIONS-- sections, which we don't use; just strip it away (see https://github.com/php/php-src/issues/15367)

$(BUILD_DIR)/Makefile: $(BUILD_DIR)/configure
# ensure list of rust files is up to date
$(BUILD_DIR)/.rust_files_list: $(RUST_FILES)
$(Q) printf '%s\n' $(RUST_FILES) | sort > $(BUILD_DIR)/.rust_files_list.tmp
$(Q) cmp -s $(BUILD_DIR)/.rust_files_list $(BUILD_DIR)/.rust_files_list.tmp 2>/dev/null \
&& rm -f $(BUILD_DIR)/.rust_files_list.tmp \
|| mv $(BUILD_DIR)/.rust_files_list.tmp $(BUILD_DIR)/.rust_files_list

$(BUILD_DIR)/Makefile: $(BUILD_DIR)/configure $(BUILD_DIR)/.rust_files_list
$(Q) (cd $(BUILD_DIR); $(if $(ASAN),CFLAGS="${CFLAGS} -DZEND_TRACK_ARENA_ALLOC") ./configure --$(if $(RUST_DEBUG_BUILD),enable,disable)-ddtrace-rust-debug $(if $(ASAN), --enable-ddtrace-sanitize) $(EXTRA_CONFIGURE_OPTIONS))

$(SO_FILE): $(if $(ASSUME_COMPILED),, $(ALL_OBJECT_FILES) $(BUILD_DIR)/compile_rust.sh)
Expand Down
30 changes: 17 additions & 13 deletions components-rs/common.h
Original file line number Diff line number Diff line change
Expand Up @@ -429,13 +429,10 @@ typedef struct ddog_RemoteConfigState ddog_RemoteConfigState;
typedef struct ddog_SidecarActionsBuffer ddog_SidecarActionsBuffer;

/**
* `SidecarTransport` is a wrapper around a BlockingTransport struct from the `datadog_ipc` crate
* that handles transparent reconnection.
* It is used for sending `SidecarInterfaceRequest` and receiving `SidecarInterfaceResponse`.
* `SidecarTransport` wraps a [`SidecarSender`] with transparent reconnection support.
*
* This transport is used for communication between different parts of the sidecar service.
* It is a blocking transport, meaning that it will block the current thread until the operation is
* complete.
* It is a blocking transport (all operations block the current thread).
*/
typedef struct ddog_SidecarTransport ddog_SidecarTransport;

Expand Down Expand Up @@ -1388,6 +1385,14 @@ typedef struct ddog_crasht_Slice_CInt {
uintptr_t len;
} ddog_crasht_Slice_CInt;

/**
* Represents an object that should only be referred to by its handle.
* Do not access its member for any reason, only use the C API functions on this struct.
*/
typedef struct ddog_crasht_Handle_StackTrace {
struct ddog_crasht_StackTrace *inner;
} ddog_crasht_Handle_StackTrace;

/**
* A generic result type for when an operation may fail,
* or may return <T> in case of success.
Expand Down Expand Up @@ -1493,14 +1498,6 @@ typedef struct ddog_crasht_Span {
ddog_CharSlice thread_name;
} ddog_crasht_Span;

/**
* Represents an object that should only be referred to by its handle.
* Do not access its member for any reason, only use the C API functions on this struct.
*/
typedef struct ddog_crasht_Handle_StackTrace {
struct ddog_crasht_StackTrace *inner;
} ddog_crasht_Handle_StackTrace;

typedef struct ddog_crasht_ThreadData {
bool crashed;
ddog_CharSlice name;
Expand Down Expand Up @@ -1875,6 +1872,13 @@ void ddog_endpoint_set_timeout(struct ddog_Endpoint *endpoint, uint64_t millis);

void ddog_endpoint_set_test_token(struct ddog_Endpoint *endpoint, ddog_CharSlice token);

/**
* Set whether to use the system DNS resolver when building the reqwest client.
* If false, the default in-process resolver is used.
*/
void ddog_endpoint_set_use_system_resolver(struct ddog_Endpoint *endpoint,
bool use_system_resolver);

void ddog_endpoint_drop(struct ddog_Endpoint*);

struct ddog_Option_U32 ddog_Option_U32_some(uint32_t v);
Expand Down
46 changes: 45 additions & 1 deletion components-rs/crashtracker.h
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,45 @@ struct ddog_VoidResult ddog_crasht_init_without_receiver(struct ddog_crasht_Conf
*/
struct ddog_crasht_Slice_CInt ddog_crasht_default_signals(void);

/**
* Report an unhandled exception as a crash event.
*
* This function sends a crash report for an unhandled exception detected
* by the runtime. It is intended to be called when the process is in a
* terminal state due to an unhandled exception.
*
* # Parameters
* - `error_type`: Optional type/class of the exception (e.g. "NullPointerException"). Pass empty
* CharSlice for unknown.
* - `error_message`: Optional error message. Pass empty CharSlice for no message.
* - `runtime_stack`: Stack trace from the runtime. Consumed by this call.
*
* If the crash-tracker has not been initialized, this function is a no-op.
*
* # Side effects
* This function disables the signal-based crash handler before performing
* any work. This means that if the process receives a fatal signal (SIGSEGV)
* during or after this call, the crashtracker will not produce a
* second crash report. The previous signal handler (if any) will still be
* chained.
*
* # Failure mode
* If a fatal signal occurs while this function is in progress, the calling
* process is in an unrecoverable state; the crashtracker cannot report the
* secondary fault and the caller's own signal handler (if any) will execute
* in a potentially corrupted context. Callers should treat this function as a
* terminal operation and exit shortly after it returns.
*
* # Safety
* Crash-tracking functions are not reentrant.
* No other crash-handler functions should be called concurrently.
* The `runtime_stack` handle must be valid and will be consumed.
*/
DDOG_CHECK_RETURN
struct ddog_VoidResult ddog_crasht_report_unhandled_exception(ddog_CharSlice error_type,
ddog_CharSlice error_message,
struct ddog_crasht_Handle_StackTrace *runtime_stack);

/**
* Removes all existing additional tags
* Expected to be used after a fork, to reset the additional tags on the child
Expand Down Expand Up @@ -661,7 +700,12 @@ struct ddog_VoidResult ddog_crasht_CrashInfoBuilder_with_thread_name(struct ddog
* The `builder` can be null, but if non-null it must point to a Builder made by this module,
* which has not previously been dropped.
* All arguments must be valid.
* This method requires that the builder has a UUID and metadata set
* This method requires that the builder has `metadata` and `kind` set
* Applications can add `message` or `sig_info` to the builder to provide additional context.
* If set, the data will be used to derive the crash ping message in the order of
* - an explicit message set with `with_message`
* - sig_info set with `with_sig_info`
* - kind set with `with_kind`
*/
DDOG_CHECK_RETURN
struct ddog_VoidResult ddog_crasht_CrashInfoBuilder_upload_ping_to_endpoint(struct ddog_crasht_Handle_CrashInfoBuilder *builder,
Expand Down
12 changes: 7 additions & 5 deletions components-rs/ddtrace.h
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,9 @@ ddog_MaybeError ddog_sidecar_connect_php(struct ddog_SidecarTransport **connecti
ddog_CharSlice log_level,
bool enable_telemetry,
void (*on_reconnect)(struct ddog_SidecarTransport*),
const struct ddog_Endpoint *crashtracker_endpoint);
const struct ddog_Endpoint *crashtracker_endpoint,
uint64_t backpressure_bytes,
uint64_t backpressure_queue);

void ddtrace_sidecar_reconnect(struct ddog_SidecarTransport **transport,
struct ddog_SidecarTransport *(*factory)(void));
Expand Down Expand Up @@ -155,10 +157,10 @@ ddog_MaybeError ddog_sidecar_telemetry_buffer_flush(struct ddog_SidecarTransport
const ddog_QueueId *queue_id,
struct ddog_SidecarActionsBuffer *buffer);

void ddog_sidecar_telemetry_register_metric_buffer(struct ddog_SidecarActionsBuffer *buffer,
ddog_CharSlice metric_name,
enum ddog_MetricType metric_type,
enum ddog_MetricNamespace namespace_);
ddog_MaybeError ddog_sidecar_telemetry_register_metric(struct ddog_SidecarTransport **transport,
ddog_CharSlice metric_name,
enum ddog_MetricType metric_type,
enum ddog_MetricNamespace namespace_);

void ddog_sidecar_telemetry_add_span_metric_point_buffer(struct ddog_SidecarActionsBuffer *buffer,
ddog_CharSlice metric_name,
Expand Down
4 changes: 1 addition & 3 deletions components-rs/sidecar.h
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ ddog_MaybeError ddog_sidecar_session_set_config(struct ddog_SidecarTransport **t
uintptr_t force_drop_size,
ddog_CharSlice log_level,
ddog_CharSlice log_path,
void *remote_config_notify_function,
void *_remote_config_notify_function,
const enum ddog_RemoteConfigProduct *remote_config_products,
uintptr_t remote_config_products_count,
const enum ddog_RemoteConfigCapabilities *remote_config_capabilities,
Expand All @@ -207,7 +207,6 @@ ddog_MaybeError ddog_sidecar_session_set_config(struct ddog_SidecarTransport **t
* Updates the process_tags for an existing session.
*/
ddog_MaybeError ddog_sidecar_session_set_process_tags(struct ddog_SidecarTransport **transport,
ddog_CharSlice session_id,
ddog_CharSlice process_tags);

/**
Expand Down Expand Up @@ -361,7 +360,6 @@ ddog_MaybeError ddog_sidecar_dogstatsd_set(struct ddog_SidecarTransport **transp
* Sets x-datadog-test-session-token on all requests for the given session.
*/
ddog_MaybeError ddog_sidecar_set_test_session_token(struct ddog_SidecarTransport **transport,
ddog_CharSlice session_id,
ddog_CharSlice token);

/**
Expand Down
5 changes: 5 additions & 0 deletions components-rs/sidecar.rs
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,8 @@ pub extern "C" fn ddog_sidecar_connect_php(
enable_telemetry: bool,
on_reconnect: Option<extern "C" fn(*mut SidecarTransport)>,
crashtracker_endpoint: Option<&Endpoint>,
backpressure_bytes: u64,
backpressure_queue: u64,
) -> MaybeError {
let mut cfg = config::FromEnv::config();
cfg.self_telemetry = enable_telemetry;
Expand Down Expand Up @@ -151,6 +153,8 @@ pub extern "C" fn ddog_sidecar_connect_php(
cfg.child_env.insert(OsStr::new("DD_TRACE_LOG_LEVEL").into(), log_level);
}

cfg.pipe_buffer_size = backpressure_bytes as usize;

let reconnect_fn = on_reconnect.map(|on_reconnect| {
let cfg = cfg.clone();
Box::new(move || {
Expand All @@ -162,6 +166,7 @@ pub extern "C" fn ddog_sidecar_connect_php(

let mut stream = try_c!(sidecar_connect(cfg));
stream.reconnect_fn = reconnect_fn;
let _ = stream.set_backpressure(backpressure_bytes as usize, backpressure_queue);
*connection = Box::into_raw(stream);

MaybeError::None
Expand Down
18 changes: 10 additions & 8 deletions components-rs/telemetry.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use hashbrown::{Equivalent, HashMap};
use std::collections::HashSet;
use std::ffi::CString;
use std::path::PathBuf;
use std::time::{Duration, Instant, SystemTime};
use std::time::{Duration, SystemTime};

use datadog_ipc::platform::NamedShmHandle;
use datadog_sidecar::one_way_shared_memory::{open_named_shm, OneWayShmReader};
Expand Down Expand Up @@ -168,21 +168,23 @@ pub extern "C-unwind" fn ddog_sidecar_telemetry_buffer_flush(
}

#[no_mangle]
pub unsafe extern "C" fn ddog_sidecar_telemetry_register_metric_buffer(
buffer: &mut SidecarActionsBuffer,
pub unsafe extern "C" fn ddog_sidecar_telemetry_register_metric(
transport: &mut Box<SidecarTransport>,
metric_name: CharSlice,
metric_type: MetricType,
namespace: MetricNamespace,
) {
buffer
.buffer
.push(SidecarAction::RegisterTelemetryMetric(MetricContext {
) -> MaybeError {
try_c!(blocking::register_telemetry_metric(
transport,
MetricContext {
name: metric_name.to_utf8_lossy().into_owned(),
namespace,
metric_type,
tags: Vec::default(),
common: true,
}));
},
));
MaybeError::None
}

#[no_mangle]
Expand Down
2 changes: 2 additions & 0 deletions ext/configuration.h
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,8 @@ enum ddtrace_sampling_rules_format {
CONFIG(INT, DD_TRACE_AGENT_MAX_PAYLOAD_SIZE, "52428800", .ini_change = zai_config_system_ini_change) \
CONFIG(INT, DD_TRACE_AGENT_STACK_INITIAL_SIZE, "131072", .ini_change = zai_config_system_ini_change) \
CONFIG(INT, DD_TRACE_AGENT_STACK_BACKLOG, "12", .ini_change = zai_config_system_ini_change) \
CONFIG(INT, DD_TRACE_SIDECAR_BACKPRESSURE_BYTES, "4194304", .ini_change = zai_config_system_ini_change) \
CONFIG(INT, DD_TRACE_SIDECAR_BACKPRESSURE_QUEUE, "100", .ini_change = zai_config_system_ini_change) \
CONFIG(STRING, DD_TRACE_AGENT_TEST_SESSION_TOKEN, "", .ini_change = ddtrace_alter_test_session_token) \
CONFIG(BOOL, DD_TRACE_PROPAGATE_USER_ID_DEFAULT, "false") \
CONFIG(CUSTOM(INT), DD_DBM_PROPAGATION_MODE, "disabled", .parser = dd_parse_dbm_mode) \
Expand Down
3 changes: 1 addition & 2 deletions ext/otel_config.c
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,8 @@ ZEND_EXTERN_MODULE_GLOBALS(ddtrace);

static void report_otel_cfg_telemetry_invalid(const char *otel_cfg, const char *dd_cfg, bool pre_rinit) {
if (!pre_rinit && ddtrace_sidecar && get_DD_INSTRUMENTATION_TELEMETRY_ENABLED()) {
ddog_sidecar_telemetry_register_metric(&ddtrace_sidecar, DDOG_CHARSLICE_C("otel.env.invalid"), DDOG_METRIC_TYPE_COUNT, DDOG_METRIC_NAMESPACE_TRACERS);
ddog_SidecarActionsBuffer *buffer = ddtrace_telemetry_buffer();
ddog_sidecar_telemetry_register_metric_buffer(buffer, DDOG_CHARSLICE_C("otel.env.invalid"), DDOG_METRIC_TYPE_COUNT,
DDOG_METRIC_NAMESPACE_TRACERS);
ddog_CharSlice tags;
tags.len = asprintf((char **)&tags.ptr, "config_opentelemetry:%s,config_datadog:%s", otel_cfg, dd_cfg);
ddog_sidecar_telemetry_add_span_metric_point_buffer(buffer, DDOG_CHARSLICE_C("otel.env.invalid"), 1, tags);
Expand Down
8 changes: 3 additions & 5 deletions ext/sidecar.c
Original file line number Diff line number Diff line change
Expand Up @@ -129,8 +129,7 @@ void ddtrace_sidecar_update_process_tags(void) {
return;
}

ddog_CharSlice session_id = (ddog_CharSlice) {.ptr = (char *) dd_sidecar_formatted_session_id, .len = sizeof(dd_sidecar_formatted_session_id)};
ddog_sidecar_session_set_process_tags(&ddtrace_sidecar, session_id, dd_zend_string_to_CharSlice(process_tags));
ddog_sidecar_session_set_process_tags(&ddtrace_sidecar, dd_zend_string_to_CharSlice(process_tags));
}

static void dd_sidecar_on_reconnect(ddog_SidecarTransport *transport) {
Expand Down Expand Up @@ -208,7 +207,7 @@ static ddog_SidecarTransport *dd_sidecar_connection_factory_ex(bool is_fork) {
}

ddog_SidecarTransport *sidecar_transport;
if (!ddtrace_ffi_try("Failed connecting to the sidecar", ddog_sidecar_connect_php(&sidecar_transport, logpath, dd_zend_string_to_CharSlice(get_global_DD_TRACE_LOG_LEVEL()), get_global_DD_INSTRUMENTATION_TELEMETRY_ENABLED(), dd_sidecar_on_reconnect, ddtrace_endpoint))) {
if (!ddtrace_ffi_try("Failed connecting to the sidecar", ddog_sidecar_connect_php(&sidecar_transport, logpath, dd_zend_string_to_CharSlice(get_global_DD_TRACE_LOG_LEVEL()), get_global_DD_INSTRUMENTATION_TELEMETRY_ENABLED(), dd_sidecar_on_reconnect, ddtrace_endpoint, (uint64_t)get_global_DD_TRACE_SIDECAR_BACKPRESSURE_BYTES(), (uint64_t)get_global_DD_TRACE_SIDECAR_BACKPRESSURE_QUEUE()))) {
dd_free_endpoints();
return NULL;
}
Expand Down Expand Up @@ -632,9 +631,8 @@ bool ddtrace_alter_test_session_token(zval *old_value, zval *new_value, zend_str
UNUSED(old_value, new_str);
if (ddtrace_sidecar) {
ddog_endpoint_set_test_token(ddtrace_endpoint, dd_zend_string_to_CharSlice(Z_STR_P(new_value)));
ddog_CharSlice session_id = (ddog_CharSlice) {.ptr = (char *) dd_sidecar_formatted_session_id, .len = sizeof(dd_sidecar_formatted_session_id)};
ddtrace_ffi_try("Failed updating test session token",
ddog_sidecar_set_test_session_token(&ddtrace_sidecar, session_id, dd_zend_string_to_CharSlice(Z_STR_P(new_value))));
ddog_sidecar_set_test_session_token(&ddtrace_sidecar, dd_zend_string_to_CharSlice(Z_STR_P(new_value))));
}
#ifndef _WIN32
ddtrace_coms_set_test_session_token(Z_STRVAL_P(new_value), Z_STRLEN_P(new_value));
Expand Down
Loading
Loading