Skip to content

Commit

Permalink
feat: Update to new sentry types (#82)
Browse files Browse the repository at this point in the history
  • Loading branch information
mitsuhiko authored and jan-auer committed Sep 12, 2018
1 parent d7c15e9 commit 9317df1
Show file tree
Hide file tree
Showing 13 changed files with 86 additions and 70 deletions.
28 changes: 14 additions & 14 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -30,33 +30,33 @@ with_debug_meta = ["findshlibs", "with_client_implementation"]
with_test_support = []

[dependencies]
backtrace = { version = "0.3.8", optional = true }
url = { version = "1.7.0", optional = true }
backtrace = { version = "0.3.9", optional = true }
url = { version = "1.7.1", optional = true }
failure = { version = "0.1.2", optional = true }
log = { version = "0.4.3", optional = true, features = ["std"] }
sentry-types = "0.5.3"
env_logger = { version = "0.5.10", optional = true }
reqwest = { version = "0.8.6", optional = true }
log = { version = "0.4.5", optional = true, features = ["std"] }
sentry-types = "0.7.1"
env_logger = { version = "0.5.13", optional = true }
reqwest = { version = "0.8.8", optional = true }
uuid = { version = "0.6.5", features = ["v4"] }
lazy_static = "1.0.1"
regex = { version = "1.0.0", optional = true }
lazy_static = "1.1.0"
regex = { version = "1.0.5", optional = true }
error-chain = { version = "0.12.0", optional = true }
im = { version = "12.0.0", optional = true }
libc = { version = "0.2.42", optional = true }
libc = { version = "0.2.43", optional = true }
hostname = { version = "0.1.5", optional = true }
findshlibs = { version = "0.4.0", optional = true }
rand = "0.5.4"
rand = "0.5.5"

[target."cfg(not(windows))".dependencies]
uname = { version = "0.1.1", optional = true }

[build-dependencies]
rustc_version = { version = "0.2.2", optional = true }
rustc_version = { version = "0.2.3", optional = true }

[dev-dependencies]
failure_derive = "0.1.1"
pretty_env_logger = "0.2.3"
actix-web = { version = "0.6.12", default-features = false }
failure_derive = "0.1.2"
pretty_env_logger = "0.2.4"
actix-web = { version = "0.7.7", default-features = false }

[[example]]
name = "error-chain-demo"
Expand Down
14 changes: 12 additions & 2 deletions integrations/sentry-actix/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -84,8 +84,9 @@ use actix_web::middleware::{Middleware, Response, Started};
use actix_web::{Error, HttpMessage, HttpRequest, HttpResponse};
use failure::Fail;
use sentry::integrations::failure::exception_from_single_fail;
use sentry::protocol::{Event, Level};
use sentry::protocol::{ClientSdkPackageInfo, Event, Level};
use sentry::Hub;
use std::borrow::Cow;
use std::sync::{Arc, Mutex};
use uuid::Uuid;

Expand Down Expand Up @@ -228,6 +229,15 @@ impl<S: 'static> Middleware<S> for SentryMiddleware {
}
}

if let Some(sdk) = event.sdk.take() {
let mut sdk = sdk.into_owned();
sdk.packages.push(ClientSdkPackageInfo {
package_name: "sentry-actix".into(),
version: env!("CARGO_PKG_VERSION").into(),
});
event.sdk = Some(Cow::Owned(sdk));
}

Some(event)
}));
});
Expand Down Expand Up @@ -303,7 +313,7 @@ impl ActixWebHubExt for Hub {
}
exceptions.reverse();
self.capture_event(Event {
exceptions: exceptions,
exception: exceptions.into(),
level: Level::Error,
..Default::default()
})
Expand Down
17 changes: 6 additions & 11 deletions src/backtrace_support.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use std::fmt;
use backtrace::Backtrace;
use regex::{Captures, Regex};

use api::protocol::{FileLocation, Frame, InstructionInfo, Stacktrace};
use api::protocol::{Frame, Stacktrace};

lazy_static!{
static ref HASH_FUNC_RE: Regex = Regex::new(r#"(?x)
Expand Down Expand Up @@ -131,16 +131,11 @@ pub fn backtrace_to_stacktrace(bt: &Backtrace) -> Option<Stacktrace> {
None
},
function: Some(function),
instruction_info: InstructionInfo {
instruction_addr: Some(frame.ip().into()),
..Default::default()
},
location: FileLocation {
abs_path,
filename,
line: sym.lineno().map(|l| l.into()),
column: None,
},
instruction_addr: Some(frame.ip().into()),
abs_path,
filename,
lineno: sym.lineno().map(|l| l.into()),
colno: None,
..Default::default()
}
})
Expand Down
25 changes: 13 additions & 12 deletions src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -395,8 +395,16 @@ impl Client {
};
}

if event.id.is_none() {
event.id = Some(Uuid::new_v4());
// id, debug meta and sdk are set before the processors run so that the
// processors can poke around in that data.
if event.event_id.is_nil() {
event.event_id = Uuid::new_v4();
}
if event.debug_meta.is_empty() {
event.debug_meta = Cow::Borrowed(&DEBUG_META);
}
if event.sdk.is_none() {
event.sdk = Some(Cow::Borrowed(&SDK_INFO));
}

if let Some(scope) = scope {
Expand All @@ -423,19 +431,12 @@ impl Client {
if event.server_name.is_none() {
event.server_name = self.options.server_name.clone();
}
if event.sdk_info.is_none() {
event.sdk_info = Some(Cow::Borrowed(&SDK_INFO));
}

if &event.platform == "other" {
event.platform = "native".into();
}

if event.debug_meta.is_empty() {
event.debug_meta = Cow::Borrowed(&DEBUG_META);
}

for exc in &mut event.exceptions {
for exc in &mut event.exception {
if let Some(ref mut stacktrace) = exc.stacktrace {
// automatically trim backtraces
if self.options.trim_backtraces {
Expand Down Expand Up @@ -512,7 +513,7 @@ impl Client {

if let Some(ref func) = self.options.before_send {
sentry_debug!("invoking before_send callback");
let id = event.id;
let id = event.event_id;
func(event).or_else(move || {
sentry_debug!("before_send dropped event {:?}", id);
None
Expand Down Expand Up @@ -542,7 +543,7 @@ impl Client {
if let Some(ref transport) = *self.transport.read().unwrap() {
if self.sample_should_send() {
if let Some(event) = self.prepare_event(event, scope) {
let event_id = event.id.unwrap();
let event_id = event.event_id;
transport.send_event(event);
return event_id;
}
Expand Down
16 changes: 14 additions & 2 deletions src/constants.rs
Original file line number Diff line number Diff line change
@@ -1,22 +1,34 @@
use api::protocol::ClientSdkInfo;
use api::protocol::{ClientSdkInfo, ClientSdkPackageInfo};

/// The version of the library
pub const VERSION: &str = env!("CARGO_PKG_VERSION");

include!(concat!(env!("OUT_DIR"), "/constants.gen.rs"));

lazy_static! {
pub static ref USER_AGENT: String = format!("sentry-rust/{}", VERSION);
pub static ref USER_AGENT: String = format!("sentry.rust/{}", VERSION);
pub static ref SDK_INFO: ClientSdkInfo = ClientSdkInfo {
name: "sentry-rust".into(),
version: VERSION.into(),
packages: vec![ClientSdkPackageInfo {
package_name: "cargo:sentry".into(),
version: VERSION.into(),
}],
integrations: {
#[allow(unused_mut)]
let mut rv = vec![];
#[cfg(feature = "with_failure")]
{
rv.push("failure".to_string());
}
#[cfg(feature = "with_panic")]
{
rv.push("panic".to_string());
}
#[cfg(feature = "with_error_chain")]
{
rv.push("error_chain".to_string());
}
#[cfg(feature = "with_log")]
{
rv.push("log".to_string());
Expand Down
2 changes: 1 addition & 1 deletion src/hub.rs
Original file line number Diff line number Diff line change
Expand Up @@ -300,7 +300,7 @@ impl Hub {
if client.options().attach_stacktrace {
let thread = current_thread(true);
if thread.stacktrace.is_some() {
event.threads.push(thread);
event.threads.values.push(thread);
}
}
self.capture_event(event)
Expand Down
2 changes: 1 addition & 1 deletion src/integrations/error_chain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ where
T::ErrorKind: Debug + Display,
{
Event {
exceptions: exceptions_from_error_chain(e),
exception: exceptions_from_error_chain(e).into(),
level: Level::Error,
..Default::default()
}
Expand Down
24 changes: 9 additions & 15 deletions src/integrations/failure.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ use failure::{Error, Fail};
use regex::Regex;
use uuid::Uuid;

use api::protocol::{Event, Exception, FileLocation, Frame, InstructionInfo, Level, Stacktrace};
use api::protocol::{Event, Exception, Frame, Level, Stacktrace};
use backtrace_support::{demangle_symbol, error_typename, filename, strip_symbol};
use hub::Hub;

Expand Down Expand Up @@ -71,18 +71,12 @@ fn parse_stacktrace(bt: &str) -> Option<Stacktrace> {
None
},
function: Some(function),
instruction_info: InstructionInfo {
instruction_addr: Some(captures["addr"].parse().unwrap()),
..Default::default()
},
location: FileLocation {
abs_path,
filename,
line: captures
.name("lineno")
.map(|x| x.as_str().parse::<u64>().unwrap()),
column: None,
},
instruction_addr: Some(captures["addr"].parse().unwrap()),
abs_path,
filename,
lineno: captures
.name("lineno")
.map(|x| x.as_str().parse::<u64>().unwrap()),
..Default::default()
}
})
Expand Down Expand Up @@ -127,7 +121,7 @@ pub fn event_from_error(err: &failure::Error) -> Event<'static> {

exceptions.reverse();
Event {
exceptions,
exception: exceptions.into(),
level: Level::Error,
..Default::default()
}
Expand All @@ -145,7 +139,7 @@ pub fn event_from_fail<F: Fail + ?Sized>(fail: &F) -> Event<'static> {

exceptions.reverse();
Event {
exceptions,
exception: exceptions.into(),
level: Level::Error,
..Default::default()
}
Expand Down
4 changes: 2 additions & 2 deletions src/integrations/log.rs
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ pub fn event_from_record(record: &log::Record, with_stacktrace: bool) -> Event<'
Event {
logger: Some(record.target().into()),
level: convert_log_level(record.level()),
exceptions: vec![Exception {
exception: vec![Exception {
ty: record.target().into(),
value: Some(format!("{}", record.args())),
stacktrace: if with_stacktrace {
Expand All @@ -162,7 +162,7 @@ pub fn event_from_record(record: &log::Record, with_stacktrace: bool) -> Event<'
None
},
..Default::default()
}],
}].into(),
..Default::default()
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/integrations/panic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,12 @@ pub fn message_from_panic_info<'a>(info: &'a panic::PanicInfo) -> &'a str {
pub fn event_from_panic_info(info: &panic::PanicInfo) -> Event<'static> {
let msg = message_from_panic_info(info);
Event {
exceptions: vec![Exception {
exception: vec![Exception {
ty: "panic".into(),
value: Some(msg.to_string()),
stacktrace: current_stacktrace(),
..Default::default()
}],
}].into(),
level: Level::Fatal,
..Default::default()
}
Expand Down
4 changes: 2 additions & 2 deletions src/scope/real.rs
Original file line number Diff line number Diff line change
Expand Up @@ -299,11 +299,11 @@ impl Scope {
}

for processor in &self.event_processors {
let id = event.id;
let id = event.event_id;
event = match processor(event) {
Some(event) => event,
None => {
sentry_debug!("event processor dropped event {:?}", id);
sentry_debug!("event processor dropped event {}", id);
return None;
}
}
Expand Down
14 changes: 9 additions & 5 deletions src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use std::mem;
use std::thread;

use api::protocol::{
Context, DebugImage, DeviceContext, OsContext, RuntimeContext, Stacktrace, Thread,
Context, DebugImage, DeviceContext, Map, OsContext, RuntimeContext, Stacktrace, Thread,
};

#[cfg(all(feature = "with_device_info", target_os = "macos"))]
Expand Down Expand Up @@ -199,13 +199,17 @@ pub fn rust_context() -> Option<Context> {
#[cfg(feature = "with_device_info")]
{
use constants::{RUSTC_CHANNEL, RUSTC_VERSION};
let mut ctx: Context = RuntimeContext {
let ctx = RuntimeContext {
name: Some("rustc".into()),
version: RUSTC_VERSION.map(|x| x.into()),
other: {
let mut map = Map::default();
if let Some(channel) = RUSTC_CHANNEL {
map.insert("channel".to_string(), channel.into());
}
map
},
}.into();
if let Some(channel) = RUSTC_CHANNEL {
ctx.extra.insert("channel".into(), channel.into());
}
Some(ctx)
}
#[cfg(not(feature = "with_device_info"))]
Expand Down
2 changes: 1 addition & 1 deletion tests/test_basic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ fn test_basic_capture_message() {
vec![("worker".to_string(), "worker1".to_string())]
);

assert_eq!(event.id, last_event_id);
assert_eq!(Some(event.event_id), last_event_id);
}

#[test]
Expand Down

0 comments on commit 9317df1

Please sign in to comment.