opentelemetry-php icon indicating copy to clipboard operation
opentelemetry-php copied to clipboard

OpenTelemetry Laravel with Zipkin not creating auto spans

Open de3 opened this issue 1 year ago • 5 comments
trafficstars

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

de3 avatar Feb 28 '24 09:02 de3

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?

ChrisLightfootWild avatar Feb 28 '24 13:02 ChrisLightfootWild

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 avatar Feb 29 '24 00:02 de3

@de3 I've just tested with PHP 8.3.3 and had the following locally:

image

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.

ChrisLightfootWild avatar Mar 02 '24 13:03 ChrisLightfootWild

Hi @ChrisLightfootWild

I think there are 2 problems I found

  1. automatic span only working when using php artisan serve command
  2. and its only working in laravel 10.x

I've test it with 2 different laravel version

  1. Using laravel 10.x with nginx -> automatic span is not working
  2. Using laravel 10.x with artisan serve -> automatic span is working
  3. Using laravel 8.x with nginx -> automatic span is not working
  4. 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

de3 avatar Mar 04 '24 02:03 de3

Hi @ChrisLightfootWild

I think there are 2 problems I found

  1. automatic span only working when using php artisan serve command
  2. and its only working in laravel 10.x

I've test it with 2 different laravel version

  1. Using laravel 10.x with nginx -> automatic span is not working
  2. Using laravel 10.x with artisan serve -> automatic span is working
  3. Using laravel 8.x with nginx -> automatic span is not working
  4. 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

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: image

--

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).

ChrisLightfootWild avatar Mar 05 '24 23:03 ChrisLightfootWild

Hey @de3, are you still facing difficulty with this issue?

ChrisLightfootWild avatar Mar 26 '24 14:03 ChrisLightfootWild

@de3 please reopen this ticket if you're still having issues here.

bobstrecansky avatar Mar 27 '24 12:03 bobstrecansky