Configuration

Installation

composer require ecotone/open-telemetry

Configuration with Jaeger

We may use Jaeger for as our 3rd party Tracing System, which will is free open source option.

docker run -p 16686:16686 -p 4317:4317 -e COLLECTOR_OTLP_ENABLED=true jaegertracing/all-in-one:latest

Install GRPC and Protobuf

There are two ways of sending traces, over HTTP or GRPC with Protobuf. It's recommended to use the second approach, as it avoids putting pressure on your Application performance.

# Install PHP Extensions
install-php-extensions grpc protobuf
# Install PHP Packages in your application
composer require open-telemetry/transport-grpc
composer require open-telemetry/exporter-otlp

Add Tracer Provider to Dependency Container

In order to use OpenTelemetry Support we need to add TracerProviderInterface to our Dependency Container.

# config/services.yaml
OpenTelemetry\API\Trace\TracerProviderInterface:
    class: OpenTelemetry\API\Trace\TracerProviderInterface
    factory: ['Ecotone\OpenTelemetry\Support\OTelTracer', 'create']

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.

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:

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 we may want to start tracing before Application is bootstrapped. This way we will be able to see time how much time Application have spent on bootstrapping vs actual processing. So if you want to take over the process or use of auto-configuration for this, then you can disable force flushing in Ecotone:

Last updated

Was this helpful?