Skip to content

Commit

Permalink
feat: Report download metrics for internal symbol sources (#1589)
Browse files Browse the repository at this point in the history
  • Loading branch information
loewenheim authored Jan 13, 2025
1 parent bba422c commit f762622
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 5 deletions.
18 changes: 16 additions & 2 deletions crates/symbolicator-service/src/download/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -329,8 +329,7 @@ impl DownloadService {
) -> CacheEntry {
let host = source.host();

// Check whether `source` is an internal Sentry source. We don't ever
// want to put such sources on the block list.
let is_builtin_source = source.is_builtin();
let source_metric_key = source.source_metric_key().to_string();
// NOTE: This allow-lists every external non-http symbol server.
// This includes S3, GCS, and builtin http symbol servers that might misbehave.
Expand Down Expand Up @@ -381,6 +380,21 @@ impl DownloadService {
}
}

// Emit metrics about download result for internal sources
if is_builtin_source {
let status = match result {
Ok(_) => "success",
Err(CacheError::NotFound) => "notfound",
Err(CacheError::PermissionDenied(_)) => "permissiondenied",
Err(CacheError::Timeout(_)) => "timeout",
Err(CacheError::DownloadError(_)) => "downloaderror",
Err(CacheError::Malformed(_)) => "malformed",
Err(CacheError::Unsupported(_)) => "unsupported",
Err(CacheError::InternalError) => "internalerror",
};
metric!(counter("service.builtin_source.download") += 1, "source" => &source_metric_key, "status" => status);
}

result
}

Expand Down
10 changes: 7 additions & 3 deletions crates/symbolicator-sources/src/remotefile.rs
Original file line number Diff line number Diff line change
Expand Up @@ -231,13 +231,12 @@ impl RemoteFile {
/// If this is a built-in source the source_id is returned, otherwise this falls
/// back to the source type name.
pub fn source_metric_key(&self) -> &str {
let id = self.source_id().as_str();
// The IDs of built-in sources (see: SENTRY_BUILTIN_SOURCES in sentry) always start with
// "sentry:" (e.g. "sentry:electron") and are safe to use as a key. If this is a custom
// source, then the source_id is a random string which inflates the cardinality of this
// metric as the tag values will greatly vary.
if id.starts_with("sentry:") {
return id;
if self.is_builtin() {
return self.source_id().as_str();
}
match self {
Self::Sentry(..) => "sentry",
Expand All @@ -248,6 +247,11 @@ impl RemoteFile {
}
}

/// Returns whether a symbol source is builtin (see `SENTRY_BUILTIN_SOURCES` in sentry).
pub fn is_builtin(&self) -> bool {
self.source_id().as_str().starts_with("sentry:")
}

/// Returns a URI for the location of the object file.
///
/// There is no guarantee about any format of this URI, for some sources it could be
Expand Down

0 comments on commit f762622

Please sign in to comment.