Skip to content

Commit a57fbfa

Browse files
committed
More exception replay stuff
Signed-off-by: Bob Weinand <[email protected]>
1 parent 5960e70 commit a57fbfa

24 files changed

Lines changed: 766 additions & 527 deletions

components-rs/ddtrace.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,8 @@ void ddog_reset_logger(void);
166166
uint32_t ddog_get_logs_count(ddog_CharSlice level);
167167

168168
struct ddog_RemoteConfigState *ddog_init_remote_config(ddog_CharSlice tracer_version,
169-
const struct ddog_Endpoint *endpoint);
169+
const struct ddog_Endpoint *endpoint,
170+
bool live_debugging_enabled);
170171

171172
void ddog_process_remote_configs(struct ddog_RemoteConfigState *remote_config);
172173

@@ -222,6 +223,8 @@ void ddtrace_sidecar_reconnect(struct ddog_SidecarTransport **transport,
222223

223224
bool ddog_shm_limiter_inc(const struct ddog_MaybeShmLimiter *limiter, uint32_t limit);
224225

226+
bool ddog_exception_hash_limiter_inc(struct ddog_SidecarTransport *connection, uint64_t hash);
227+
225228
bool ddtrace_detect_composer_installed_json(struct ddog_SidecarTransport **transport,
226229
const struct ddog_InstanceId *instance_id,
227230
const ddog_QueueId *queue_id,

components-rs/live-debugger.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,8 @@ ddog_DebuggerCapture *ddog_create_exception_snapshot(struct ddog_Vec_DebuggerPay
4444
ddog_CharSlice language,
4545
ddog_CharSlice id,
4646
ddog_CharSlice exception_id,
47+
ddog_CharSlice exception_hash,
48+
uint32_t frame_index,
4749
uint64_t timestamp);
4850

4951
struct ddog_DebuggerPayload *ddog_create_log_probe_snapshot(const struct ddog_Probe *probe,

components-rs/remote_config.rs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,13 +86,19 @@ pub struct LiveDebuggerState {
8686
pub unsafe extern "C" fn ddog_init_remote_config(
8787
tracer_version: CharSlice,
8888
endpoint: &Endpoint,
89+
live_debugging_enabled: bool,
8990
) -> Box<RemoteConfigState> {
91+
let mut products = vec![RemoteConfigProduct::ApmTracing];
92+
if live_debugging_enabled {
93+
products.push(RemoteConfigProduct::LiveDebugger);
94+
}
95+
9096
Box::new(RemoteConfigState {
9197
manager: RemoteConfigManager::new(ConfigInvariants {
9298
language: "php".to_string(),
9399
tracer_version: tracer_version.to_utf8_lossy().into(),
94100
endpoint: endpoint.clone(),
95-
products: DDTRACE_REMOTE_CONFIG_PRODUCTS.to_vec(),
101+
products,
96102
capabilities: DDTRACE_REMOTE_CONFIG_CAPABILITIES.to_vec(),
97103
}),
98104
live_debugger: LiveDebuggerState::default(),

components-rs/sidecar.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,7 @@ ddog_MaybeError ddog_sidecar_session_set_config(struct ddog_SidecarTransport **t
169169
ddog_CharSlice tracer_version,
170170
uint32_t flush_interval_milliseconds,
171171
uint32_t telemetry_heartbeat_interval_millis,
172+
uint32_t exception_hash_rate_limiter_seconds,
172173
uintptr_t force_flush_size,
173174
uintptr_t force_drop_size,
174175
ddog_CharSlice log_level,

components-rs/sidecar.rs

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,10 @@ use tracing::warn;
88
use std::os::windows::ffi::OsStrExt;
99
use std::sync::Mutex;
1010
use datadog_sidecar::config::{self, AppSecConfig, LogMethod};
11-
use datadog_sidecar::service::blocking::SidecarTransport;
11+
use datadog_sidecar::service::blocking::{acquire_exception_hash_rate_limiter, SidecarTransport};
1212
use ddcommon::rate_limiter::{Limiter, LocalLimiter};
1313
use datadog_ipc::rate_limiter::{AnyLimiter, ShmLimiterMemory};
14+
use datadog_sidecar::service::exception_hash_rate_limiter::ExceptionHashRateLimiter;
1415
use datadog_sidecar::tracer::shm_limiter_path;
1516
use ddcommon_ffi::slice::AsBytes;
1617
use ddcommon_ffi::{CharSlice, self as ffi, MaybeError};
@@ -158,6 +159,11 @@ lazy_static! {
158159
warn!("Attempt to use the SHM_LIMITER failed: {e:?}");
159160
None
160161
}, Some);
162+
163+
pub static ref EXCEPTION_HASH_LIMITER: Option<ExceptionHashRateLimiter> = ExceptionHashRateLimiter::open().map_or_else(|e| {
164+
warn!("Attempt to use the EXCEPTION_HASH_LIMITER failed: {e:?}");
165+
None
166+
}, Some);
161167
}
162168

163169
pub struct MaybeShmLimiter(Option<AnyLimiter>);
@@ -187,3 +193,14 @@ impl MaybeShmLimiter {
187193
pub extern "C" fn ddog_shm_limiter_inc(limiter: &MaybeShmLimiter, limit: u32) -> bool {
188194
limiter.inc(limit)
189195
}
196+
197+
#[no_mangle]
198+
pub extern "C" fn ddog_exception_hash_limiter_inc(connection: &mut SidecarTransport, hash: u64) -> bool {
199+
if let Some(limiter) = &*EXCEPTION_HASH_LIMITER {
200+
if let Some(limiter) = limiter.find(hash) {
201+
return limiter.inc();
202+
}
203+
}
204+
let _ = acquire_exception_hash_rate_limiter(connection, hash);
205+
true
206+
}

config.m4

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,7 @@ if test "$PHP_DDTRACE" != "no"; then
152152
ext/dogstatsd_client.c \
153153
ext/engine_api.c \
154154
ext/engine_hooks.c \
155+
ext/exception_serialize.c \
155156
ext/excluded_modules.c \
156157
ext/git.c \
157158
ext/handlers_api.c \

config.w32

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ if (PHP_DDTRACE != 'no') {
2626
DDTRACE_EXT_SOURCES += " dogstatsd.c";
2727
DDTRACE_EXT_SOURCES += " engine_api.c";
2828
DDTRACE_EXT_SOURCES += " engine_hooks.c";
29+
DDTRACE_EXT_SOURCES += " exception_serialize.c";
2930
DDTRACE_EXT_SOURCES += " excluded_modules.c";
3031
DDTRACE_EXT_SOURCES += " git.c";
3132
DDTRACE_EXT_SOURCES += " handlers_api.c";

ext/configuration.h

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -124,9 +124,9 @@ enum ddtrace_sampling_rules_format {
124124
CONFIG(BOOL, DD_TRACE_DB_CLIENT_SPLIT_BY_INSTANCE, "false") \
125125
CONFIG(BOOL, DD_TRACE_HTTP_CLIENT_SPLIT_BY_DOMAIN, "false") \
126126
CONFIG(BOOL, DD_TRACE_REDIS_CLIENT_SPLIT_BY_HOST, "false") \
127-
CONFIG(BOOL, DD_EXCEPTION_DEBUGGING_ENABLED, "false") \
128-
CONFIG(BOOL, DD_EXCEPTION_DEBUGGING_CAPTURE_FULL_CALLSTACK, "true") \
129-
CONFIG(INT, DD_EXCEPTION_DEBUGGING_MAX_FRAMES_TO_CAPTURE, "0") \
127+
CONFIG(BOOL, DD_EXCEPTION_REPLAY_ENABLED, "false") \
128+
CONFIG(INT, DD_EXCEPTION_REPLAY_MAX_FRAMES_TO_CAPTURE, "-1") \
129+
CONFIG(INT, DD_EXCEPTION_REPLAY_RATE_LIMIT_SECONDS, "3600", .ini_change = zai_config_system_ini_change) \
130130
CONFIG(STRING, DD_TRACE_MEMORY_LIMIT, "") \
131131
CONFIG(BOOL, DD_TRACE_REPORT_HOSTNAME, "false") \
132132
CONFIG(BOOL, DD_TRACE_FLUSH_COLLECT_CYCLES, "false") \
@@ -165,7 +165,7 @@ enum ddtrace_sampling_rules_format {
165165
CONFIG(INT, DD_TRACE_AGENT_CONNECT_TIMEOUT, DD_CFG_EXPSTR(DD_TRACE_AGENT_CONNECT_TIMEOUT_VAL), \
166166
.ini_change = zai_config_system_ini_change) \
167167
CONFIG(INT, DD_TRACE_DEBUG_PRNG_SEED, "-1", .ini_change = ddtrace_reseed_seed_change) \
168-
CONFIG(BOOL, DD_LOG_BACKTRACE, "true") \
168+
CONFIG(BOOL, DD_LOG_BACKTRACE, "true") \
169169
CONFIG(BOOL, DD_TRACE_GENERATE_ROOT_SPAN, "true", .ini_change = ddtrace_span_alter_root_span_config) \
170170
CONFIG(INT, DD_TRACE_SPANS_LIMIT, "1000") \
171171
CONFIG(BOOL, DD_TRACE_128_BIT_TRACEID_GENERATION_ENABLED, "true") \
@@ -223,6 +223,9 @@ enum ddtrace_sampling_rules_format {
223223
CONFIG(INT, DD_OPENAI_SPAN_CHAR_LIMIT, "128") \
224224
CONFIG(DOUBLE, DD_OPENAI_SPAN_PROMPT_COMPLETION_SAMPLE_RATE, "1.0") \
225225
CONFIG(DOUBLE, DD_OPENAI_LOG_PROMPT_COMPLETION_SAMPLE_RATE, "0.1") \
226+
CONFIG(DOUBLE, DD_REMOTE_CONFIG_POLL_INTERVAL_SECONDS, "5", .ini_change = zai_config_system_ini_change) \
227+
CONFIG(BOOL, DD_REMOTE_CONFIGURATION_ENABLED, "true", .ini_change = zai_config_system_ini_change) \
228+
CONFIG(BOOL, DD_DYNAMIC_INSTRUMENTATION_ENABLED, "false", .ini_change = zai_config_system_ini_change) \
226229
CONFIG(SET, DD_DYNAMIC_INSTRUMENTATION_REDACTED_IDENTIFIERS, "", .ini_change = zai_config_system_ini_change) \
227230
CONFIG(SET, DD_DYNAMIC_INSTRUMENTATION_REDACTED_TYPES, "", .ini_change = zai_config_system_ini_change) \
228231
DD_INTEGRATIONS

ext/ddtrace.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1488,9 +1488,8 @@ static void dd_initialize_request(void) {
14881488
}
14891489
}
14901490

1491-
// TODO CONFIG option for RC
14921491
if (!DDTRACE_G(remote_config_state) && ddtrace_endpoint) {
1493-
DDTRACE_G(remote_config_state) = ddog_init_remote_config(DDOG_CHARSLICE_C(PHP_DDTRACE_VERSION), ddtrace_endpoint);
1492+
DDTRACE_G(remote_config_state) = ddog_init_remote_config(DDOG_CHARSLICE_C(PHP_DDTRACE_VERSION), ddtrace_endpoint, get_global_DD_DYNAMIC_INSTRUMENTATION_ENABLED());
14941493
}
14951494

14961495
if (DDTRACE_G(remote_config_state)) {

0 commit comments

Comments
 (0)