~/docs
Resonate
Resonate
0.x 0.3.0, current
Fledge APM
Toggle sidebar
Fledge APM
webpatser/fledge-apm 0.3.0

Fledge APM 0.x

Introduction

Fiber-aware OpenTelemetry tracing for Fledge apps, exported as OTLP to Elastic APM or any OTel backend.

Fledge APM is fiber-aware OpenTelemetry tracing for Fledge apps. Spans are exported as OTLP to Elastic APM or any other OTel backend.

Fledge runs work in parallel fibers: Livewire lazy cards, FiberDB::concurrent, anything you start with async(). Stock OTel context storage cannot follow that, so parallel work either bleeds into the wrong span or starts a trace of its own. Fledge APM keeps one active span per fiber, and a fiber started with async() inherits the span of whoever started it. A request with five parallel cards shows up as one trace with five sibling spans, and the queries nest under the card that ran them.

It is independent of Laravel Pulse. Pulse stays your at-a-glance dashboard; this gives you the per-request span trees.

What gets traced

Each source can be switched off under apm.instrumentation.

Source Recorded as
HTTP kernel Root transaction: route name, method, status code, user id. Back-dated to request start.
Queue jobs Consumer transaction per job. The traceparent travels in the job payload, so a job continues the trace that dispatched it.
Artisan commands Command transaction. Long-running or noisy commands (queue:work, queue:listen, horizon, horizon:*, pulse:work, pulse:check, schedule:work, reverb:start, octane:*, serve, tinker and a few more) are skipped; see apm.console.ignore.
Database queries DB span, back-dated by the query time. Statements are truncated at 2048 characters and bindings are never inlined.
Cache Cache spans for get, put and forget. Keys are not recorded by default.
HTTP client Client span per outgoing request of Laravel's Http client, with a traceparent header sent along. URLs are redacted.
Livewire A livewire update span per update request, with mount, update, hydrate, properties, call and render spans per component below it. For FiberHandleRequests batches each lazy card is a sibling span.
Exceptions Reported exceptions are recorded on the active span and mark the transaction as failed, which also makes the trace sampler keep it.

Spans are only created inside a trace, so a query run by something that has no transaction (a boot-time call, say) is skipped instead of creating orphan traces.

Known limits

  • Under Swoole, RoadRunner and FrankenPHP an idle worker keeps its buffered spans until its next request or until it stops.
  • Only Laravel's Http client is traced. Other clients (raw Guzzle, curl, SDKs with their own transport) are not.
  • While the circuit breaker is open, spans are dropped, not queued.
  • Raw EventLoop::queue() callbacks and Fledge's low-level server/IO loops do not carry trace context. Fibers started with async() do.

Elastic APM notes

Kibana's APM UI only reads the traces-apm*, metrics-apm* and logs-apm.error* data streams, and those are fed by an APM intake. Writing OTLP at a bare Elasticsearch cluster does nothing. You need one of:

  • APM Server
  • the Elastic Agent with the APM integration (Fleet)
  • an EDOT collector (Elastic Distribution of OpenTelemetry)

Point OTEL_EXPORTER_OTLP_ENDPOINT at that intake. Because this is plain OTLP, the same setup works with any other OTel backend (Tempo, Jaeger, Honeycomb, and so on).

Origins

Fledge's async layer started as a port of amphp and its event loop as a port of Revolt, both MIT licensed. Fledge has since gone its own way: PHP 8.6 only, shaped around Laravel, and maintained independently, so it does not track either project.

The package is MIT licensed. The event loop comes from Fledge Loop and the async layer from Fledge Fiber.