Download the PHP package monkeyscloud/monkeyslegion-telemetry without Composer
On this page you can find all versions of the php package monkeyscloud/monkeyslegion-telemetry. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download monkeyscloud/monkeyslegion-telemetry
More information about monkeyscloud/monkeyslegion-telemetry
Files in monkeyscloud/monkeyslegion-telemetry
Package monkeyslegion-telemetry
Short Description Comprehensive telemetry package with PSR-3 logging, metrics (Prometheus/StatsD), and distributed tracing for MonkeysLegion projects
License MIT
Homepage https://monkeyslegion.com
Informations about the package monkeyslegion-telemetry
🐒 MonkeysLegion Telemetry 2.0
A production-grade observability toolkit for PHP 8.4+ providing metrics, distributed tracing, and structured logging in a single, unified package. Ships with Prometheus, StatsD, W3C Trace Context, and PSR-3/PSR-15 integrations out of the box.
What's New in 2.0
| Area | v1 | v2 |
|---|---|---|
| PHP version | 8.1+ | 8.4+ — readonly, final, enums, named args |
| Metrics | Basic Prometheus only | MetricsInterface — Prometheus, StatsD, InMemory, Null drivers |
| Tracing | ❌ | Full W3C Trace Context — spans, events, exporters |
| Logging | ❌ | PSR-3 TelemetryLogger with automatic trace correlation |
| Middleware | ❌ | PSR-15 RequestMetricsMiddleware + RequestTracingMiddleware |
| Attributes | ❌ | #[Traced], #[Counted], #[Timed] |
| Factory | Manual construction | TelemetryFactory::create() — one-line bootstrapping |
| Facade | ❌ | Telemetry::counter(), Telemetry::trace(), Telemetry::log() |
Features
📊 Metrics — Counter, Gauge, Histogram, Summary with Prometheus and StatsD backends
🔍 Distributed Tracing — W3C Trace Context compatible spans, events, and exception recording
📝 Structured Logging — PSR-3 logger with automatic trace/span ID injection
🌐 PSR-15 Middleware — Automatic HTTP request metrics and distributed tracing
🏷️ PHP 8 Attributes — #[Traced], #[Counted], #[Timed] for declarative instrumentation
🏭 Factory Pattern — One-line bootstrap via TelemetryFactory::create()
⚡ Zero-cost Null Drivers — NullMetrics, NullTracer for safe development
Installation
Optional Dependencies
Quick Start
One-line Bootstrap
Metrics
All metric drivers implement MetricsInterface and support Counter, Gauge, Histogram, Summary, and Timer operations.
Drivers
| Driver | Class | Use Case |
|---|---|---|
null |
NullMetrics |
Development — zero overhead |
memory |
InMemoryMetrics |
Testing, single-request |
prometheus |
PrometheusMetrics |
Production — Prometheus scraping |
statsd |
StatsDMetrics |
Production — StatsD / DogStatsD / Telegraf |
Counter (Monotonically Increasing)
Gauge (Point-in-Time Value)
Histogram (Distribution / Timing)
Timer Helper
Direct Driver Construction
Distributed Tracing
W3C Trace Context compatible tracing with automatic parent-child span relationships.
Traced Callback (Recommended)
Manual Span Management
Span Events
Trace Context Propagation
Span Kinds
| Kind | Use |
|---|---|
SpanKind::INTERNAL |
Default — internal application logic |
SpanKind::SERVER |
Incoming HTTP request handling |
SpanKind::CLIENT |
Outgoing HTTP / DB / RPC call |
SpanKind::PRODUCER |
Message queue publish |
SpanKind::CONSUMER |
Message queue consume |
Exporters
| Exporter | Class | Use Case |
|---|---|---|
console |
ConsoleExporter |
Local development / debugging |
http |
JsonHttpExporter |
OTLP/HTTP — Jaeger, Tempo, Zipkin |
| — | InMemoryExporter |
Unit testing |
Logging with Trace Correlation
PSR-3 compatible logging that automatically injects trace_id and span_id into every log entry.
Direct Logger Construction
Log Processors
PSR-15 Middleware
Request Metrics
Automatically records http_requests_total, http_request_duration_seconds, and http_requests_in_progress for every request.
Recorded metrics:
| Metric | Type | Labels |
|---|---|---|
http_requests_total |
Counter | method, route, status |
http_request_duration_seconds |
Histogram | method, route, status |
http_requests_in_progress |
Gauge | — |
Request Tracing
Creates a root SERVER span per request with W3C trace context propagation.
Span attributes:
| Attribute | Example |
|---|---|
http.method |
GET |
http.url |
https://api.example.com/users/42 |
http.target |
/users/42 |
http.status_code |
200 |
http.host |
api.example.com |
net.peer.ip |
192.168.1.1 |
PHP 8 Attributes
Declarative instrumentation via attributes. Combine with an AOP framework or the MonkeysLegion service container for automatic weaving.
#[Traced] — Automatic Span Creation
#[Counted] — Automatic Call Counting
#[Timed] — Automatic Duration Measurement
Factory & Configuration
TelemetryFactory
Configuration Reference
Metrics
| Key | Type | Default | Description |
|---|---|---|---|
driver |
string |
'null' |
null, memory, prometheus, statsd |
namespace |
string |
'app' |
Metric name prefix |
host |
string |
'127.0.0.1' |
StatsD host |
port |
int |
8125 |
StatsD port |
dogstatsd |
bool |
false |
Enable DogStatsD tag format |
sample_rate |
float |
1.0 |
StatsD sampling rate (0.0–1.0) |
prometheus_adapter |
Adapter |
InMemory |
Prometheus storage adapter |
Tracing
| Key | Type | Default | Description |
|---|---|---|---|
enabled |
bool |
true |
Enable/disable tracing |
service_name |
string |
'app' |
Service identifier |
sample_rate |
float |
1.0 |
Trace sampling rate (0.0–1.0) |
exporter |
string |
'console' |
console, http, none |
endpoint |
string |
'http://localhost:4318/v1/traces' |
OTLP endpoint |
headers |
array |
[] |
Extra HTTP headers for exporter |
Logging
| Key | Type | Default | Description |
|---|---|---|---|
stream |
string\|resource |
'php://stderr' |
Output stream |
level |
string |
'debug' |
Minimum log level (PSR-3) |
json |
bool |
false |
Enable JSON formatting |
pretty |
bool |
false |
Pretty-print JSON |
Complete Application Example
Prometheus Metrics Endpoint
Architecture
Testing
License
MIT © MonkeysCloud