opentelemetry-php
opentelemetry-php copied to clipboard
OpenTelemetry Laravel with Zipkin not creating auto spans
Issue Description:
I'm encountering an issue where OpenTelemetry Laravel is not generating auto spans when using Zipkin as the exporter. I've followed the official documentation (https://opentelemetry.io/docs/languages/php/automatic/) for Laravel instrumentation and configured the Zipkin exporter correctly.
Environment:
- PHP version: 8.3.3
- Laravel version: 8
- Instrumentation Libraries: https://packagist.org/packages/open-telemetry/opentelemetry-auto-laravel
- Exporter: https://packagist.org/packages/open-telemetry/exporter-zipkin
Environment Variables:
- OTEL_PHP_AUTOLOAD_ENABLED=true
- OTEL_SERVICE_NAME=fooobar
- OTEL_TRACES_EXPORTER=zipkin
- OTEL_PROPAGATORS=baggage,tracecontext
- OTEL_EXPORTER_ZIPKIN_ENDPOINT=http://zipkin:9411
Troubleshooting Steps Taken:
- Testing with exporter
console, no issue, tracer shown in console - Zipkin endpoint is reachable, trying to modify endpoint to random port, it return error (Failed to connect to zipkin port 9412), I assume existing config is correct
- When add manual span in a controller, it return my custom span including automatic span
- When there is no manual span (custom span) in controller, there is no span generated in zipkin
Expected Result:
Automatic spans are generated even there is no manual span in controller
Actual Result:
No automatic spans are created when there is no manual span in controller
I have used this locally with Zipkin before. I will have a look at this and see if it is still working as expected!
@de3 how are you running your application?
Hi @ChrisLightfootWild
So I add opentelemetry to my existing laravel application using automatic instrumentation and zero code configuration I use laravel instrument libraries and zipkin exporter as tracer exporter My laravel stack and zipkin are running inside docker
I assume when using automatic instrumentation it will create span automatically whenever I access my application
So I try to access 1 on my API endpoint, but don't see any span created in zipkin dashboard
When I try to create manual span, somehow it showing including others span that I not create manually
Do you need another details to replicate @ChrisLightfootWild ?
@de3 I've just tested with PHP 8.3.3 and had the following locally:
Here's a snippet of my docker-compose:
command:
- php
- artisan
- serve
- --host
- 0.0.0.0
- -vvv
environment:
OTEL_EXPORTER_ZIPKIN_ENDPOINT: http://zipkin:9411/api/v2/spans
OTEL_PHP_AUTOLOAD_ENABLED: "true"
OTEL_PROPAGATORS: baggage,tracecontext
OTEL_SERVICE_NAME: laravel-app-10.x
OTEL_TRACES_EXPORTER: zipkin
How are you running PHP in your container? I wonder if there might be a difference there.
Hi @ChrisLightfootWild
I think there are 2 problems I found
- automatic span only working when using
php artisan servecommand - and its only working in laravel 10.x
I've test it with 2 different laravel version
- Using laravel 10.x with nginx -> automatic span is not working
- Using laravel 10.x with
artisan serve-> automatic span is working - Using laravel 8.x with nginx -> automatic span is not working
- Using laravel 8.x with
artisan serve-> automatic span is not working
my complete env
OTEL_EXPORTER_ZIPKIN_ENDPOINT=http://zipkin:9411/api/v2/spans
OTEL_EXPORTER_ZIPKIN_PROTOCOL=http/json
OTEL_PHP_AUTOLOAD_ENABLED="true"
OTEL_PROPAGATORS=baggage,tracecontext
OTEL_SERVICE_NAME=laravel-app-10.x
OTEL_TRACES_EXPORTER=zipkin
OTEL_METRICS_EXPORTER=console
OTEL_LOGS_EXPORTER=console
Hi @ChrisLightfootWild
I think there are 2 problems I found
- automatic span only working when using
php artisan servecommand- and its only working in laravel 10.x
I've test it with 2 different laravel version
- Using laravel 10.x with nginx -> automatic span is not working
- Using laravel 10.x with
artisan serve-> automatic span is working- Using laravel 8.x with nginx -> automatic span is not working
- Using laravel 8.x with
artisan serve-> automatic span is not workingmy complete env
OTEL_EXPORTER_ZIPKIN_ENDPOINT=http://zipkin:9411/api/v2/spans OTEL_EXPORTER_ZIPKIN_PROTOCOL=http/json OTEL_PHP_AUTOLOAD_ENABLED="true" OTEL_PROPAGATORS=baggage,tracecontext OTEL_SERVICE_NAME=laravel-app-10.x OTEL_TRACES_EXPORTER=zipkin OTEL_METRICS_EXPORTER=console OTEL_LOGS_EXPORTER=console
Hey @de3
For reference, I had this working on both 6.x and 10.x previously already but went back to double check it still worked on 6.x.
Here it is working on PHP 8.0.30 with Laravel 6.20.44:
--
I've just tried it on Laravel 8.x and it does not work for me with auto instrumentation. I apologise that this had slipped my mind, but having looked a little further I do remember seeing this before.
The Laravel ServeCommand in 8.x only passes a known whitelist of environment variables through to the spawned process, such that the necessary OTEL_* ones are stripped away.
The code that does that is here.
You can just skip that locally in your docker-compose and use the built-in PHP server instead, with something like:
command: ["php", "-S", "0.0.0.0:8000", "public/index.php"]
This makes sense until where you mention you add some manual instrumentation and then this works. Have you checked that again more recently to confirm that is still the case?
--
So that just leaves nginx, which it sounds like you have not had working yet under any Laravel/PHP combination.
Could you share an example of your configuration for that setup? (Ideally via docker-compose definition).
Hey @de3, are you still facing difficulty with this issue?
@de3 please reopen this ticket if you're still having issues here.