#![cfg_attr(docsrs, feature(doc_cfg))]
#![cfg_attr(
feature = "document-features",
cfg_attr(doc, doc = ::document_features::document_features!(
feature_label =
r#"<span class="stab portability"><code>{feature}</code></span>"#
)
)
)]
#![doc = include_str!("../README.md")]
pub mod common;
#[cfg_attr(docsrs, doc(cfg(feature = "error-client")))]
#[cfg(feature = "error-client")]
pub mod error;
#[cfg_attr(docsrs, doc(cfg(feature = "session-client")))]
#[cfg(feature = "session-client")]
pub mod session;
#[cfg(test)]
mod test {
pub mod doctest_support {
#[test]
#[allow(unused)]
#[cfg(all(feature = "session-client", feature = "ureq", feature = "sync"))]
pub fn sessions_synchrous_ureq() {
use crate::common::builder::client_builder::ClientBuilder;
use crate::common::traits::backend_builder_trait_sync::BackendBuilderTraitSync;
use crate::common::traits::client_trait_sync::ClientTraitSync;
let mut cb = ClientBuilder::session();
cb.configure(
"Your API key goes here",
"A name to identify your application",
"Notifier version",
"dev",
"Application version",
);
let mut client = cb.ureq().build().unwrap();
#[cfg(norun)]
let result = client.send();
#[cfg(norun)]
if result.is_ok() {
let response = result.unwrap();
if response.status() != 200 {
} else {
}
} else {
}
}
#[test]
#[allow(unused)]
#[cfg(all(feature = "session-client", feature = "reqwest", feature = "async"))]
pub fn sessions_asynchronous_reqwest() {
use crate::common::bundle::*;
let mut cb = ClientBuilder::session();
cb.configure(
"Your API key goes here",
"A name to identify your application",
"Notifier version",
"dev",
"Application version",
);
let mut client = cb.reqwest().non_blocking().build().unwrap();
#[cfg(norun)]
match client.send().await {
Ok(response) => {
},
Err(error) => {
},
}
}
}
#[test]
#[allow(unused)]
#[cfg(all(feature = "error-client", feature = "reqwest", feature = "async"))]
pub fn error_asynchronous_reqwest() {
use crate::common::builder::client_builder::ClientBuilder;
use crate::common::traits::decider_trait_async::DeciderTraitAsync;
use crate::common::traits::backend_builder_trait_async::BackendBuilderTraitAsync;
use crate::common::traits::client_trait_async::ClientTraitAsync;
let mut cb = ClientBuilder::error();
cb.configure(
"Your API key goes here",
"An error class for your message",
"The error message you wish to record",
"Notifier name",
"Notifier version",
"Rust 1.82.0 with lemon-bugsnag-rs",
"dev"
);
let mut client = cb.reqwest().non_blocking().build().unwrap();
#[cfg(norun)]
match client.send().await {
Ok(response) => {
},
Err(error) => {
},
}
}
#[test]
#[allow(unused)]
#[cfg(all(feature = "error-client", feature = "reqwest", feature = "sync"))]
pub fn error_synchronous_reqwest() {
use crate::common::bundle::*;
let mut cb = ClientBuilder::error();
cb.configure(
"Your API key goes here",
"An error class for your message",
"The error message you wish to record",
"Notifier name",
"Notifier version",
"Rust 1.82.0 with lemon-bugsnag-rs",
"dev"
);
let mut client = cb.reqwest().blocking().build().unwrap();
#[cfg(norun)]
match client.send() {
Ok(response) => {
},
Err(error) => {
}
}
}
#[cfg(feature = "error-client")]
pub mod test_error_utility {
#[cfg(feature = "optional-builders")]
use crate::error::payload::events::event::EventBuilder;
use crate::error::{
error_client_builder::ErrorClientBuilder,
payload::{
events::{
enums::{BreadcrumbType, RuntimeType, Severity},
Breadcrumb, Event, Exception, StackTrace, StackTraceCode,
},
notifier::Dependency,
notifier::Notifier as ErrorNotifier,
},
};
use crate::{
common::builder::client_builder::ClientBuilder,
error::payload::events::App,
};
pub fn get_error_client_builder() -> ErrorClientBuilder {
let mut cb = ClientBuilder::error();
cb.set_host("notify.bugsnag.com")
.set_scheme("https")
.set_api_key(std::env::var(
"NAB_BUGSNAG_RS_API_KEY"
).unwrap_or_else(|_| {
assert!(false, "NAB_BUGSNAG_RS_API_KEY not found in environment, or contains invalid unicode");
"".to_string()
}).as_str());
cb.set_notifier(
ErrorNotifier {
name: "Name".to_string(),
version: "Version".to_string(),
url: "Url".to_string(),
dependencies: Some([
Dependency {
name: "Dependency 1".to_string(),
version: "Dependency 1 version".to_string(),
url: "Dependency 1 url".to_string()
},
Dependency {
name: "Dependency 2".to_string(),
version: "Dependency 2 Version".to_string(),
url: "Dependency 2 Url".to_string()
},
].to_vec()),
}
)
.set_events(
[
Event {
app: Some(App {
id: None
, version: Some("1.0.2".to_string())
, version_code: Some(1)
, bundle_version: None
, code_bundle_id: None
, build_uuid: None
, release_stage: None
, app_type: None
, dsym_uuids: None
, duration: None
, duration_in_foreground: None
, in_foreground: None
, is_launching: None
, binary_arch: None
, running_on_rosetta: None
})
, breadcrumbs: Some([Breadcrumb {
timestamp: "Right now".to_string()
, name: "This is the name of a breadcrumb".to_string()
, breadcrumb_type: BreadcrumbType::Navigation
, meta_data: Some([
("Metadata key one".to_string()
, "Metadata value one".to_string()),
("Metadata key two".to_string()
, "Metadata value two".to_string())
].into()) }].to_vec())
, context: None
, device: None
, exceptions: [Exception { error_class: "Exception name goes here".to_string()
, message: Some("This is an error message".to_string())
, stack_trace: [
StackTrace {
file: "this is the file the error occurred in".to_string()
, line_number: 42
, column_number: Some(128)
, method: "method_name()".to_string()
, in_project: Some(true)
, code: Some(StackTraceCode {
code: [
(10, "This is the code on line 2".to_string())
, (2, "This is the code on line 2".to_string())
, (6, "This is the code on line 2".to_string())
, (4, "This is the code on line 4".to_string())
, (8, "This is the code on line 4".to_string())
, (12, "This is the code on line 4".to_string())
].into()
})
, frame_address: Some("0x00BFD60000".to_string())
, load_address: Some("0x0000000000".to_string())
, is_lr: Some(false)
, is_pc: Some(false)
, symbol_address: Some("0x00bb00bbdd".to_string())
, macho_file: Some("we don't have this nosnense".to_string())
, macho_load_address: Some("0x00ffff00dd".to_string())
, macho_uuid: Some("asdffdsaqwerrewq".to_string())
, macho_vm_address: Some("Come on, now".to_string())
, code_identifier: Some("this is probably going to be a hash of the binary or something".to_string())
}].to_vec()
, runtime_type: Some(RuntimeType::Go) }].to_vec()
, feature_flags: None
, grouping_hash: None
, meta_data: Some([
("Metadata key one".to_string()
, "Metadata value one".to_string()),
("Metadata key two".to_string()
, "Metadata value two".to_string())
].into())
, project_packages: None
, request: None
, session: None
, severity: Some(Severity::Info)
, severity_reason: None
, threads: None
, unhandled: None
, user: None
}
].to_vec()
);
cb
}
#[cfg(feature = "optional-builders")]
#[allow(dead_code)]
pub fn get_event_builder() -> EventBuilder {
let mut event_builder = EventBuilder::default();
let mut exception_builder = Exception::builder();
exception_builder.set_error_class("get_event_builder exception");
let mut stack_trace_builder = StackTrace::builder();
stack_trace_builder.set_file("File");
stack_trace_builder.set_line_number(2);
stack_trace_builder.set_method("get_event_builder()");
exception_builder
.set_stack_trace(stack_trace_builder.build().unwrap());
event_builder
.set_exceptions([exception_builder.build().unwrap()].to_vec());
event_builder
}
#[allow(dead_code)]
pub fn extract_event_at_index(
client_builder: &ErrorClientBuilder,
index: usize,
) -> Event {
let events = client_builder.events().unwrap();
let event = events.get(index).unwrap().to_owned();
event
}
}
}