|
1 |
| -# symfony-otel-bundle |
2 |
| -OpenTelemetry client Bundle |
| 1 | +# Symfony OpenTelemetry client Bundle |
| 2 | +This bundle provides configured official otel bundle for Symfony application under the hood. |
| 3 | +In addition, it provides a general way to configure telemetry collection via configuration list of Kernel listeners. |
| 4 | + |
| 5 | +## Setup bundle |
| 6 | +Enable bundle in your Symfony application: |
| 7 | +```php |
| 8 | +return [ |
| 9 | + Macpaw\SymfonyOtelBundle\SymfonyOtelBundle::class => ['all' => true], |
| 10 | + // ... |
| 11 | +]; |
| 12 | +``` |
| 13 | + |
| 14 | +## Configuration understanding |
| 15 | +This bundle is a decoration under [https://github.com/opentelemetry-php/contrib-sdk-bundle](https://github.com/opentelemetry-php/contrib-sdk-bundle) to simplify integration with the official bundle and provide generic kernel listeners for data tracing. |
| 16 | +If you want to get more information about configuration, please refer to the official bundle documentation. |
| 17 | + |
| 18 | +## Setup bundle |
| 19 | + |
| 20 | +## Kernel event listeners |
| 21 | +Example of kernel event listener implementation can be found in `Macpaw\SymfonyOtelBundle\Span\ExecutionTimeSpanTracer` class. |
| 22 | +When specific listener need to be configured, you need to add it to `span_tracers` list in configuration after implementation. |
| 23 | + |
| 24 | +### Example |
| 25 | + |
| 26 | +1. Create a custom span tracer class: |
| 27 | + |
| 28 | + ```php |
| 29 | + namespace Macpaw\SymfonyOtelBundle\Span; |
| 30 | + |
| 31 | + use Symfony\Component\EventDispatcher\EventSubscriberInterface; |
| 32 | + use OpenTelemetry\API\Trace\Span; |
| 33 | + |
| 34 | + class CustomSpanTracer implements EventSubscriberInterface |
| 35 | + { |
| 36 | + public function onKernelRequest(RequestEvent $event): void |
| 37 | + { |
| 38 | + $span = Span::startSpan('custom_span'); |
| 39 | + // Add custom tracing logic here |
| 40 | + $span->end(); |
| 41 | + } |
| 42 | + |
| 43 | + public static function getSubscribedEvents(): array |
| 44 | + { |
| 45 | + return [ |
| 46 | + KernelEvents::REQUEST => 'onKernelRequest', |
| 47 | + ]; |
| 48 | + } |
| 49 | + } |
| 50 | + ``` |
| 51 | + |
| 52 | +2. Register the custom span tracer in the Symfony configuration: |
| 53 | + |
| 54 | + ```yaml |
| 55 | + # config/packages/symfony_otel.yaml |
| 56 | + symfony_otel: |
| 57 | + span_tracers: |
| 58 | + - App\Span\CustomSpanTracer |
| 59 | + ``` |
| 60 | + |
| 61 | +## Environment Variables |
| 62 | + |
| 63 | +This bundle supports the following OpenTelemetry SDK environment variables for configuration: |
| 64 | + |
| 65 | +- `OTEL_RESOURCE_ATTRIBUTES`: Key-value pairs to be used as resource attributes. |
| 66 | +- `OTEL_SERVICE_NAME`: The name of the service. |
| 67 | +- `OTEL_TRACES_EXPORTER`: The exporter to be used for traces. |
| 68 | +- `OTEL_METRICS_EXPORTER`: The exporter to be used for metrics. |
| 69 | +- `OTEL_LOGS_EXPORTER`: The exporter to be used for logs. |
| 70 | +- `OTEL_EXPORTER_OTLP_ENDPOINT`: The endpoint for the OTLP exporter. |
| 71 | +- `OTEL_EXPORTER_OTLP_HEADERS`: Headers to be sent with each OTLP request. |
| 72 | +- `OTEL_EXPORTER_OTLP_TIMEOUT`: Timeout for OTLP requests. |
| 73 | +- `OTEL_PROPAGATORS`: Propagators to be used for context propagation. |
| 74 | +- `OTEL_TRACES_SAMPLER`: The sampler to be used for traces. |
| 75 | +- `OTEL_TRACES_SAMPLER_ARG`: Arguments for the trace sampler. |
| 76 | + |
| 77 | +For a complete list and detailed descriptions, please refer to the [OpenTelemetry SDK Environment Variables documentation](https://opentelemetry.io/docs/specs/otel/configuration/sdk-environment-variables/). |
0 commit comments