PHP Observability
Also Known As
Monolog
OpenTelemetry PHP
PHP metrics
PHP tracing
TL;DR
The three pillars of observability in PHP applications — structured logs, application metrics, and distributed traces — and the tools that provide them (Monolog, Prometheus, OpenTelemetry).
Explanation
PHP observability toolkit: Logs (Monolog with structured JSON handlers — Loki, Elasticsearch, Datadog), Metrics (prometheus/client_php — expose /metrics for Prometheus scraping; StatsD for push-based metrics), Traces (opentelemetry-php or Datadog ddtrace auto-instrumentation — distributed tracing across services). PHP-specific considerations: PHP-FPM process-per-request model means metrics must persist across requests (shared memory via APCu or push to StatsD). Correlation IDs: generate a UUID per request, pass it in all log entries and outgoing HTTP headers — enables correlating logs, metrics, and traces for a single request.
Common Misconception
✗ Error logs are sufficient for production observability — error logs show what broke but not why or when degradation started; metrics show trends, traces show the critical path, and logs add context — all three are needed.
Why It Matters
A PHP application with only error logs cannot answer: is response time increasing? Which endpoint is slowest? When did performance degrade? Metrics and traces answer these questions that logs cannot.
Common Mistakes
- No correlation IDs — cannot connect related events across log lines and services.
- Logging without structure — plain text logs cannot be queried for specific fields.
- Metrics without labels — unlabelled counters cannot distinguish between endpoints.
- No request duration histogram — cannot calculate p95/p99 latency without it.
Code Examples
✗ Vulnerable
// Plain text logs — unsearchable:
error_log('Error processing order ' . $id . ' for user ' . $userId);
// Cannot query: all errors for user 42
// Cannot correlate with database traces
// Cannot alert when error rate exceeds threshold
✓ Fixed
// Structured observability:
// 1. Structured logging:
$logger->error('order.processing.failed', [
'order_id' => $id,
'user_id' => $userId,
'trace_id' => $this->traceId,
'duration_ms' => $elapsed,
]);
// 2. Metrics:
$counter->labels(['endpoint' => 'checkout', 'status' => '500'])->inc();
$histogram->labels(['endpoint' => 'checkout'])->observe($duration);
// 3. Trace propagation:
$span = $tracer->spanBuilder('order.process')->startSpan();
$span->setAttribute('order.id', $id);
finally { $span->end(); }
Tags
🤝 Adopt this term
£79/year · your link shown here
Added
16 Mar 2026
Edited
22 Mar 2026
Views
18
🤖 AI Guestbook educational data only
|
|
Last 30 days
Agents 0
No pings yet today
No pings yesterday
Amazonbot 8
Perplexity 2
Unknown AI 2
ChatGPT 2
Google 1
Ahrefs 1
Also referenced
How they use it
crawler 15
crawler_json 1
Related categories
⚡
DEV INTEL
Tools & Severity
🟡 Medium
⚙ Fix effort: Medium
⚡ Quick Fix
Instrument PHP with the OpenTelemetry auto-instrumentation package — it adds traces for HTTP, PDO, Redis, and queue calls with zero code changes
📦 Applies To
PHP 8.0+
web
cli
queue-worker
laravel
symfony
🔗 Prerequisites
🔍 Detection Hints
No APM tracing on PHP app; only infrastructure metrics no request-level visibility; slow requests hard to diagnose without traces
Auto-detectable:
✗ No
opentelemetry
datadog
newrelic
tideways
⚠ Related Problems
🤖 AI Agent
Confidence: Medium
False Positives: Medium
✗ Manual fix
Fix: Medium
Context: File