Skip to main content

Sentry

Struct Sentry 

Source
pub struct Sentry { /* private fields */ }
Expand description

Reports spans at warning level or above that carry an error as Sentry issues.

Each event carries the error and its chain of causes (at most 10, root cause first), the trace context, http.url, http.method and http.query as the request, http.response.status_code as the response, and every other attribute (except span.* and level) as a context, tag or extra, as the classifier decides. A boolean span.handled attribute sets whether the error was handled; otherwise fatal spans are unhandled.

PHP: Utopia\Span\Exporter\Sentry. It sends with a PSR-18 client and waits for the reply; here the default HttpTransport sends in the background on the current runtime.

use std::sync::{Arc, Mutex};
use utopia_span::exporter::Request;
use utopia_span::{Exporter, Failure, Level, Sentry, Span};

let sent = Arc::new(Mutex::new(Vec::<Request>::new()));
let log = sent.clone();
let sentry = Sentry::new("https://publickey@sentry.example.com:9000/123")?
    .transport(move |request: Request| log.lock().unwrap().push(request));

let span = Span::new("test");
span.finish_with(Some(Level::Error), Some(Failure::new("RuntimeException", "Test error")));
assert!(sentry.sample(&span));
sentry.export(&span);

let request = &sent.lock().unwrap()[0];
assert_eq!(request.url, "https://sentry.example.com:9000/api/123/envelope/");
assert!(String::from_utf8_lossy(&request.body).contains(r#""value":"Test error""#));
use Utopia\Span\Exporter\Sentry;
use Utopia\Span\Span;

$sentry = new Sentry(dsn: 'https://publickey@sentry.example.com:9000/123');
$span = new Span('test');
$span->finish(error: new \RuntimeException('Test error'));
var_dump($sentry->sample($span)); // bool(true)
// $sentry->export($span) POSTs to https://sentry.example.com:9000/api/123/envelope/

Implementations§

Source§

impl Sentry

Source

pub fn new(dsn: &str) -> Result<Self, Error>

An exporter to the project of dsn (https://<key>@<host>/<project>).

Fails with Error::InvalidArgument when the DSN is empty, malformed, or lacks the key, host or project.

PHP: new Sentry(dsn: $dsn).

use utopia_span::Sentry;

assert!(Sentry::new("https://key@sentry.io/123").is_ok());
assert_eq!(Sentry::new("").unwrap_err().to_string(), "Sentry DSN is required");
assert_eq!(
    Sentry::new("https://sentry.io/123").unwrap_err().to_string(),
    "Invalid Sentry DSN: must include public key, host, and project ID",
);
use Utopia\Span\Exporter\Sentry;

try {
    new Sentry(dsn: 'https://sentry.io/123');
} catch (\InvalidArgumentException $e) {
    echo $e->getMessage(), "\n"; // Invalid Sentry DSN: must include public key, host, and project ID
}
Source

pub fn sampler( self, sampler: impl Fn(&Span) -> bool + Send + Sync + 'static, ) -> Self

Exports only the spans sampler accepts, among those at warning level or above: it narrows what is sent, never widens it.

PHP: the $sampler argument.

Source

pub fn environment(self, environment: impl Into<String>) -> Self

The environment events are tagged with (production).

PHP: the $environment argument.

Source

pub fn release(self, release: impl Into<String>) -> Self

The release events are tagged with (a version or commit).

PHP: the $release argument.

Source

pub fn server_name(self, server_name: impl Into<String>) -> Self

The server name events are tagged with.

PHP: the $serverName argument.

Source

pub fn classifier( self, classifier: impl Fn(&str) -> SentryField + Send + Sync + 'static, ) -> Self

Decides where each attribute goes; the default puts every attribute in the event’s context.

PHP: the $classifier argument.

Source

pub fn transport(self, transport: impl Transport + 'static) -> Self

Sends envelopes with transport instead of the default HTTP client.

PHP: the $client argument.

Source

pub fn request(&self, span: &Span) -> Option<Request>

The request this exporter sends for span, or None when the span has no error or its event cannot be encoded.

Trait Implementations§

Source§

impl Debug for Sentry

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Exporter for Sentry

Source§

fn sample(&self, span: &Span) -> bool

Whether to export span; false drops it. Read more
Source§

fn export(&self, span: &Span)

Exports a finished span. Called for spans Exporter::sample accepted. Read more

Auto Trait Implementations§

§

impl !RefUnwindSafe for Sentry

§

impl !UnwindSafe for Sentry

§

impl Forget for Sentry

§

impl Freeze for Sentry

§

impl Move for Sentry

§

impl Send for Sentry

§

impl Sync for Sentry

§

impl Unpin for Sentry

§

impl UnsafeUnpin for Sentry

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self> ⓘ

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self> ⓘ

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> ⓘ
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self> ⓘ

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more