~/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

Configuration

Environment variables, sampling, batching, circuit breaker, instrumentation toggles and privacy options.

Publish the file with php artisan vendor:publish --tag=apm-config to get config/apm.php.

Environment variables

Variable Default What it does
APM_ENABLED false Master switch.
APM_SAMPLE_RATE 1.0 Share of new traces to keep (0.0 to 1.0).
APM_KEEP_ERRORS true Keep traces with a failed span even when the ratio dropped them.
APM_SLOW_THRESHOLD_MS 1000 Keep traces whose transaction took at least this long. 0 disables.
APM_EXPORTER otlp otlp exports over OTLP/HTTP; memory keeps spans in process (tests).
OTEL_SERVICE_NAME APP_NAME Service name in the APM UI.
OTEL_SERVICE_VERSION none Service version.
OTEL_DEPLOYMENT_ENVIRONMENT APP_ENV Environment label.
OTEL_EXPORTER_OTLP_ENDPOINT http://localhost:4318 Base URL; /v1/traces is appended.
OTEL_EXPORTER_OTLP_TRACES_ENDPOINT none Full traces URL, wins over the base endpoint.
OTEL_EXPORTER_OTLP_HEADERS none Comma separated key=value pairs, values URL encoded.
OTEL_EXPORTER_OTLP_PROTOCOL http/protobuf Or http/json. gRPC is not supported.
OTEL_EXPORTER_OTLP_COMPRESSION gzip Or none.
OTEL_EXPORTER_OTLP_TIMEOUT 2000 Per request, in milliseconds; always capped by the flush budget.
APM_EXPORT_CONNECT_TIMEOUT 1000 Connect timeout in milliseconds.
APM_EXPORT_MAX_RETRIES 3 Retries happen only on the final flush (queue WorkerStopping, shutdown).
APM_MAX_QUEUE_SIZE 2048 Most spans held in memory.
APM_MAX_EXPORT_BATCH_SIZE 128 Spans per export chunk.
APM_WORKER_FLUSH_INTERVAL 5 Seconds between flushes in queue and Octane workers.
APM_FLUSH_BUDGET_MS 1500 Bound for one whole flush, including timeouts and retries.
APM_BREAKER_ENABLED true Circuit breaker for failed exports.
APM_BREAKER_SECONDS 30 How long workers skip exporting after a failure.
APM_BREAKER_STORE none apcu, local (this process only) or a cache store name. Null picks APCu when enabled, else the default cache store.

Instrumentation

Each span source is a boolean under apm.instrumentation: http, queue, console, database, cache, http_client, livewire and exceptions. All default to true. They are only read when APM is enabled.

'instrumentation' => [
'http' => true,
'queue' => true,
'console' => true,
'database' => true,
'cache' => true,
'http_client' => true,
'livewire' => true,
'exceptions' => true,
],

apm.console.ignore takes command names and * patterns and replaces the built-in list of skipped commands. Null keeps the default; set it to [] to trace every command.

Sampling

Head sampling keeps APM_SAMPLE_RATE of new traces. Below 1.0, traces the ratio dropped are still recorded in memory, and are exported anyway when a span failed (keep.errors) or the transaction was slow (keep.slow_ms). For plain head sampling, set keep.errors to false and keep.slow_ms to 0; dropped traces then cost almost nothing.

An incoming traceparent is ignored by default, so a public client cannot choose your trace ids. Set apm.http.trust_traceparent to true to continue the caller's trace id when requests come from services you own (or a trusted proxy). Even then its sampled flag is not honored by default (apm.http.honor_sampled_flag), so an outside client cannot force or suppress sampling on your app. Turn it on if the caller is another service you own and you want one sampling decision across both.

Production safety

A tracer must never take your app down with it. Spans are buffered in process and exported after the response was sent (terminating callback, off the response path). Queue workers flush on an interval and once more when they stop.

Under Octane, spans are exported once APM_MAX_EXPORT_BATCH_SIZE spans are buffered or APM_WORKER_FLUSH_INTERVAL seconds have passed, checked when a request ends, and when the worker stops. Where the Fledge event loop runs (the Fledge server, torque workers), a background timer also exports an idle worker's spans every APM_WORKER_FLUSH_INTERVAL seconds. Under Swoole, RoadRunner and FrankenPHP no loop runs between requests, so an idle worker keeps its spans until its next request or until it stops. A worker killed without a clean stop (kill -9, a reload past its kill timeout) loses what was buffered since its last export: up to APM_MAX_EXPORT_BATCH_SIZE minus one spans plus the last request's spans, capped by APM_MAX_QUEUE_SIZE.

  • Flush budget: APM_FLUSH_BUDGET_MS bounds one whole flush. A slow or dead intake holds a PHP-FPM or queue worker for at most that long, and a flush stops at its first failed chunk.
  • No retries on hot paths: retries only happen on the final flush. After an HTTP response or between jobs it is one attempt per chunk.
  • Circuit breaker: after a failed export, every worker skips exporting for APM_BREAKER_SECONDS and drops its spans. "Export failure" log lines are throttled to one per window. Running out of the flush budget partway through a flush, after the intake accepted an earlier chunk, does not open the breaker (the rest of the batch is dropped). A first chunk that exhausts the budget, a failure that returns before the deadline (a 5xx or connect error), a request that runs past the flush deadline, and 3 budget cut-offs in a row on one worker still open it; a flush that exports everything resets that count.
  • Bounded memory: the queue holds at most APM_MAX_QUEUE_SIZE spans and exports in chunks of APM_MAX_EXPORT_BATCH_SIZE.

Privacy defaults

Option Default Notes
apm.http.record_client_ip false client.address.
apm.http.record_user_agent true user_agent.original.
apm.http.record_user_id true enduser.id.
apm.options.database.max_statement_length 2048 Longer statements are truncated.
apm.options.database.legacy_attributes true Also set the legacy db.system and db.statement attributes.
apm.options.database.record_bindings false Bindings are stripped from recorded exception messages.
apm.options.cache.record_keys false Cache keys can hold PII.
apm.options.http_client.propagate true Send a traceparent header on outgoing requests.
apm.options.http_client.error_on_4xx false Only 5xx and transport errors mark a client span as failed.
apm.options.http_client.record_full_path false Keeps the path in url.full verbatim.

Query bindings are never sent, request bodies and headers are never recorded, and outgoing URLs are redacted.

Outgoing URL paths

url.full on client spans drops userinfo and the fragment, and redacts credential-looking query values. Secrets carried in the path are replaced by REDACTED too: Telegram bot tokens, Slack and Discord webhook secrets, and any segment with a random-looking run of 32 or more characters (JWTs, percent-encoded base64 and segments with matrix params included).

UUIDs, version strings and ordinary file names stay readable. 32+ character hex identifiers such as Git SHAs, MD5 object keys and Gravatar hashes are hidden. Set apm.options.http_client.record_full_path to true to export the path verbatim; it applies to the whole app, and userinfo and query redaction still apply.

Limits:

  • A path secret shorter than 32 characters outside the known Telegram, Slack and Discord shapes is exported as is.

Query bindings

Bindings are never sent, but exception messages can still carry values:

  • A wrapper exception that rewords the SQL message instead of including it verbatim still exports what it wrote.
  • The database driver's own message is kept, so a message such as Duplicate entry '[email protected]' for key ... still contains the value.