NAME
Sentry::Web::Request - Internal: the request core of the web integrations
SYNOPSIS
# An adapter of a web framework or server
Sentry::Web::Request->in_scopes(sub ($isolation) {
my $request = Sentry::Web::Request->begin(
data => Sentry::Web::RequestData::Foo->new(req => $req),
name => "GET $path",
source => 'url',
origin => 'auto.http.foo',
);
my $response = eval { $app->handle($req) };
$request->fail if !$response;
$request->finish($response && $response->status);
...; # once the response is out
$request->release;
});
DESCRIPTION
Internal. What the official SDKs do in their WSGI or Rack middleware, for the adapters of web frameworks and servers: one request in one isolation scope, its request data (see Sentry::Web::RequestData) in the scope's request slot, an http.server transaction, and sending held back until the response is complete.
"begin" returns the adapter's Sentry::Web::Request::Handle. An adapter running inside another one (e.g. CGI::Application under mod_perl) adopts the outer request: it may rename and fail the request, names itself as the transaction's origin, and its request data replaces that of the outer adapter (frameworks parse the body, servers do not), or only adds the body where the server's view outlives the framework's (see Sentry::Web::RequestData::Adopted). When it finishes, its application has answered: it ends the transaction, while its objects are still alive for before_send and event processors. Without an HTTP status of its own, the transaction gets the one the outer adapter has seen so far (the CGI header printed under CGI or FastCGI). Ending the request (its session, sending) stays with the outer adapter.
METHODS
current
The unfinished request of the isolation scope in effect, or undef.
in_scopes
Runs the callback in clones of the scopes in effect, or in the scopes in effect if a request is being served there already.
begin
Starts or adopts the request and returns a handle, see "SYNOPSIS".
set_name
$request->set_name('GET /users/:id', 'route');
Names the transaction, unless the application renamed it (source custom, see "set_transaction_name" in Sentry::Scope).
drop_transaction
Drops the transaction of a request that turns out not to need one (e.g. a static file): it is neither finished nor sent.
fail
Marks the request as failed.
cancel
Marks the request as cancelled by the client.
finish
$request->finish($http_status);
Ends the request and its transaction, unless that has ended already; adapters call it through their handle.
finish_transaction
$request->finish_transaction($http_status);
Ends only the transaction; adapters inside another one call it through their handle's finish.
guarded
guarded(sub { ... });
Runs SDK code of an adapter: errors are logged, never thrown.