Configuration¶
The plugin has two modes. The prepend mode wins when it is configured; otherwise the plugin mode is used.
The tool_otel column of the tables shows whether the moodle-tool_otel plugin has an equivalent setting.
Plugin mode (default)¶
Configure it in Site administration > Plugins > Admin tools > Sentry Configuration. The SDK is started on the first Moodle event of each request, with the settings saved in the database. Errors that happen before that point (for example “Database connection failed”) are not sent.
Setting |
Description |
tool_otel |
|---|---|---|
|
Turns on sending to Sentry. |
❌ |
|
DSN of the Sentry project. |
✅ Equivalent: OTLP endpoint, protocol and headers. |
|
URL of the project’s JavaScript Loader, to capture browser errors. |
❌ |
|
Release name. |
❌ |
|
Environment name ( |
❌ |
|
Server name sent with the events. |
❌ |
|
Sends personal data added by the SDK integrations. Off by default. |
❌ |
|
Error sample rate, from 0.0 to 1.0. |
❌ |
|
Turns on SDK tracing. |
✅ The whole plugin is about tracing. |
|
Trace sample rate, from 0.0 to 1.0. |
✅ Sampling rate. |
|
Profiling sample rate. Depends on tracing. |
❌ |
|
Maximum number of breadcrumbs per event. |
❌ |
|
How much of the request body is sent ( |
❌ |
|
Attaches a stack trace to messages too, not only to exceptions. |
❌ |
|
Maximum length of event texts before they are cut. |
❌ |
|
Error types reported, in the format of PHP’s |
❌ |
|
Exception classes that are not sent. |
❌ |
|
Transaction names that are not sent. |
❌ |
|
Module prefixes that belong or do not belong to the application, to highlight your own code in the stack trace. |
❌ |
The page also has the connection test button (see Usage).
Prepend mode (before Moodle)¶
Available from version 5.3.0 (Moodle 5.3). PHP loads admin/tool/sentry/prepend.php before every script (web and CLI), so Sentry starts before config.php, the database and the plugin settings. The mode is used only when both conditions are true:
auto_prepend_filepoints to the plugin’sprepend.php;the
SENTRY_DSNenvironment variable is set.
In php.ini (or a file in conf.d, for example 30-sentry.ini):
; Moodle 5.3 keeps the code in public/.
auto_prepend_file=/var/www/html/public/admin/tool/sentry/prepend.php
In this mode the plugin does not start the SDK again and ignores the PHP options of the settings page; only the JavaScript Loader is still used. The settings page shows a notice when the mode is active.
Variable |
Default |
Description |
tool_otel |
|---|---|---|---|
|
DSN of the project. Required. |
✅ |
|
|
|
Environment name. |
❌ |
|
Release name, for example the image tag ( |
❌ |
|
|
|
Error sample rate, from 0.0 to 1.0. |
❌ |
|
|
Comma separated exception classes; replaces the default list. |
❌ |
|
|
|
❌ |
Fixed options in this mode: request bodies are never sent; no personal data is sent by default; the values of sensitive parameters (token, wstoken, password, sesskey, key, secret, code, ticket…) are replaced with [Filtered]; events are tagged with the Moodle component, the error code and the running task.
Trace continuation (from 5.3.5): when the request has a valid W3C traceparent header (version 00), for example created by the web server, PHP events continue that trace. The trace id is the same in Sentry (search trace:<id> or the trace_id tag), in the web server logs and wherever else the header is logged. sentry-php only reads sentry-trace, so the plugin converts the header; the sampling stays with this site. A sentry-trace header (with its baggage) is used instead only when there is no traceparent or both have the same trace id. Malformed headers are ignored. With the browser SDK from environment variables, the events of the page get the trace_id tag of the request that served it.
The variables must reach PHP:
PHP-FPM:
clear_env = noin the pool, orenv[SENTRY_DSN] = ...(orfastcgi_param SENTRY_DSN ...in nginx).Apache (mod_php):
SetEnv SENTRY_DSN ....Docker:
environment:of the PHP container.CLI (cron): the variables of the shell that runs
admin/cli/cron.php.
Optional: exceptions thrown inside lib/setup.php (for example, with the database down) reach Moodle’s handler before the plugin can chain the handlers. To capture them too, wrap the last line of config.php:
try {
require_once(__DIR__ . '/lib/setup.php');
} catch (\Throwable $e) {
if (class_exists('\tool_sentry\local\prepend', false)) {
\tool_sentry\local\prepend::capture($e);
}
throw $e;
}
To go back to the plugin mode, remove auto_prepend_file or unset SENTRY_DSN.
Browser SDK from environment variables¶
The javascriptloader setting starts the browser SDK through the Sentry JavaScript Loader, read from the database. Sites configured by environment variables (prepend mode) can do the same for the browser:
Variable |
Meaning |
|---|---|
|
DSN of the browser project (usually a different project from PHP). Required. |
|
URL of the SDK bundle ( |
|
Share of browser errors sent, from 0.0 to 1.0. Default 1.0. |
|
The same values used by the PHP SDK. |
With both SENTRY_JS_DSN and SENTRY_JS_SRC set, the plugin adds the script to the <head> of every page (hook before_standard_head_html_generation) and the javascriptloader setting is not used.
In both modes the browser script:
replaces the values of sensitive URL parameters (
sesskey,token,wstoken,password,key,secret,code,ticket) with[Filtered], in the events and in the breadcrumbs, and removes cookies and headers from the request data, except theUser-Agent, which Sentry needs to show the browser and the operating system;drops the events of pages where the core scripts of Moodle did not load (
M.utilundefined): there every script of the page fails and the cause is in the browser (network drop, content blocker);removes the JavaScript revision from the stack frames (see Issue grouping);
ignores browser noise: network failures (
Load failed,Failed to fetch),out of memory, extensions, Google Analytics and Tag Manager, and Android/iOS webviews;sends errors only from scripts of the site (
allowUrls=$CFG->wwwroot), without personal data (sendDefaultPiioff); the numeric user id only withSENTRY_SEND_USER_ID=true.