Skip to content

Messenger Instrumentation - The root span seems never ended #172

@jvocampings

Description

@jvocampings

Hi

My configuration for instrumentation:

    instrumentation:
        http_kernel:
            type: auto
            tracing:
                enabled: true
        http_client:
            tracing:
                enabled: true
        messenger:
            type: auto
            tracing:
                enabled: true
        console:
            type: auto
            tracing:
                enabled: true

I'm using the main branch.

I run bin/console messenger:consume my_transport --limit=1.

When I check traces on my Grafana (from Tempo data source), I see a trace with <root span not yet received>.

And in my app logs

[2025-04-17T10:45:44.401272+00:00] open_telemetry.DEBUG: Starting span "454bfad0716aba41" 
[2025-04-17T10:45:44.404044+00:00] open_telemetry.DEBUG: Activating new scope "877" 
[2025-04-17T10:45:44.644812+00:00] open_telemetry.DEBUG: Using scope "877" 
..................... 
SOME OTHER APPLICATIVE LOGS
..................... 
[2025-04-17T10:45:45.078182+00:00] open_telemetry.DEBUG: Detaching scope "499"
[2025-04-17T10:45:45.078334+00:00] open_telemetry.DEBUG: Ending span "2720d0ecbb384553"

The span 454bfad0716aba41, which is the first one (then the root span), is never ended. Then never sent to the collector.
I don't have any issue with other command. I tested with bin/console assets:install.

I added some debug in TraceableConsoleEventSubscriber:

  • 454bfad0716aba41 (the root span) is started by the method startSpan when the event ConsoleEvents::COMMAND occurs
  • 2720d0ecbb384553 (the last span in my logs) is ended by the method endSpan when the event ConsoleEvents::TERMINATE occurs.

I don't know why it happens like this. I assume it is related to the command messenger:consume which is designed to run indefinitely and something strange happen.

So maybe we should do this ?

  • always exclude messenger:consume from Command instrumentation
  • listen Messenger events to encapsulate each message consumed in a span instead of using the Messenger Middleware ?

Metadata

Metadata

Assignees

Type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions