From 5334fb55ab669081abab950bf812fdd81cb84d6d Mon Sep 17 00:00:00 2001 From: Florian Engelhardt Date: Tue, 16 Jan 2024 23:01:01 +0100 Subject: [PATCH] fix(profiler) prevent emitting empty profiles (#2397) * panic! * do not send empty samples to the other thread * ignore empty samples in sampling thread * Update profiling/src/profiling/mod.rs Co-authored-by: Levi Morrison * if profiling is disabled, we do not need any other checks --------- Co-authored-by: Levi Morrison --- profiling/src/profiling/mod.rs | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/profiling/src/profiling/mod.rs b/profiling/src/profiling/mod.rs index bf0ab395b6..f214ed2561 100644 --- a/profiling/src/profiling/mod.rs +++ b/profiling/src/profiling/mod.rs @@ -346,6 +346,12 @@ impl TimeCollector { profiles: &mut HashMap, started_at: &WallTime, ) { + if message.key.sample_types.len() == 0 { + // profiling disabled, this should not happen! + warn!("A sample with no sample types was recorded in the profiler. Please report this to Datadog."); + return; + } + let profile: &mut InternalProfile = if let Some(value) = profiles.get_mut(&message.key) { value } else { @@ -1034,6 +1040,7 @@ impl Profiler { let mut sample_types = Vec::with_capacity(SAMPLE_TYPES.len()); let mut sample_values = Vec::with_capacity(SAMPLE_TYPES.len()); + if locals.profiling_enabled { // sample, wall-time, cpu-time let len = 2 + locals.profiling_experimental_cpu_time_enabled as usize;