Function sentry::add_breadcrumb

source ·
pub fn add_breadcrumb<B: IntoBreadcrumbs>(breadcrumb: B)
Expand description

Records a breadcrumb by calling a function.

The total number of breadcrumbs that can be recorded are limited by the configuration on the client. This function accepts any object that implements IntoBreadcrumbs which is implemented for a varienty of common types. For efficiency reasons you can also pass a closure returning a breadcrumb in which case the closure is only called if the client is enabled.

The most common implementations that can be passed:

  • Breadcrumb: to record a breadcrumb
  • Vec<Breadcrumb>: to record more than one breadcrumb in one go.
  • Option<Breadcrumb>: to record a breadcrumb or not
  • additionally all of these can also be returned from an FnOnce()

Example

use sentry::protocol::{Breadcrumb, Map};

sentry::add_breadcrumb(|| Breadcrumb {
    ty: "http".into(),
    category: Some("request".into()),
    data: {
        let mut map = Map::new();
        map.insert("method".into(), "GET".into());
        map.insert("url".into(), "https://example.com/".into());
        map
    },
    ..Default::default()
});