Skip to content

Commit

Permalink
feat: Tag "number of frames" metrics with platforms (#1562)
Browse files Browse the repository at this point in the history
Each count is tagged with the platform of the
individual frames as well as that of the
whole event.

As a drive-by, this also implements
`AsRef<str>` for the platform types.
  • Loading branch information
loewenheim authored Dec 2, 2024
1 parent 8faeb5c commit de05225
Show file tree
Hide file tree
Showing 7 changed files with 152 additions and 55 deletions.
34 changes: 28 additions & 6 deletions crates/symbolicator-js/src/metrics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,10 @@
//! - `js.scraped_files`: The number of files that were scraped from the Web.
//! Should be `0`, as we should find/use files from within bundles or as individual artifacts.
use std::collections::HashMap;

use symbolic::debuginfo::sourcebundle::SourceFileType;
use symbolicator_service::{metric, metrics};
use symbolicator_service::{metric, metrics, types::Platform};

use crate::interface::{JsStacktrace, ResolvedWith};

Expand Down Expand Up @@ -222,17 +224,37 @@ impl JsMetrics {

/// Record metrics about stacktraces and frames.
pub fn record_stacktrace_metrics(
event_platform: Option<Platform>,
stacktraces: &[JsStacktrace],
unsymbolicated_frames: u64,
missing_sourcescontent: u64,
) {
let event_platform = event_platform
.as_ref()
.map(|p| p.as_ref())
.unwrap_or("none");

metric!(time_raw("symbolication.num_stacktraces") = stacktraces.len() as u64);
metric!(
time_raw("symbolication.num_frames") = stacktraces
.iter()
.map(|s| s.frames.len() as u64)
.sum::<u64>()

// Count number of frames by platform (including no platform)
let frames_by_platform = stacktraces.iter().flat_map(|st| st.frames.iter()).fold(
HashMap::new(),
|mut map, frame| {
let platform = frame.platform.as_ref();
let count: &mut usize = map.entry(platform).or_default();
*count += 1;
map
},
);

for (p, count) in &frames_by_platform {
let frame_platform = p.map(|p| p.as_ref()).unwrap_or("none");
metric!(
time_raw("symbolication.num_frames") =
count,
"frame_platform" => frame_platform, "event_platform" => event_platform
);
}
metric!(time_raw("symbolication.unsymbolicated_frames") = unsymbolicated_frames);
metric!(time_raw("js.missing_sourcescontent") = missing_sourcescontent);
}
8 changes: 7 additions & 1 deletion crates/symbolicator-js/src/symbolication.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ impl SourceMapService {
) -> CompletedJsSymbolicationResponse {
let mut raw_stacktraces = std::mem::take(&mut request.stacktraces);
let apply_source_context = request.apply_source_context;
let platform = request.platform.clone();
let mut lookup = SourceMapLookup::new(self.clone(), request).await;
lookup.prepare_modules(&mut raw_stacktraces[..]);

Expand Down Expand Up @@ -71,7 +72,12 @@ impl SourceMapService {
}

lookup.record_metrics();
record_stacktrace_metrics(&stacktraces, unsymbolicated_frames, missing_sourcescontent);
record_stacktrace_metrics(
platform,
&stacktraces,
unsymbolicated_frames,
missing_sourcescontent,
);

let (used_artifact_bundles, scraping_attempts) = lookup.into_records();

Expand Down
61 changes: 42 additions & 19 deletions crates/symbolicator-native/src/metrics.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
use std::collections::HashMap;

use symbolic::common::DebugId;
use symbolicator_service::metric;
use symbolicator_service::types::ObjectFileStatus;
use symbolicator_service::{metric, types::Platform};
use symbolicator_sources::ObjectType;

use crate::interface::{CompleteObjectInfo, CompleteStacktrace};
Expand Down Expand Up @@ -83,14 +85,20 @@ pub struct StacktraceMetrics {
}

pub fn record_symbolication_metrics(
event_platform: Option<Platform>,
origin: StacktraceOrigin,
metrics: StacktraceMetrics,
modules: &[CompleteObjectInfo],
stacktraces: &[CompleteStacktrace],
) {
let origin = origin.to_string();

let platform = modules
let event_platform = event_platform
.as_ref()
.map(|p| p.as_ref())
.unwrap_or("none");

let object_platform = modules
.iter()
.find_map(|m| {
if m.raw.ty == ObjectType::Unknown {
Expand Down Expand Up @@ -133,64 +141,79 @@ pub fn record_symbolication_metrics(

metric!(
time_raw("symbolication.num_modules") = modules.len() as u64,
"platform" => &platform, "origin" => &origin
"platform" => &object_platform, "origin" => &origin
);
metric!(
time_raw("symbolication.unusable_modules") = unusable_modules,
"platform" => &platform, "origin" => &origin
"platform" => &object_platform, "origin" => &origin
);
metric!(
time_raw("symbolication.unparsable_modules") = unparsable_modules,
"platform" => &platform, "origin" => &origin
"platform" => &object_platform, "origin" => &origin
);

metric!(
time_raw("symbolication.num_stacktraces") = stacktraces.len() as u64,
"platform" => &platform, "origin" => &origin
"platform" => &object_platform, "origin" => &origin
);
metric!(
time_raw("symbolication.short_stacktraces") = metrics.short_traces,
"platform" => &platform, "origin" => &origin
"platform" => &object_platform, "origin" => &origin
);
metric!(
time_raw("symbolication.truncated_stacktraces") = metrics.truncated_traces,
"platform" => &platform, "origin" => &origin
"platform" => &object_platform, "origin" => &origin
);
metric!(
time_raw("symbolication.bad_stacktraces") = metrics.bad_traces,
"platform" => &platform, "origin" => &origin
"platform" => &object_platform, "origin" => &origin
);

metric!(
time_raw("symbolication.num_frames") =
stacktraces.iter().map(|s| s.frames.len() as u64).sum::<u64>(),
"platform" => &platform, "origin" => &origin
// Count number of frames by platform (including no platform)
let frames_by_platform = stacktraces.iter().flat_map(|st| st.frames.iter()).fold(
HashMap::new(),
|mut map, frame| {
let platform = frame.raw.platform.as_ref();
let count: &mut usize = map.entry(platform).or_default();
*count += 1;
map
},
);

for (p, count) in &frames_by_platform {
let frame_platform = p.map(|p| p.as_ref()).unwrap_or("none");
metric!(
time_raw("symbolication.num_frames") =
count,
"platform" => &object_platform, "origin" => &origin,
"frame_platform" => frame_platform, "event_platform" => event_platform
);
}
metric!(
time_raw("symbolication.scanned_frames") = metrics.scanned_frames,
"platform" => &platform, "origin" => &origin
"platform" => &object_platform, "origin" => &origin
);
metric!(
time_raw("symbolication.unsymbolicated_frames") = metrics.unsymbolicated_frames,
"platform" => &platform, "origin" => &origin
"platform" => &object_platform, "origin" => &origin
);
metric!(
time_raw("symbolication.unsymbolicated_context_frames") =
metrics.unsymbolicated_context_frames,
"platform" => &platform, "origin" => &origin
"platform" => &object_platform, "origin" => &origin
);
metric!(
time_raw("symbolication.unsymbolicated_cfi_frames") =
metrics.unsymbolicated_cfi_frames,
"platform" => &platform, "origin" => &origin
"platform" => &object_platform, "origin" => &origin
);
metric!(
time_raw("symbolication.unsymbolicated_scanned_frames") =
metrics.unsymbolicated_scanned_frames,
"platform" => &platform, "origin" => &origin
"platform" => &object_platform, "origin" => &origin
);
metric!(
time_raw("symbolication.unmapped_frames") = metrics.unmapped_frames,
"platform" => &platform, "origin" => &origin
"platform" => &object_platform, "origin" => &origin
);
}
3 changes: 2 additions & 1 deletion crates/symbolicator-native/src/symbolication/symbolicate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ impl SymbolicationActor {
request: SymbolicateStacktraces,
) -> anyhow::Result<CompletedSymbolicationResponse> {
let SymbolicateStacktraces {
platform,
stacktraces,
sources,
scope,
Expand Down Expand Up @@ -133,7 +134,7 @@ impl SymbolicationActor {

// bring modules back into the original order
let modules = module_lookup.into_inner();
record_symbolication_metrics(origin, metrics, &modules, &stacktraces);
record_symbolication_metrics(platform, origin, metrics, &modules, &stacktraces);

Ok(CompletedSymbolicationResponse {
signal,
Expand Down
32 changes: 26 additions & 6 deletions crates/symbolicator-proguard/src/metrics.rs
Original file line number Diff line number Diff line change
@@ -1,24 +1,44 @@
use std::{collections::HashMap, sync::Arc};

use symbolicator_service::metric;
use symbolicator_service::{metric, types::Platform};

use crate::interface::{JvmException, JvmStacktrace};

/// Record metrics about exceptions, stacktraces, frames, and remapped classes.
pub fn record_symbolication_metrics(
event_platform: Option<Platform>,
exceptions: &[JvmException],
stacktraces: &[JvmStacktrace],
classes: &HashMap<Arc<str>, Arc<str>>,
unsymbolicated_frames: u64,
) {
let event_platform = event_platform
.as_ref()
.map(|p| p.as_ref())
.unwrap_or("none");

metric!(time_raw("symbolication.num_exceptions") = exceptions.len() as u64);
metric!(time_raw("symbolication.num_stacktraces") = stacktraces.len() as u64);
metric!(
time_raw("symbolication.num_frames") = stacktraces
.iter()
.map(|s| s.frames.len() as u64)
.sum::<u64>()

// Count number of frames by platform (including no platform)
let frames_by_platform = stacktraces.iter().flat_map(|st| st.frames.iter()).fold(
HashMap::new(),
|mut map, frame| {
let platform = frame.platform.as_ref();
let count: &mut usize = map.entry(platform).or_default();
*count += 1;
map
},
);

for (p, count) in &frames_by_platform {
let frame_platform = p.map(|p| p.as_ref()).unwrap_or("none");
metric!(
time_raw("symbolication.num_frames") =
count,
"frame_platform" => frame_platform, "event_platform" => event_platform
);
}
metric!(time_raw("symbolication.num_classes") = classes.len() as u64);
metric!(time_raw("symbolication.unsymbolicated_frames") = unsymbolicated_frames);
}
3 changes: 2 additions & 1 deletion crates/symbolicator-proguard/src/symbolication.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ impl ProguardService {
request: SymbolicateJvmStacktraces,
) -> CompletedJvmSymbolicationResponse {
let SymbolicateJvmStacktraces {
platform,
scope,
sources,
exceptions,
Expand All @@ -37,7 +38,6 @@ impl ProguardService {
release_package,
apply_source_context,
classes,
..
} = request;

let mut unsymbolicated_frames = 0;
Expand Down Expand Up @@ -165,6 +165,7 @@ impl ProguardService {
.collect();

record_symbolication_metrics(
platform,
&remapped_exceptions,
&remapped_stacktraces,
&remapped_classes,
Expand Down
Loading

0 comments on commit de05225

Please sign in to comment.