Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion src/commands/bash_hook.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ use crate::config::Config;
use crate::utils::event::{attach_logfile, get_sdk_info};
use crate::utils::releases::detect_release_name;

const MAX_BREADCRUMBS: usize = 100;

const BASH_SCRIPT: &str = include_str!("../bashsupport.sh");
lazy_static! {
static ref FRAME_RE: Regex = Regex::new(r"^(.*?):(.*):(\d+)$").unwrap();
Expand Down Expand Up @@ -188,7 +190,7 @@ fn send_event(
}
}

attach_logfile(&mut event, logfile, true)?;
attach_logfile(&mut event, logfile, true, MAX_BREADCRUMBS)?;

event.exception.values.push(Exception {
ty: "BashError".into(),
Expand Down
12 changes: 10 additions & 2 deletions src/commands/send_event.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@ use crate::utils::args::{get_timestamp, validate_distribution};
use crate::utils::event::{attach_logfile, get_sdk_info};
use crate::utils::releases::detect_release_name;

/// The maximum number of breadcrumbs to attach to an event.
const MAX_BREADCRUMBS: usize = 100;

pub fn make_command(command: Command) -> Command {
command.about("Send a manual event to Sentry.")
.long_about(
Expand Down Expand Up @@ -143,7 +146,7 @@ pub fn make_command(command: Command) -> Command {
Arg::new("logfile")
.value_name("PATH")
.long("logfile")
.help("Send a logfile as breadcrumbs with the event (last 100 records)"),
.help(format!("Send a logfile as breadcrumbs with the event (last {MAX_BREADCRUMBS} records)")),
)
.arg(
Arg::new("with_categories")
Expand Down Expand Up @@ -322,7 +325,12 @@ pub fn execute(matches: &ArgMatches) -> Result<()> {
}

if let Some(logfile) = matches.get_one::<String>("logfile") {
attach_logfile(&mut event, logfile, matches.get_flag("with_categories"))?;
attach_logfile(
&mut event,
logfile,
matches.get_flag("with_categories"),
MAX_BREADCRUMBS,
)?;
}

let id = send_raw_event(event)?;
Expand Down
11 changes: 8 additions & 3 deletions src/utils/event.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,12 @@ lazy_static! {
}

/// Attaches all logs from a logfile as breadcrumbs to the given event.
pub fn attach_logfile(event: &mut Event<'_>, logfile: &str, with_component: bool) -> Result<()> {
pub fn attach_logfile(
event: &mut Event<'_>,
logfile: &str,
with_component: bool,
max_breadcrumbs: usize,
) -> Result<()> {
let f = fs::File::open(logfile).context("Could not open logfile")?;

// sentry currently requires timestamps for breadcrumbs at all times.
Expand Down Expand Up @@ -46,8 +51,8 @@ pub fn attach_logfile(event: &mut Event<'_>, logfile: &str, with_component: bool
})
}

if event.breadcrumbs.len() > 100 {
let skip = event.breadcrumbs.len() - 100;
if event.breadcrumbs.len() > max_breadcrumbs {
let skip = event.breadcrumbs.len() - max_breadcrumbs;
event.breadcrumbs.values.drain(..skip);
}

Expand Down
Loading