OpenTelemetry (Tracing and Metrics)
OpenTelemetry is tracing abstraction to collect and aggregate data such as metrics and traces. As OpenTelemetry is tracing abstraction is not force to use specific Tracing 3rd party. Depending on the need and preferences, we may choose provides like DataDog, Jaeger, Zipkin etc.
Ecotone brings full tracing using OpenTelemetry to your PHP applications, which will provide with details about your Message flows in the system, no matter if they run synchronously or asynchronously.
Installation
Configuration with Jaeger
We may use Jaeger for as our 3rd party Tracing System, which will is free open source option.
Install GRPC and Protobuf
This is needed to make Tracing insignificant to your Application performance.
Add Tracer Provider to Dependency Container
In order to use OpenTelemetry Support
we need to add TracerProviderInterface
to our Dependency Container.
By default OTelTracer will use localhost:4317
to push the logs, this is the port we've exposed in previous step, as this is where Jaeger exposes Collector.
You may now test integration by checking your Jaeger UI at localhost:16686
.
Auto-configuration
OpenTelemetry comes with auto configuration which allows us to to hook in into any method and class without modifying existing code. There are multiple preconfigured packages available, that can hook into PDO, Curl, Laravel or Symfony Requests etc.
Auto-packages - Read more about available packages
To make use of Auto-Instrumentation, we need to provide environment variables, that will be used to automatically configure it. This is needed, because auto-instrumentation may hook even before our Application is booted to provide full insightful details:
Installation and details - You may read more about installation here
When using environment variables to configure tracing instead of OTelTracer
in your Dependency Container, you may use inbuilt Tracer Provider that will create the Tracer based on environments:
Flushing Traces
By default Ecotone will flush traces
after Command/Query buses are executed or after handling Message asynchronously. This way traces will be propagated without any extra configuration.
However you may want to include bootstrap time for your HTTP Requests, and as Command Bus is executed after your Application is already bootstrapped, this won't be included.
So if you want to take over the process or use of auto-configuration for this, then you can disable force flushing in Ecotone:
If you've enabled auto-instrumentation for Laravel or Symfony, you may disable flush on Bus withForceFlushOnBusExecution(false)
, as traces will be pushed at the end of the Request.
Materials
Demo implementation
Links
Last updated