Skip to content

Commit 9317df1

Browse files
mitsuhikojan-auer
authored andcommitted
feat: Update to new sentry types (#82)
1 parent d7c15e9 commit 9317df1

File tree

13 files changed

+86
-70
lines changed

13 files changed

+86
-70
lines changed

Cargo.toml

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -30,33 +30,33 @@ with_debug_meta = ["findshlibs", "with_client_implementation"]
3030
with_test_support = []
3131

3232
[dependencies]
33-
backtrace = { version = "0.3.8", optional = true }
34-
url = { version = "1.7.0", optional = true }
33+
backtrace = { version = "0.3.9", optional = true }
34+
url = { version = "1.7.1", optional = true }
3535
failure = { version = "0.1.2", optional = true }
36-
log = { version = "0.4.3", optional = true, features = ["std"] }
37-
sentry-types = "0.5.3"
38-
env_logger = { version = "0.5.10", optional = true }
39-
reqwest = { version = "0.8.6", optional = true }
36+
log = { version = "0.4.5", optional = true, features = ["std"] }
37+
sentry-types = "0.7.1"
38+
env_logger = { version = "0.5.13", optional = true }
39+
reqwest = { version = "0.8.8", optional = true }
4040
uuid = { version = "0.6.5", features = ["v4"] }
41-
lazy_static = "1.0.1"
42-
regex = { version = "1.0.0", optional = true }
41+
lazy_static = "1.1.0"
42+
regex = { version = "1.0.5", optional = true }
4343
error-chain = { version = "0.12.0", optional = true }
4444
im = { version = "12.0.0", optional = true }
45-
libc = { version = "0.2.42", optional = true }
45+
libc = { version = "0.2.43", optional = true }
4646
hostname = { version = "0.1.5", optional = true }
4747
findshlibs = { version = "0.4.0", optional = true }
48-
rand = "0.5.4"
48+
rand = "0.5.5"
4949

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

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

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

6161
[[example]]
6262
name = "error-chain-demo"

integrations/sentry-actix/src/lib.rs

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -84,8 +84,9 @@ use actix_web::middleware::{Middleware, Response, Started};
8484
use actix_web::{Error, HttpMessage, HttpRequest, HttpResponse};
8585
use failure::Fail;
8686
use sentry::integrations::failure::exception_from_single_fail;
87-
use sentry::protocol::{Event, Level};
87+
use sentry::protocol::{ClientSdkPackageInfo, Event, Level};
8888
use sentry::Hub;
89+
use std::borrow::Cow;
8990
use std::sync::{Arc, Mutex};
9091
use uuid::Uuid;
9192

@@ -228,6 +229,15 @@ impl<S: 'static> Middleware<S> for SentryMiddleware {
228229
}
229230
}
230231

232+
if let Some(sdk) = event.sdk.take() {
233+
let mut sdk = sdk.into_owned();
234+
sdk.packages.push(ClientSdkPackageInfo {
235+
package_name: "sentry-actix".into(),
236+
version: env!("CARGO_PKG_VERSION").into(),
237+
});
238+
event.sdk = Some(Cow::Owned(sdk));
239+
}
240+
231241
Some(event)
232242
}));
233243
});
@@ -303,7 +313,7 @@ impl ActixWebHubExt for Hub {
303313
}
304314
exceptions.reverse();
305315
self.capture_event(Event {
306-
exceptions: exceptions,
316+
exception: exceptions.into(),
307317
level: Level::Error,
308318
..Default::default()
309319
})

src/backtrace_support.rs

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ use std::fmt;
33
use backtrace::Backtrace;
44
use regex::{Captures, Regex};
55

6-
use api::protocol::{FileLocation, Frame, InstructionInfo, Stacktrace};
6+
use api::protocol::{Frame, Stacktrace};
77

88
lazy_static!{
99
static ref HASH_FUNC_RE: Regex = Regex::new(r#"(?x)
@@ -131,16 +131,11 @@ pub fn backtrace_to_stacktrace(bt: &Backtrace) -> Option<Stacktrace> {
131131
None
132132
},
133133
function: Some(function),
134-
instruction_info: InstructionInfo {
135-
instruction_addr: Some(frame.ip().into()),
136-
..Default::default()
137-
},
138-
location: FileLocation {
139-
abs_path,
140-
filename,
141-
line: sym.lineno().map(|l| l.into()),
142-
column: None,
143-
},
134+
instruction_addr: Some(frame.ip().into()),
135+
abs_path,
136+
filename,
137+
lineno: sym.lineno().map(|l| l.into()),
138+
colno: None,
144139
..Default::default()
145140
}
146141
})

src/client.rs

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -395,8 +395,16 @@ impl Client {
395395
};
396396
}
397397

398-
if event.id.is_none() {
399-
event.id = Some(Uuid::new_v4());
398+
// id, debug meta and sdk are set before the processors run so that the
399+
// processors can poke around in that data.
400+
if event.event_id.is_nil() {
401+
event.event_id = Uuid::new_v4();
402+
}
403+
if event.debug_meta.is_empty() {
404+
event.debug_meta = Cow::Borrowed(&DEBUG_META);
405+
}
406+
if event.sdk.is_none() {
407+
event.sdk = Some(Cow::Borrowed(&SDK_INFO));
400408
}
401409

402410
if let Some(scope) = scope {
@@ -423,19 +431,12 @@ impl Client {
423431
if event.server_name.is_none() {
424432
event.server_name = self.options.server_name.clone();
425433
}
426-
if event.sdk_info.is_none() {
427-
event.sdk_info = Some(Cow::Borrowed(&SDK_INFO));
428-
}
429434

430435
if &event.platform == "other" {
431436
event.platform = "native".into();
432437
}
433438

434-
if event.debug_meta.is_empty() {
435-
event.debug_meta = Cow::Borrowed(&DEBUG_META);
436-
}
437-
438-
for exc in &mut event.exceptions {
439+
for exc in &mut event.exception {
439440
if let Some(ref mut stacktrace) = exc.stacktrace {
440441
// automatically trim backtraces
441442
if self.options.trim_backtraces {
@@ -512,7 +513,7 @@ impl Client {
512513

513514
if let Some(ref func) = self.options.before_send {
514515
sentry_debug!("invoking before_send callback");
515-
let id = event.id;
516+
let id = event.event_id;
516517
func(event).or_else(move || {
517518
sentry_debug!("before_send dropped event {:?}", id);
518519
None
@@ -542,7 +543,7 @@ impl Client {
542543
if let Some(ref transport) = *self.transport.read().unwrap() {
543544
if self.sample_should_send() {
544545
if let Some(event) = self.prepare_event(event, scope) {
545-
let event_id = event.id.unwrap();
546+
let event_id = event.event_id;
546547
transport.send_event(event);
547548
return event_id;
548549
}

src/constants.rs

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,34 @@
1-
use api::protocol::ClientSdkInfo;
1+
use api::protocol::{ClientSdkInfo, ClientSdkPackageInfo};
22

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

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

88
lazy_static! {
9-
pub static ref USER_AGENT: String = format!("sentry-rust/{}", VERSION);
9+
pub static ref USER_AGENT: String = format!("sentry.rust/{}", VERSION);
1010
pub static ref SDK_INFO: ClientSdkInfo = ClientSdkInfo {
1111
name: "sentry-rust".into(),
1212
version: VERSION.into(),
13+
packages: vec![ClientSdkPackageInfo {
14+
package_name: "cargo:sentry".into(),
15+
version: VERSION.into(),
16+
}],
1317
integrations: {
1418
#[allow(unused_mut)]
1519
let mut rv = vec![];
1620
#[cfg(feature = "with_failure")]
1721
{
1822
rv.push("failure".to_string());
1923
}
24+
#[cfg(feature = "with_panic")]
25+
{
26+
rv.push("panic".to_string());
27+
}
28+
#[cfg(feature = "with_error_chain")]
29+
{
30+
rv.push("error_chain".to_string());
31+
}
2032
#[cfg(feature = "with_log")]
2133
{
2234
rv.push("log".to_string());

src/hub.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -300,7 +300,7 @@ impl Hub {
300300
if client.options().attach_stacktrace {
301301
let thread = current_thread(true);
302302
if thread.stacktrace.is_some() {
303-
event.threads.push(thread);
303+
event.threads.values.push(thread);
304304
}
305305
}
306306
self.capture_event(event)

src/integrations/error_chain.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ where
6565
T::ErrorKind: Debug + Display,
6666
{
6767
Event {
68-
exceptions: exceptions_from_error_chain(e),
68+
exception: exceptions_from_error_chain(e).into(),
6969
level: Level::Error,
7070
..Default::default()
7171
}

src/integrations/failure.rs

Lines changed: 9 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ use failure::{Error, Fail};
3232
use regex::Regex;
3333
use uuid::Uuid;
3434

35-
use api::protocol::{Event, Exception, FileLocation, Frame, InstructionInfo, Level, Stacktrace};
35+
use api::protocol::{Event, Exception, Frame, Level, Stacktrace};
3636
use backtrace_support::{demangle_symbol, error_typename, filename, strip_symbol};
3737
use hub::Hub;
3838

@@ -71,18 +71,12 @@ fn parse_stacktrace(bt: &str) -> Option<Stacktrace> {
7171
None
7272
},
7373
function: Some(function),
74-
instruction_info: InstructionInfo {
75-
instruction_addr: Some(captures["addr"].parse().unwrap()),
76-
..Default::default()
77-
},
78-
location: FileLocation {
79-
abs_path,
80-
filename,
81-
line: captures
82-
.name("lineno")
83-
.map(|x| x.as_str().parse::<u64>().unwrap()),
84-
column: None,
85-
},
74+
instruction_addr: Some(captures["addr"].parse().unwrap()),
75+
abs_path,
76+
filename,
77+
lineno: captures
78+
.name("lineno")
79+
.map(|x| x.as_str().parse::<u64>().unwrap()),
8680
..Default::default()
8781
}
8882
})
@@ -127,7 +121,7 @@ pub fn event_from_error(err: &failure::Error) -> Event<'static> {
127121

128122
exceptions.reverse();
129123
Event {
130-
exceptions,
124+
exception: exceptions.into(),
131125
level: Level::Error,
132126
..Default::default()
133127
}
@@ -145,7 +139,7 @@ pub fn event_from_fail<F: Fail + ?Sized>(fail: &F) -> Event<'static> {
145139

146140
exceptions.reverse();
147141
Event {
148-
exceptions,
142+
exception: exceptions.into(),
149143
level: Level::Error,
150144
..Default::default()
151145
}

src/integrations/log.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,7 @@ pub fn event_from_record(record: &log::Record, with_stacktrace: bool) -> Event<'
153153
Event {
154154
logger: Some(record.target().into()),
155155
level: convert_log_level(record.level()),
156-
exceptions: vec![Exception {
156+
exception: vec![Exception {
157157
ty: record.target().into(),
158158
value: Some(format!("{}", record.args())),
159159
stacktrace: if with_stacktrace {
@@ -162,7 +162,7 @@ pub fn event_from_record(record: &log::Record, with_stacktrace: bool) -> Event<'
162162
None
163163
},
164164
..Default::default()
165-
}],
165+
}].into(),
166166
..Default::default()
167167
}
168168
}

src/integrations/panic.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,12 +36,12 @@ pub fn message_from_panic_info<'a>(info: &'a panic::PanicInfo) -> &'a str {
3636
pub fn event_from_panic_info(info: &panic::PanicInfo) -> Event<'static> {
3737
let msg = message_from_panic_info(info);
3838
Event {
39-
exceptions: vec![Exception {
39+
exception: vec![Exception {
4040
ty: "panic".into(),
4141
value: Some(msg.to_string()),
4242
stacktrace: current_stacktrace(),
4343
..Default::default()
44-
}],
44+
}].into(),
4545
level: Level::Fatal,
4646
..Default::default()
4747
}

src/scope/real.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -299,11 +299,11 @@ impl Scope {
299299
}
300300

301301
for processor in &self.event_processors {
302-
let id = event.id;
302+
let id = event.event_id;
303303
event = match processor(event) {
304304
Some(event) => event,
305305
None => {
306-
sentry_debug!("event processor dropped event {:?}", id);
306+
sentry_debug!("event processor dropped event {}", id);
307307
return None;
308308
}
309309
}

src/utils.rs

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ use std::mem;
33
use std::thread;
44

55
use api::protocol::{
6-
Context, DebugImage, DeviceContext, OsContext, RuntimeContext, Stacktrace, Thread,
6+
Context, DebugImage, DeviceContext, Map, OsContext, RuntimeContext, Stacktrace, Thread,
77
};
88

99
#[cfg(all(feature = "with_device_info", target_os = "macos"))]
@@ -199,13 +199,17 @@ pub fn rust_context() -> Option<Context> {
199199
#[cfg(feature = "with_device_info")]
200200
{
201201
use constants::{RUSTC_CHANNEL, RUSTC_VERSION};
202-
let mut ctx: Context = RuntimeContext {
202+
let ctx = RuntimeContext {
203203
name: Some("rustc".into()),
204204
version: RUSTC_VERSION.map(|x| x.into()),
205+
other: {
206+
let mut map = Map::default();
207+
if let Some(channel) = RUSTC_CHANNEL {
208+
map.insert("channel".to_string(), channel.into());
209+
}
210+
map
211+
},
205212
}.into();
206-
if let Some(channel) = RUSTC_CHANNEL {
207-
ctx.extra.insert("channel".into(), channel.into());
208-
}
209213
Some(ctx)
210214
}
211215
#[cfg(not(feature = "with_device_info"))]

tests/test_basic.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ fn test_basic_capture_message() {
2525
vec![("worker".to_string(), "worker1".to_string())]
2626
);
2727

28-
assert_eq!(event.id, last_event_id);
28+
assert_eq!(Some(event.event_id), last_event_id);
2929
}
3030

3131
#[test]

0 commit comments

Comments
 (0)