moodlehq / moodle-package-otel
OpenTelemetry integration for Moodle LMS
Requires
- ext-opentelemetry: *
- nyholm/psr7: *
- open-telemetry/api: ^1.1
- open-telemetry/opentelemetry-logger-monolog: *
- open-telemetry/sdk: ^1.13
- symfony/http-client: ^7.4
Requires (Dev)
- phpstan/phpstan: ^2
Suggests
- open-telemetry/opentelemetry-auto-postgresql: Auto-instrumentation for Postgresql
README
This is the OpenTelemetry integration for Moodle. It must be installed using composer, and requires the OpenTelemetry PHP Extension.
Installation
Open Telemetry requires the installation of the Open Telemetry PHP Extension.
After the installation of Moodle, and the Open Telemetry extension, this plugin can be installed using composer:
composer require moodlehq/moodle-package-otel
Exporters and Protocols must also be installed per your requirements, for example:
composer require open-telemetry/exporter-otlp
PHP Configuration will be required as described by your preferred exporter.
Overview
Auto-instrumentation hooks are registered via composer, and spans will be automatically created for (moodlelms):
- Every access (root span), including for:
- Web Requests
- CLI Usage
- When a web request is made using the Moodle Routing engine:
- App::handle() - update the root span with Routing-specific information
- InvocationStrategyInterface - controller/action
- RoutingMiddleware::performRouting - update the root span's name with either route name or pattern
Spans are also created for:
- Tasks (
moodlelms.cronlistener) - for the processing of each- scheduled task; and
- adhoc task.
- Moodle Events (
moodlelms.eventlistener) - for the processing of Logging Events at:- time of event dispatch; and
- time of bulk processing.
- Web Service Requests (
moodlelms.externalapilistener) - one span per external function call.
Configuration
The extension can be disabled via runtime configuration:
The core functionality and all child listeners can be disabled using:
OTEL_PHP_DISABLED_INSTRUMENTATIONS=moodlelms
To disable instrumentation for one of the groups of child listeners:
OTEL_PHP_DISABLED_INSTRUMENTATIONS=moodlelms.cronlistener
Adding additional instrumentation
You can add other auto-instrumentation using composer.
If you wish to create Moodle-specific instrumentation you can either do so as a standard Open Telemetry instrumentation, or you can create a Moodle Package.
Creating Moodle Open Telemetry Auto Instrumentation packages
To create your own page, you should:
- specify a package type of
moodle-package-otelhook - define your listeners with each listener implementing the
Moodlehq\MoodlePackageOtel\Instrumentation\MoodleListenerInterfaceinterface and optionally using theMoodlehq\MoodlePackageOtel\Instrumentation\MoodleListenerTraittrait - define a
\Namespace\Instrumentation\ListenersDescriberclass which implements\Moodlehq\MoodlePackageOtel\Instrumentation\ListenersDescriberInterface - define your listeners in the
ListenersDescriberclass