Integration of the OpenTelemetry PHP library with Drupal. More info about OpenTelemetry »
This allows you to see not only the total execution time of the Drupal Request, but also detailed information about internal processes like time spent on preparing the Request, SQL queries, etc.
The module was presented at DrupalCon Singapore 2024 - here is the presentation and the slides.
Quick start
If you are new to observability, telemetry, and all that stuff - here are the easy steps to make it work directly on your localhost out of the box, using ddev:
- Install Drupal using DDEV
- Install an OpenTelemetry Receiver locally, for example from Grafana:
ddev get MurzNN/ddev-grafana && ddev restart
- Install and enable the Drupal OpenTelemetry module:
composer require drupal/opentelemetry && drush en opentelemetry
- Go to the
/admin/config/development/opentelemetry
and set the endpoint tohttp://opentelemetry-grafana:4318
- Open the Grafana Web UI on the url like
https://your-project-name.ddev.site:3000/
, click on the "Explore" item on the left menu, and choose the "Traces" in the dropdown.
Usage example in your custom code:
$this->openTelemetryTracer = \Drupal::service('opentelemetry.tracer');
$tracer = $this->openTelemetryTracer->getTracer();
$mainSpan = $tracer->spanBuilder('My custom operation')->startSpan();
// Make an external API call.
$apiCallSpan = $tracer->spanBuilder("Coindesk API call")->startSpan();
$data = json_decode(
file_get_contents('https://api.coindesk.com/v1/bpi/currentprice.json')
);
$apiCallSpan->end();
// Set attributes and put an event to the main span.
$bots = 3;
$mainSpan->setAttribute('Bitcoin value', $data->bpi->USD->rate_float);
$mainSpan->addEvent('Starting bots tuning', ['bots available' => $bots]);
for ($i = 1; $i <= $bots; $i++) {
$innerSpan = $tracer->spanBuilder("Tuning bot $i")->startSpan();
// Do some internal business logic.
usleep(rand(200000, 500000));
$raised[$i] = rand(0, 100);
$innerSpan->addEvent("Bot $i raised money!", ['amount' => $raised[$i]]);
usleep(rand(100000, 200000));
$innerSpan->end();
}
// Do some more stuff and finalize the main span.
usleep(rand(200000, 500000));
$mainSpan->addEvent('We got richer!', ['raised' => array_sum($raised)]);
$mainSpan->setAttribute('raised_details', $raised);
$mainSpan->end();
Supporting this Module
You can convey gratitude to me for the development of the module and motivate me to do more through these services:
Project information
- Module categories: Developer tools, Integrations, Performance
- 72 sites report using this module
- Created by murz on , updated
- Stable releases for this project are covered by the security advisory policy.
There are currently no supported stable releases.
Releases
Improved OpenTelemetry format for logs
Development version: 1.0.x-dev updated 19 Dec 2024 at 16:12 UTC