Skip to content
Closed
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
3 changes: 2 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,10 @@ name = "sentry-rust-minidump"
version = "0.1.0"

[dependencies]
bincode = "1"
crash-handler = "0.3.1"
dirs-next = "2"
minidumper = "0.3.1"
sentry = {git = "https://github.com/getsentry/sentry-rust.git"}
sentry = {git = "https://github.com/timfish/sentry-rust.git", branch = "feat/scope-listener"}
thiserror = "1"
uuid = {version = "1", features = ["v4"]}
16 changes: 15 additions & 1 deletion src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ use crash_handler::{make_crash_event, CrashContext, CrashEventResult, CrashHandl
use std::{
fmt::Debug,
process::{Child, Command},
sync::Arc,
time::Duration,
};

Expand All @@ -26,8 +27,21 @@ pub fn start(release: &str) -> Result<(Child, CrashHandler), ClientStartError> {
let mut wait_time = 0;

loop {
match minidumper::Client::with_name(&socket_name) {
match minidumper::Client::with_name(&socket_name).map(Arc::new) {
Ok(client) => {
let cloned_client = client.clone();

sentry::configure_scope(|scope| {
scope.add_scope_listener(move |update| {
let encoded: Vec<u8> =
bincode::serialize(update).expect("should be able to serialise");

cloned_client
.send_message(1, &encoded)
.expect("IPC should work without fail no?");
})
});

#[allow(unsafe_code)]
match CrashHandler::attach(unsafe {
make_crash_event(move |crash_context: &CrashContext| {
Expand Down
26 changes: 23 additions & 3 deletions src/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use crate::socket_from_release;
use minidumper::{LoopAction, MinidumpBinary, Server, ServerHandler};
use sentry::{
protocol::{Attachment, AttachmentType, Event, Value},
Level,
Level, ScopeUpdate,
};
use std::{
fs::{self, File},
Expand Down Expand Up @@ -82,8 +82,28 @@ impl ServerHandler for Handler {
LoopAction::Exit
}

fn on_message(&self, _kind: u32, _buffer: Vec<u8>) {
//
fn on_message(&self, kind: u32, buffer: Vec<u8>) {
if let 1 = kind {
let update: ScopeUpdate =
bincode::deserialize(&buffer[..]).expect("should be valid bincode");

match update {
ScopeUpdate::AddBreadcrumb(b) => sentry::add_breadcrumb(b),
ScopeUpdate::ClearBreadcrumbs => {
sentry::configure_scope(|scope| scope.clear_breadcrumbs())
}
ScopeUpdate::User(user) => sentry::configure_scope(|scope| scope.set_user(user)),
ScopeUpdate::SetExtra(k, v) => {
sentry::configure_scope(|scope| scope.set_extra(&k, v))
}
ScopeUpdate::RemoveExtra(k) => {
sentry::configure_scope(|scope| scope.remove_extra(&k))
}
ScopeUpdate::SetTag(k, v) => sentry::configure_scope(|scope| scope.set_tag(&k, v)),
ScopeUpdate::RemoveTag(k) => sentry::configure_scope(|scope| scope.remove_tag(&k)),
_ => todo!(),
}
}
}
}

Expand Down