Skip to content

Commit d597f87

Browse files
authored
fix(client): Merge default contexts without scope (#47)
1 parent 54e1dc3 commit d597f87

File tree

2 files changed

+32
-34
lines changed

2 files changed

+32
-34
lines changed

Cargo.toml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,16 +33,16 @@ backtrace = { version = "0.3.8", optional = true }
3333
url = { version = "1.7.0", optional = true }
3434
failure = { version = "0.1.1", optional = true }
3535
log = { version = "0.4.1", optional = true }
36-
serde = "1.0.64"
36+
serde = "1.0.66"
3737
serde_json = "1.0.19"
38-
sentry-types = "0.5.2"
38+
sentry-types = "0.5.3"
3939
reqwest = { version = "0.8.6", optional = true }
4040
uuid = { version = "0.6.5", features = ["v4"] }
4141
lazy_static = "1.0.1"
4242
regex = { version = "1.0.0", optional = true }
4343
error-chain = { version = "0.11.0", optional = true }
4444
im = { version = "10.2.0", optional = true }
45-
libc = { version = "0.2.41", optional = true }
45+
libc = { version = "0.2.42", optional = true }
4646
hostname = { version = "0.1.5", optional = true }
4747
findshlibs = { version = "0.4.0", optional = true }
4848

src/client/real.rs

Lines changed: 29 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ use uuid::Uuid;
1111
use api::Dsn;
1212
use backtrace_support::{function_starts_with, is_sys_function};
1313
use constants::{SDK_INFO, USER_AGENT};
14+
use protocol::map::Entry;
1415
use protocol::{Context, DebugMeta, Event};
1516
use scope::{bind_client, Scope};
1617
use transport::Transport;
@@ -283,6 +284,10 @@ impl Client {
283284
};
284285
}
285286

287+
let mut add_os = true;
288+
let mut add_rust = true;
289+
let mut add_device = true;
290+
286291
if let Some(scope) = scope {
287292
if !scope.breadcrumbs.is_empty() {
288293
event
@@ -311,10 +316,6 @@ impl Client {
311316
.extend(scope.tags.iter().map(|(k, v)| ((*k).clone(), (*v).clone())));
312317
}
313318

314-
let mut add_os = true;
315-
let mut add_rust = true;
316-
let mut add_device = true;
317-
318319
for (key, value) in scope.contexts.iter() {
319320
match *value {
320321
None => match key.as_str() {
@@ -332,33 +333,6 @@ impl Client {
332333
}
333334
}
334335

335-
if add_os {
336-
if let Some(ref os) = CONTEXT_DEFAULTS.os {
337-
event
338-
.contexts
339-
.entry("os".to_string())
340-
.or_insert_with(|| os.clone());
341-
}
342-
}
343-
344-
if add_rust {
345-
if let Some(ref rust) = CONTEXT_DEFAULTS.rust {
346-
event
347-
.contexts
348-
.entry("rust".to_string())
349-
.or_insert_with(|| rust.clone());
350-
}
351-
}
352-
353-
if add_device {
354-
if let Some(ref device) = CONTEXT_DEFAULTS.device {
355-
event
356-
.contexts
357-
.entry("device".to_string())
358-
.or_insert_with(|| device.clone());
359-
}
360-
}
361-
362336
if event.transaction.is_none() {
363337
if let Some(ref txn) = scope.transaction {
364338
event.transaction = Some((**txn).clone());
@@ -375,6 +349,30 @@ impl Client {
375349
}
376350
}
377351

352+
if add_os {
353+
if let Entry::Vacant(entry) = event.contexts.entry("os".to_string()) {
354+
if let Some(ref os) = CONTEXT_DEFAULTS.os {
355+
entry.insert(os.clone());
356+
}
357+
}
358+
}
359+
360+
if add_rust {
361+
if let Entry::Vacant(entry) = event.contexts.entry("rust".to_string()) {
362+
if let Some(ref rust) = CONTEXT_DEFAULTS.rust {
363+
entry.insert(rust.clone());
364+
}
365+
}
366+
}
367+
368+
if add_device {
369+
if let Entry::Vacant(entry) = event.contexts.entry("device".to_string()) {
370+
if let Some(ref device) = CONTEXT_DEFAULTS.device {
371+
entry.insert(device.clone());
372+
}
373+
}
374+
}
375+
378376
if event.release.is_none() {
379377
event.release = self.options.release.clone();
380378
}

0 commit comments

Comments
 (0)