informaticauco / simplesamlphp-module-ucowatchdog
SimpleSAMLphp 2.x module for GlitchTip/Sentry error reporting, SAML error classification, and diagnostics
Package info
github.com/InformaticaUCO/simplesamlphp-module-ucowatchdog
Type:simplesamlphp-module
pkg:composer/informaticauco/simplesamlphp-module-ucowatchdog
Requires
- php: >=8.3
- sentry/sentry: ^4.0
- simplesamlphp/composer-module-installer: ^1.3
Requires (Dev)
- phpunit/phpunit: ^10.5
- simplesamlphp/simplesamlphp: ^2.5
Suggests
None
Provides
None
Conflicts
None
Replaces
None
- dev-main
- 1.0.0
- dev-agent/issue-14-follow-getcause
- dev-agent/issue-10-defer-sends-after-response
- dev-agent/issue-8-inner-logging-handler
- dev-agent/issue-7-housekeeping
- dev-agent/issue-6-diagnostics-csp-csrf-i18n
- dev-agent/issue-5-ignored-error-codes-single-source
- dev-agent/issue-4-diagnostics-misleading-status
- dev-agent/issue-2-cross-request-circuit-breaker
- dev-fix/request-body-allowlist
- dev-fix/log-capture-aggregation
This package is auto-updated.
Last update: 2026-12-04 09:46:37 UTC
README
A SimpleSAMLphp 2.5+ module for automated error reporting to GlitchTip or Sentry (via the official sentry/sentry v4 PHP SDK), tailored for SAML Identity Providers and Service Providers.
Features
- SAML-aware exception capture (
hook_exception_handler):- Automatically tags events with
saml.error_code,saml.status,saml.sub_status,saml.sp_entity_id,saml.idp_entity_id,saml.authsource, andtrack_id(matching the tracking ID shown on SimpleSAMLphp's error page).
- Automatically tags events with
- Logging handler decorator (
WatchdogLoggingHandler):- Wraps your primary SimpleSAMLphp logging handler (
file,syslog,errorlog,stderr, or custom) without altering local log files. - Records preceding log entries as breadcrumbs and forwards
ERR/CRIT/ALERT/EMERGmessages. - Sends each logged error as one event: the backtrace SimpleSAMLphp logs line by line is attached to it, and the message is sent without date/track ID prefix so occurrences group into one issue.
- Caps log events per request (
max_log_events_per_request, default5). - Deduplicates exception logs emitted by
SimpleSAML\Error\Error::show(). - Keeps PHP fatal shutdown error capture enabled while avoiding duplicate exception/warning captures.
- Wraps your primary SimpleSAMLphp logging handler (
- Sends after the response (PHP-FPM, LiteSpeed):
- Events are queued and sent at shutdown, after finishing the response (
fastcgi_finish_request()/litespeed_finish_request()) and releasing the PHP session, so neither the page nor the user's next request waits for the collector. The worker stays busy until the sends end. - With native PHP sessions, a later shutdown function can no longer write to the session once an event has been sent.
- Under other SAPIs (mod_php, CLI) events are sent when captured and the user waits for the collector, up to
http_timeoutper event.
- Events are queued and sent at shutdown, after finishing the response (
- Circuit breaker for an unreachable collector:
- After a failed send (network error, timeout or 5xx) nothing is sent for
breaker_ttlseconds (default60), in any request. Then a single request retries. - State is a marker file in SimpleSAMLphp's
cachedir(orbreaker_dir). If it cannot be written, the pause only covers the failing request. - Covers every send, including fatal errors captured by the SDK. A warning is logged when it trips; the diagnostics page shows its state and can reset it.
- After a failed send (network error, timeout or 5xx) nothing is sent for
- Configurable SAML client-noise filter:
- Ignores common client-side/bot SAML errors by default (
NOSTATE,NOTFOUND,NOTFOUNDREASON,METHODNOTALLOWED,USERABORTED,WRONGUSERPASS). - SimpleSAMLphp errors are filtered by error code (
ignored_error_codes/SENTRY_IGNORED_ERROR_CODES): remove a code to report it. ignored_exceptionslists classes without an error code (default: Symfony'sMethodNotAllowedHttpExceptionandSimpleSAML\Error\InvalidCredential).
- Ignores common client-side/bot SAML errors by default (
- Privacy-first defaults:
send_default_pii => false, short HTTP timeouts (1sconnect /2stotal), and automatic scrubbing of sensitive keys (password,token,cookie,authorization,SAMLResponse, etc.).- Request body: field names are sent, values only for
SAMLRequest,RelayStateandusername. - URL, query string and
INFO/NOTICElog lines (as breadcrumbs) are sent as they are; they are already in your access and SimpleSAMLphp logs.
- Built-in Admin UI diagnostics:
- Adds a link under Admin → Configuration (
hook_configpage) and a configuration status check (hook_sanitycheck). - Provides an admin-only diagnostics page (
/simplesaml/module.php/ucowatchdog/diagnostics) to inspect active configuration (without exposing the DSN) and trigger test SAML errors, unhandled exceptions, error logs, or ignored errors.
- Adds a link under Admin → Configuration (
Requirements
- PHP
>= 8.3withext-curl,ext-json,ext-mbstring - SimpleSAMLphp
^2.5
Installation
composer require informaticauco/simplesamlphp-module-ucowatchdog
Copy the configuration template to your SimpleSAMLphp config/ directory:
cp vendor/simplesamlphp/simplesamlphp/modules/ucowatchdog/config-templates/module_ucowatchdog.php config/module_ucowatchdog.php
Configuration
1. Environment variables (standard)
These must be real environment variables of the PHP process: SimpleSAMLphp does not load .env files.
export SENTRY_DSN='https://<key>@glitchtip.example.org/<project_id>' export SENTRY_ENVIRONMENT=production export SENTRY_RELEASE=my-idp@1.0.0 # Optional comma-separated override of ignored SAML error codes: # export SENTRY_IGNORED_ERROR_CODES=NOSTATE,NOTFOUND,NOTFOUNDREASON,METHODNOTALLOWED,USERABORTED,WRONGUSERPASS
PHP-FPM clears the environment of its workers by default. Declare each variable in the pool configuration, or set clear_env = no to inherit them all:
env[SENTRY_DSN] = "https://<key>@glitchtip.example.org/<project_id>" env[SENTRY_ENVIRONMENT] = "production"
When SENTRY_DSN (and dsn in module_ucowatchdog.php) is empty, the module stays inactive with zero overhead.
2. Carry over the current logging.handler
The next step replaces logging.handler in config/config.php, and the module cannot know its previous value. Before replacing it, copy that value to inner_logging_handler in config/module_ucowatchdog.php:
'inner_logging_handler' => 'syslog', // the value logging.handler has now
- If
logging.handleris not set, use'syslog', SimpleSAMLphp's default on the web (on the command line it is'stderr'). - If you skip this step, logs go to a file (
logging.logfileinloggingdir) and stop reaching their previous destination, such as a central syslog server. - Valid values are
'file','syslog','errorlog','stderr'or the name of a class that implementsLoggingHandlerInterface, other thanWatchdogLoggingHandlerand its subclasses. With any other value SimpleSAMLphp writes all logs to PHP'serror_log, with aCRITline that names the problem, and log messages are not sent to GlitchTip/Sentry.
3. Enable in config/config.php
// Enable the module 'module.enable' => [ // ... 'ucowatchdog' => true, ], // Use WatchdogLoggingHandler (delegates to inner_logging_handler, see step 2) 'logging.handler' => \SimpleSAML\Module\ucowatchdog\Logger\WatchdogLoggingHandler::class, // Optional: hide the email error report form when GlitchTip/Sentry is configured 'errorreporting' => empty(getenv('SENTRY_DSN')),
Diagnostics & Verification
-
Log in as a SimpleSAMLphp administrator.
-
Open Admin → Configuration — you will see:
- A sanity check line showing whether Watchdog reporting is enabled.
- A sanity check line showing the inner logging handler in use, or why it cannot be used.
- A Watchdog error reporting diagnostics link under the configuration tools.
-
Open the diagnostics page (
/simplesaml/module.php/ucowatchdog/diagnostics) to view active settings (or append?format=json) and trigger test events:- SAML Error (
MetadataNotFound): verifies SAML tags,track_id, and error page rendering. - Unhandled PHP Exception: verifies uncaught exception reporting with breadcrumbs.
- Logger Error: verifies
WatchdogLoggingHandlerforwarding. - Ignored Client Error (
NoState): verifies the noise filter suppresses client noise.
Under PHP-FPM the test event is sent after the page is served: reload the page to see the circuit breaker state that results from it.
- SAML Error (
Development & Testing
composer install vendor/bin/phpunit vendor/bin/phpcs vendor/bin/phpstan analyse
License
EUPL-1.2 — see LICENSE.