Skip to content

Reduce the overhead

Each request that records pays to boot the SDK, to record, and to merge into the store after the response. Work through this list, highest effect first.

Without it, booting the SDK costs about 1 ms per request instead of about 75 µs. In the deployment:

Terminal window
composer install --optimize-autoloader --no-dev

Or, after a plain install:

Terminal window
composer dump-autoload --optimize

A new connection per request adds a handshake to every merge. Set persistent on the store’s connection:

config/database.php
'metrics' => [
'host' => env('REDIS_METRICS_HOST', '127.0.0.1'),
'port' => env('REDIS_METRICS_PORT', '6379'),
'database' => env('REDIS_METRICS_DB', '0'),
'persistent' => true,
],

Prefer phpredis (REDIS_CLIENT=phpredis) to predis.

A remote Redis adds a network round trip to every merge. Run it in the same network, or the same availability zone, as the application servers.

If you run Redis yourself, prefer a glibc build to an Alpine (musl) build. Float-heavy merges run about 1.5 times faster on glibc.

  • Ignore the routes that probes and scrapers call often. See Ignore routes.
  • Turn off the instrumentation you do not use, such as METRICS_CACHE=false. A busy cache dispatches many events per request, and so does Eloquent: one event per model a query returns. See Turn off instrumentation.

Each new series costs Redis calls on its first merge, and memory for as long as the store lives. Check your own metrics and your Metrics::attributes() callbacks for values such as IDs or URLs. See Cardinality.

A value that you read from another system, such as a queue size, costs nothing per request when you read it at export time. See Read values at export time.

7. Use the cache store for development only

Section titled “7. Use the cache store for development only”

The cache store takes a lock on each merge, so writers wait for each other. Use the redis store in production.

To cut the boot further, to about 40 µs, preload the OpenTelemetry classes with OPcache (opcache.preload). Preloading needs a server restart after each deployment.