Download the PHP package cascata/hyperf-opentelemetry without Composer
On this page you can find all versions of the php package cascata/hyperf-opentelemetry. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download cascata/hyperf-opentelemetry
More information about cascata/hyperf-opentelemetry
Files in cascata/hyperf-opentelemetry
Package hyperf-opentelemetry
Short Description Drop-in OpenTelemetry integration for Hyperf 3.1+ (traces, metrics and logs via OTLP).
License MIT
Informations about the package hyperf-opentelemetry
cascata/hyperf-opentelemetry
Drop-in OpenTelemetry integration for Hyperf 3.1+ — traces, metrics and logs via OTLP, with sensible Swoole defaults.
Out of the box you get:
- HTTP server spans for every inbound request (
SERVERkind, W3C TraceContext propagation) #[Traced]attribute to wrap any service/use-case/repository method in a span- Correlation ID middleware (propagates
X-Correlation-Id) - Monolog handler that ships every log via OTLP, with
trace_id/span_idinjected automatically - Coroutine-safe trace context (survives the end of individual spans, so logs emitted by exception handlers still correlate)
- Optional Docker Compose stack with OTel Collector → Tempo / Prometheus / Loki / Grafana
Requirements
| PHP | >= 8.1 |
| Hyperf | ~3.1.0 |
| Swoole | >= 5.0 |
| ext-grpc | not required (uses OTLP HTTP) |
Install
Register the tracing middleware in config/autoload/middlewares.php:
Add the Monolog handler to config/autoload/logger.php (your existing config):
Set environment variables:
Clear the DI proxy cache and you're done:
Usage
Annotate methods you want traced
Span kinds:
Aspects only work on methods that:
- are public, non-static
- belong to classes resolved by the Hyperf container (DI)
Methods called via new ClassName() won't be intercepted.
Custom metrics
Publish optional resources
The package ships an optional config file and a complete Docker Compose stack.
The published stack lives at BASE_PATH/observability/. Bring it up with:
Grafana: http://localhost:3000 (anonymous Admin).
Architecture
The application only ever speaks OTLP to the collector. Swapping Tempo for Jaeger, or Loki for Elasticsearch, only changes the collector config — your code does not change.
Configuration reference
All values can be set via env or by publishing opentelemetry.php.
| Env var | Default | Purpose |
|---|---|---|
OTEL_ENABLED |
true |
Master switch |
OTEL_SERVICE_NAME |
hyperf-app |
service.name resource attribute |
OTEL_SERVICE_NAMESPACE |
default |
service.namespace |
OTEL_SERVICE_VERSION |
1.0.0 |
service.version |
OTEL_DEPLOYMENT_ENV |
dev |
deployment.environment.name |
OTEL_EXPORTER_OTLP_ENDPOINT |
http://otel-collector:4318 |
OTLP HTTP base URL |
OTEL_TRACES_SAMPLER_ARG |
1.0 |
TraceID-ratio sampler (0.0 – 1.0) |
Troubleshooting
No spans / logs / metrics arriving in Grafana
Verify the collector is reachable from inside the app container:
Enable internal debug logging:
Span::getCurrent() returns no-op span in exception handlers
That's why this package also stores trace_id/span_id in
Hyperf\Context — logs emitted after a span closes still correlate. No
action needed on your side.
Changes to #[Traced] annotations don't take effect
The Hyperf DI proxy cache must be regenerated:
Batch processor doesn't flush in Swoole
This package uses SimpleSpanProcessor / SimpleLogRecordProcessor by
default — they export synchronously, which is the safe choice in long-running
Swoole workers. For very high-throughput services, consider implementing a
periodic flush listener instead.
Versioning
| Branch | Hyperf | OTel SDK |
|---|---|---|
1.x |
~3.1.0 |
^1.1 |
Follows SemVer.
License
MIT
All versions of hyperf-opentelemetry with dependencies
hyperf/context Version ~3.1.0
hyperf/di Version ~3.1.0
hyperf/event Version ~3.1.0
hyperf/framework Version ~3.1.0
hyperf/http-server Version ~3.1.0
hyperf/logger Version ~3.1.0
open-telemetry/api Version ^1.1
open-telemetry/sdk Version ^1.1
open-telemetry/exporter-otlp Version ^1.1
open-telemetry/sem-conv Version ^1.27
php-http/guzzle7-adapter Version ^1.0
guzzlehttp/guzzle Version ^7.8
monolog/monolog Version ^3.0
ramsey/uuid Version ^4.7