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
impl Sentry
Sourcepub fn new(dsn: &str) -> Result<Self, Error>
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
}Sourcepub fn sampler(
self,
sampler: impl Fn(&Span) -> bool + Send + Sync + 'static,
) -> Self
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.
Sourcepub fn environment(self, environment: impl Into<String>) -> Self
pub fn environment(self, environment: impl Into<String>) -> Self
The environment events are tagged with (production).
PHP: the $environment argument.
Sourcepub fn release(self, release: impl Into<String>) -> Self
pub fn release(self, release: impl Into<String>) -> Self
The release events are tagged with (a version or commit).
PHP: the $release argument.
Sourcepub fn server_name(self, server_name: impl Into<String>) -> Self
pub fn server_name(self, server_name: impl Into<String>) -> Self
The server name events are tagged with.
PHP: the $serverName argument.
Sourcepub fn classifier(
self,
classifier: impl Fn(&str) -> SentryField + Send + Sync + 'static,
) -> Self
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.