NAME

Sentry::Integration::ModPerl - Requests of a mod_perl 2 server

SYNOPSIS

# httpd.conf
PerlPassEnv SENTRY_DSN
PerlPassEnv SENTRY_RELEASE
PerlPassEnv SENTRY_ENVIRONMENT
PerlPostConfigRequire /path/to/startup.pl

# startup.pl
use Sentry::SDK;
Sentry::SDK->init({ dsn => $ENV{SENTRY_DSN}, traces_sample_rate => 0.1 });

DESCRIPTION

A default integration, active when the process runs under mod_perl 2. Initialized in the startup file, every request of the server runs in its own isolation and current scope and gets a transaction (op http.server), whatever handles it: ModPerl::Registry or ModPerl::PerlRun scripts, response handlers of any kind. Applications need no changes. Applications instrumented on their own, such as CGI::Application (see Sentry::Integration::CGIApplication), adopt the request: the transaction is renamed after their run mode. Apache's internal dummy connections (OPTIONS *, which the parent sends its children at graceful restarts and stops and when it reaps idle ones) are no one's requests: they get neither transaction nor session.

The transaction is named after method and path (GET /perl/hello.pl, source url; ids and tokens in the path become *) and ends with the HTTP status of the response; after an internal redirect (e.g. $r->internal_redirect, ErrorDocument), with that of its target. If the client closed the connection before the response was complete, it ends with cancelled and a breadcrumb says so. If a handler died (status 500 and an error-notes note, as mod_perl and ModPerl::Registry leave them), its message is captured as unhandled exception (mechanism auto.http.mod_perl), unless the application captured the error itself.

Events captured during the request are held back and sent in the cleanup phase, after the response has been sent; the worker serves no other request meanwhile. With "background_sender" in Sentry::SDK 1 and the prefork MPM, a sender process of each worker sends them instead. The request data of events contains method, URL, query string, headers and cookies (see Sentry::DataScrubber); the body only once an application instrumented on its own (such as CGI::Application) adopted the request.

Setup

mod_perl hides the environment of the server from Perl: SENTRY_DSN, SENTRY_RELEASE, SENTRY_ENVIRONMENT and the other SENTRY_* variables (e.g. SENTRY_SEND_DEFAULT_PII) reach the SDK only through PerlPassEnv or PerlSetEnv, as in the "SYNOPSIS". Without a DSN, init warns once under mod_perl; an empty one (dsn => '') turns the SDK off without a warning.

Sentry::SDK->init pushes a PerlPostReadRequestHandler, which starts the request and registers a cleanup of the request's pool that ends it. PerlCleanupHandlers of the configuration keep running. Initialize the SDK in the startup file, i.e. in the parent process: the children forked from it inherit the client, which is safe (see "SENDING" in Sentry::SDK). Initialized later in a child, that child's following requests are traced, and the request it is initialized in if mod_perl tells it (PerlOptions +GlobalRequest, the default of SetHandler perl-script). Without, that request cannot be told apart from the process: what it sets (e.g. the user) sticks to the following requests of the child.

Where the handler goes depends on where init runs:

  • In a <Perl> section: on the server, or virtual host, the section configures.

  • In a PerlPostConfigRequire or PerlRequire file: on the main server and every virtual host, unless virtual hosts have a Perl interpreter of their own (PerlOptions +Parent). mod_perl does not tell which interpreter runs the file, and a handler registered from another interpreter would fail every request of a server. So the SDK registers no handler there and warns at startup, unless a server of the configuration names it. Name the handler in each server that initializes the SDK this way:

    <VirtualHost ...>
      PerlOptions +Parent
      PerlPostConfigRequire /path/to/startup.pl
      PerlPostReadRequestHandler Sentry::Integration::ModPerl
    </VirtualHost>

A request is started once, however often the handler is configured.

Only the prefork MPM is supported and tested, with or without a Perl built with threads. Under a threaded MPM, mod_perl serves each request with one interpreter of a pool, so the scopes, which are global to an interpreter, would stay apart; but sending and flushing at exit are untested there, so the integration warns at startup.

FUNCTIONS

handler

PerlPostReadRequestHandler Sentry::Integration::ModPerl

The handler, for virtual hosts that have to name it (see "Setup").