Search by

informaticauco / simplesamlphp-module-ucowatchdog

decano

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

Statistics

Installs: 3

Dependents: 0

Suggesters: 0

Stars: 0

Open Issues: 1


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, and track_id (matching the tracking ID shown on SimpleSAMLphp's error page).
  • 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/EMERG messages.
    • 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, default 5).
    • Deduplicates exception logs emitted by SimpleSAML\Error\Error::show().
    • Keeps PHP fatal shutdown error capture enabled while avoiding duplicate exception/warning captures.
  • 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_timeout per event.
  • Circuit breaker for an unreachable collector:
    • After a failed send (network error, timeout or 5xx) nothing is sent for breaker_ttl seconds (default 60), in any request. Then a single request retries.
    • State is a marker file in SimpleSAMLphp's cachedir (or breaker_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.
  • 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_exceptions lists classes without an error code (default: Symfony's MethodNotAllowedHttpException and SimpleSAML\Error\InvalidCredential).
  • Privacy-first defaults:
    • send_default_pii => false, short HTTP timeouts (1s connect / 2s total), and automatic scrubbing of sensitive keys (password, token, cookie, authorization, SAMLResponse, etc.).
    • Request body: field names are sent, values only for SAMLRequest, RelayState and username.
    • URL, query string and INFO/NOTICE log 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.

Requirements

  • PHP >= 8.3 with ext-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.handler is 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.logfile in loggingdir) 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 implements LoggingHandlerInterface, other than WatchdogLoggingHandler and its subclasses. With any other value SimpleSAMLphp writes all logs to PHP's error_log, with a CRIT line 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

  1. Log in as a SimpleSAMLphp administrator.

  2. 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.
  3. 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 WatchdogLoggingHandler forwarding.
    • 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.

Development & Testing

composer install
vendor/bin/phpunit
vendor/bin/phpcs
vendor/bin/phpstan analyse

License

EUPL-1.2 — see LICENSE.