Skip to content

Commit ddf48a3

Browse files
make exception message collection optional and default disable
1 parent b62bd07 commit ddf48a3

File tree

3 files changed

+49
-8
lines changed

3 files changed

+49
-8
lines changed

profiling/src/config.rs

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ pub struct SystemSettings {
2525
pub profiling_allocation_enabled: bool,
2626
pub profiling_timeline_enabled: bool,
2727
pub profiling_exception_enabled: bool,
28+
pub profiling_exception_message_enabled: bool,
2829

2930
// todo: can't this be Option<String>? I don't think the string can ever be static.
3031
pub output_pprof: Option<Cow<'static, str>>,
@@ -42,6 +43,7 @@ impl SystemSettings {
4243
self.profiling_allocation_enabled = false;
4344
self.profiling_timeline_enabled = false;
4445
self.profiling_exception_enabled = false;
46+
self.profiling_exception_message_enabled = false;
4547
}
4648

4749
/// # Safety
@@ -62,6 +64,7 @@ impl SystemSettings {
6264
profiling_allocation_enabled: profiling_allocation_enabled(),
6365
profiling_timeline_enabled: profiling_timeline_enabled(),
6466
profiling_exception_enabled: profiling_exception_enabled(),
67+
profiling_exception_message_enabled: profiling_exception_message_enabled(),
6568
output_pprof: profiling_output_pprof(),
6669
profiling_exception_sampling_distance: profiling_exception_sampling_distance(),
6770
profiling_log_level: profiling_log_level(),
@@ -122,6 +125,7 @@ impl SystemSettings {
122125
profiling_allocation_enabled: false,
123126
profiling_timeline_enabled: false,
124127
profiling_exception_enabled: false,
128+
profiling_exception_message_enabled: false,
125129
output_pprof: None,
126130
profiling_exception_sampling_distance: 0,
127131
profiling_log_level: LevelFilter::Off,
@@ -138,6 +142,7 @@ impl SystemSettings {
138142
system_settings.profiling_allocation_enabled = false;
139143
system_settings.profiling_timeline_enabled = false;
140144
system_settings.profiling_exception_enabled = false;
145+
system_settings.profiling_exception_message_enabled = false;
141146
}
142147
}
143148

@@ -332,6 +337,7 @@ pub(crate) enum ConfigId {
332337
ProfilingAllocationEnabled,
333338
ProfilingTimelineEnabled,
334339
ProfilingExceptionEnabled,
340+
ProfilingExceptionMessageEnabled,
335341
ProfilingExceptionSamplingDistance,
336342
ProfilingLogLevel,
337343
ProfilingOutputPprof,
@@ -358,6 +364,7 @@ impl ConfigId {
358364
ProfilingAllocationEnabled => b"DD_PROFILING_ALLOCATION_ENABLED\0",
359365
ProfilingTimelineEnabled => b"DD_PROFILING_TIMELINE_ENABLED\0",
360366
ProfilingExceptionEnabled => b"DD_PROFILING_EXCEPTION_ENABLED\0",
367+
ProfilingExceptionMessageEnabled => b"DD_PROFILING_EXCEPTION_MESSAGE_ENABLED\0",
361368
ProfilingExceptionSamplingDistance => b"DD_PROFILING_EXCEPTION_SAMPLING_DISTANCE\0",
362369
ProfilingLogLevel => b"DD_PROFILING_LOG_LEVEL\0",
363370

@@ -400,6 +407,7 @@ lazy_static::lazy_static! {
400407
profiling_allocation_enabled: false,
401408
profiling_timeline_enabled: false,
402409
profiling_exception_enabled: false,
410+
profiling_exception_message_enabled: false,
403411
output_pprof: None,
404412
profiling_exception_sampling_distance: u32::MAX,
405413
profiling_log_level: LevelFilter::Off,
@@ -415,6 +423,7 @@ lazy_static::lazy_static! {
415423
profiling_allocation_enabled: true,
416424
profiling_timeline_enabled: true,
417425
profiling_exception_enabled: true,
426+
profiling_exception_message_enabled: false,
418427
output_pprof: None,
419428
profiling_exception_sampling_distance: 100,
420429
profiling_log_level: LevelFilter::Off,
@@ -496,6 +505,16 @@ unsafe fn profiling_exception_enabled() -> bool {
496505
)
497506
}
498507

508+
/// # Safety
509+
/// This function must only be called after config has been initialized in
510+
/// rinit, and before it is uninitialized in mshutdown.
511+
unsafe fn profiling_exception_message_enabled() -> bool {
512+
get_system_bool(
513+
ProfilingExceptionMessageEnabled,
514+
DEFAULT_SYSTEM_SETTINGS.profiling_exception_message_enabled,
515+
)
516+
}
517+
499518
/// # Safety
500519
/// This function must only be called after config has been initialized in
501520
/// rinit, and before it is uninitialized in mshutdown.
@@ -811,6 +830,16 @@ pub(crate) fn minit(module_number: libc::c_int) {
811830
ini_change: Some(zai_config_system_ini_change),
812831
parser: None,
813832
},
833+
zai_config_entry {
834+
id: transmute(ProfilingExceptionMessageEnabled),
835+
name: ProfilingExceptionMessageEnabled.env_var_name(),
836+
type_: ZAI_CONFIG_TYPE_BOOL,
837+
default_encoded_value: ZaiStr::literal(b"0\0"),
838+
aliases: ptr::null_mut(),
839+
aliases_count: 0,
840+
ini_change: Some(zai_config_system_ini_change),
841+
parser: None,
842+
},
814843
zai_config_entry {
815844
id: transmute(ProfilingExceptionSamplingDistance),
816845
name: ProfilingExceptionSamplingDistance.env_var_name(),

profiling/src/exception.rs

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -60,13 +60,23 @@ impl ExceptionProfilingStats {
6060
#[cfg(php8)]
6161
let exception_name = unsafe { (*exception).class_name() };
6262

63-
let message = unsafe {
63+
let collect_message = REQUEST_LOCALS.with(|cell| {
64+
cell.try_borrow()
65+
.map(|locals| locals.system_settings().profiling_exception_message_enabled)
66+
.unwrap_or(false)
67+
});
68+
69+
let message = if collect_message {
6470
#[cfg(php7)]
6571
let exception_obj = (*exception).value.obj;
6672
#[cfg(php8)]
6773
let exception_obj = exception;
68-
zend::zai_str_from_zstr(zend::zai_exception_message(exception_obj).as_mut())
69-
.into_string()
74+
Some(unsafe {
75+
zend::zai_str_from_zstr(zend::zai_exception_message(exception_obj).as_mut())
76+
.into_string()
77+
})
78+
} else {
79+
None
7080
};
7181

7282
self.next_sampling_interval();

profiling/src/profiling/mod.rs

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -758,7 +758,7 @@ impl Profiler {
758758
&self,
759759
execute_data: *mut zend_execute_data,
760760
exception: String,
761-
message: String,
761+
message: Option<String>,
762762
) {
763763
let result = collect_stack_sample(execute_data);
764764
match result {
@@ -771,10 +771,12 @@ impl Profiler {
771771
value: LabelValue::Str(exception.clone().into()),
772772
});
773773

774-
labels.push(Label {
775-
key: "exception message",
776-
value: LabelValue::Str(message.into()),
777-
});
774+
if message.is_some() {
775+
labels.push(Label {
776+
key: "exception message",
777+
value: LabelValue::Str(message.unwrap().into()),
778+
});
779+
}
778780

779781
let n_labels = labels.len();
780782

0 commit comments

Comments
 (0)