Skip to content

Commit

Permalink
Merge 2b216e6 into 02c6775
Browse files Browse the repository at this point in the history
  • Loading branch information
MarijnS95 authored Jun 11, 2022
2 parents 02c6775 + 2b216e6 commit f04cedc
Show file tree
Hide file tree
Showing 10 changed files with 88 additions and 70 deletions.
4 changes: 2 additions & 2 deletions sentry-backtrace/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ Sentry integration and utilities for dealing with stacktraces.
edition = "2018"

[dependencies]
sentry-core = { version = "0.26.0", path = "../sentry-core" }
lazy_static = "1.4.0"
backtrace = "0.3.44"
once_cell = "1"
regex = "1.5.5"
sentry-core = { version = "0.26.0", path = "../sentry-core" }
12 changes: 8 additions & 4 deletions sentry-backtrace/src/parse.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
use once_cell::sync::Lazy;
use regex::Regex;

use crate::utils::{demangle_symbol, filename, strip_symbol};
use crate::{Frame, Stacktrace};

lazy_static::lazy_static! {
static ref FRAME_RE: Regex = Regex::new(r#"(?xm)
static FRAME_RE: Lazy<Regex> = Lazy::new(|| {
Regex::new(
r#"(?xm)
^
\s*(?:\d+:)?\s* # frame number (missing for inline)
Expand All @@ -27,8 +29,10 @@ lazy_static::lazy_static! {
(?::(?P<colno>\d+))? # optional source column
)?
$
"#).unwrap();
}
"#,
)
.unwrap()
});

/// Parses a backtrace string into a Sentry `Stacktrace`.
pub fn parse_stacktrace(bt: &str) -> Option<Stacktrace> {
Expand Down
46 changes: 22 additions & 24 deletions sentry-backtrace/src/trim.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,31 +2,29 @@ use sentry_core::protocol::{Frame, Stacktrace};

use crate::utils::function_starts_with;

lazy_static::lazy_static! {
static ref WELL_KNOWN_SYS_MODULES: Vec<&'static str> = vec![
"std::",
"core::",
"alloc::",
"backtrace::",
"sentry::",
"sentry_core::",
"sentry_types::",
// these are not modules but things like __rust_maybe_catch_panic
"__rust_",
"___rust_",
// these are well-known library frames
"anyhow::",
"log::",
];
const WELL_KNOWN_SYS_MODULES: &[&str] = &[
"std::",
"core::",
"alloc::",
"backtrace::",
"sentry::",
"sentry_core::",
"sentry_types::",
// these are not modules but things like __rust_maybe_catch_panic
"__rust_",
"___rust_",
// these are well-known library frames
"anyhow::",
"log::",
];

static ref WELL_KNOWN_BORDER_FRAMES: Vec<&'static str> = vec![
"std::panicking::begin_panic",
"core::panicking::panic",
// well-known library frames
"anyhow::",
"<sentry_log::Logger as log::Log>::log",
];
}
const WELL_KNOWN_BORDER_FRAMES: &[&str] = &[
"std::panicking::begin_panic",
"core::panicking::panic",
// well-known library frames
"anyhow::",
"<sentry_log::Logger as log::Log>::log",
];

/// A helper function to trim a stacktrace.
pub fn trim_stacktrace<F>(stacktrace: &mut Stacktrace, f: F)
Expand Down
34 changes: 24 additions & 10 deletions sentry-backtrace/src/utils.rs
Original file line number Diff line number Diff line change
@@ -1,25 +1,39 @@
use once_cell::sync::Lazy;
use regex::{Captures, Regex};

lazy_static::lazy_static! {
static ref HASH_FUNC_RE: Regex = Regex::new(r#"(?x)
static HASH_FUNC_RE: Lazy<Regex> = Lazy::new(|| {
Regex::new(
r#"(?x)
^(.*)::h[a-f0-9]{16}$
"#).unwrap();

static ref CRATE_RE: Regex = Regex::new(r#"(?x)
"#,
)
.unwrap()
});

static CRATE_RE: Lazy<Regex> = Lazy::new(|| {
Regex::new(
r#"(?x)
^
(?:_?<)? # trait impl syntax
(?:\w+\ as \ )? # anonymous implementor
([a-zA-Z0-9_]+?) # crate name
(?:\.\.|::) # crate delimiter (.. or ::)
"#).unwrap();

static ref COMMON_RUST_SYMBOL_ESCAPES_RE: Regex = Regex::new(r#"(?x)
"#,
)
.unwrap()
});

static COMMON_RUST_SYMBOL_ESCAPES_RE: Lazy<Regex> = Lazy::new(|| {
Regex::new(
r#"(?x)
\$
(SP|BP|RF|LT|GT|LP|RP|C|
u7e|u20|u27|u5b|u5d|u7b|u7d|u3b|u2b|u22)
\$
"#).unwrap();
}
"#,
)
.unwrap()
});

/// Tries to parse the rust crate from a function name.
pub fn parse_crate_name(func_name: &str) -> Option<String> {
Expand Down
6 changes: 3 additions & 3 deletions sentry-core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,12 @@ debug-logs = ["log_"]
test = ["client"]

[dependencies]
log_ = { package = "log", version = "0.4.8", optional = true, features = ["std"] }
once_cell = "1"
rand = { version = "0.8.1", optional = true }
sentry-types = { version = "0.26.0", path = "../sentry-types" }
serde = { version = "1.0.104", features = ["derive"] }
lazy_static = "1.4.0"
rand = { version = "0.8.1", optional = true }
serde_json = "1.0.46"
log_ = { package = "log", version = "0.4.8", optional = true, features = ["std"] }

[dev-dependencies]
# Because we re-export all the public API in `sentry`, we actually run all the
Expand Down
22 changes: 11 additions & 11 deletions sentry-core/src/constants.rs
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
use once_cell::sync::Lazy;

use crate::protocol::{ClientSdkInfo, ClientSdkPackage};

/// The version of the library
pub const VERSION: &str = env!("CARGO_PKG_VERSION");
pub const USER_AGENT: &str = concat!("sentry.rust/", env!("CARGO_PKG_VERSION"));

lazy_static::lazy_static! {
pub static ref USER_AGENT: String = format!("sentry.rust/{}", VERSION);
pub static ref SDK_INFO: ClientSdkInfo = ClientSdkInfo {
name: "sentry.rust".into(),
pub static SDK_INFO: Lazy<ClientSdkInfo> = Lazy::new(|| ClientSdkInfo {
name: "sentry.rust".into(),
version: VERSION.into(),
packages: vec![ClientSdkPackage {
name: "cargo:sentry".into(),
version: VERSION.into(),
packages: vec![ClientSdkPackage {
name: "cargo:sentry".into(),
version: VERSION.into(),
}],
integrations: vec![],
};
}
}],
integrations: vec![],
});
13 changes: 8 additions & 5 deletions sentry-core/src/hub.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,19 +8,22 @@ use std::sync::{Arc, Mutex, PoisonError, RwLock, TryLockError};
use std::thread;
use std::time::Duration;

#[cfg(feature = "client")]
use once_cell::sync::Lazy;

use crate::protocol::{Breadcrumb, Event, Level, SessionStatus};
use crate::types::Uuid;
use crate::{event_from_error, Integration, IntoBreadcrumbs, Scope, ScopeGuard};
#[cfg(feature = "client")]
use crate::{scope::Stack, session::Session, Client, Envelope};

#[cfg(feature = "client")]
lazy_static::lazy_static! {
static ref PROCESS_HUB: (Arc<Hub>, thread::ThreadId) = (
static PROCESS_HUB: Lazy<(Arc<Hub>, thread::ThreadId)> = Lazy::new(|| {
(
Arc::new(Hub::new(None, Arc::new(Default::default()))),
thread::current().id()
);
}
thread::current().id(),
)
});

#[cfg(feature = "client")]
thread_local! {
Expand Down
6 changes: 3 additions & 3 deletions sentry-core/src/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,13 @@

use std::sync::{Arc, Mutex};

use once_cell::sync::Lazy;

use crate::protocol::Event;
use crate::types::Dsn;
use crate::{ClientOptions, Envelope, Hub, Transport};

lazy_static::lazy_static! {
static ref TEST_DSN: Dsn = "https://public@sentry.invalid/1".parse().unwrap();
}
static TEST_DSN: Lazy<Dsn> = Lazy::new(|| "https://public@sentry.invalid/1".parse().unwrap());

/// Collects events instead of sending them.
///
Expand Down
4 changes: 2 additions & 2 deletions sentry-debug-images/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,6 @@ Sentry integration that adds the list of loaded libraries to events.
edition = "2018"

[dependencies]
sentry-core = { version = "0.26.0", path = "../sentry-core" }
lazy_static = "1.4.0"
findshlibs = "=0.10.2"
once_cell = "1"
sentry-core = { version = "0.26.0", path = "../sentry-core" }
11 changes: 5 additions & 6 deletions sentry-debug-images/src/integration.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use std::borrow::Cow;

use once_cell::sync::Lazy;
use sentry_core::protocol::{DebugMeta, Event};
use sentry_core::{ClientOptions, Integration};

Expand Down Expand Up @@ -55,12 +56,10 @@ impl Integration for DebugImagesIntegration {
mut event: Event<'static>,
_opts: &ClientOptions,
) -> Option<Event<'static>> {
lazy_static::lazy_static! {
static ref DEBUG_META: DebugMeta = DebugMeta {
images: crate::debug_images(),
..Default::default()
};
}
static DEBUG_META: Lazy<DebugMeta> = Lazy::new(|| DebugMeta {
images: crate::debug_images(),
..Default::default()
});

if event.debug_meta.is_empty() && (self.filter)(&event) {
event.debug_meta = Cow::Borrowed(&DEBUG_META);
Expand Down

0 comments on commit f04cedc

Please sign in to comment.