Skip to content

Conversation

Big-Shark
Copy link
Contributor

I noticed that our project lacks spans when executing console commands. I found that upon completion of a console command, only one specific span is finalized, rather than the entire transaction, unlike the behavior in TracingRequestListener. After locally modifying it to complete the transaction and running console sentry:test, I observed the other spans that were previously missing. Therefore, I believe this fix should resolve the issue.

I noticed that our project lacks spans when executing console commands. I found that upon completion of a console command, only one specific span is finalized, rather than the entire transaction, unlike the behavior in TracingRequestListener. After locally modifying it to complete the transaction and running console sentry:test, I observed the other spans that were previously missing. Therefore, I believe this fix should resolve the issue.
@Big-Shark
Copy link
Contributor Author

The tests failed because they check for the invocation of the getSpan method.

I would like to understand whether there is a bug here and the tests need to be fixed, or if the issue lies elsewhere.

@Big-Shark
Copy link
Contributor Author

@cleptric Hi, can you check my MR?

@Big-Shark Big-Shark marked this pull request as draft August 1, 2025 22:46
@cleptric cleptric requested a review from Litarnus August 11, 2025 05:33
@Litarnus
Copy link
Contributor

Hi @Big-Shark! Can you provide more information what you received before your change and after your change. It seems to make no difference for me when running sentry:test

@Big-Shark
Copy link
Contributor Author

Big-Shark commented Aug 15, 2025

Hi

Before my changes, running sentry:test produced this output:

Screenshot from 2025-08-15 10-55-20

After my changes, it looks like this:
Screenshot from 2025-08-15 10-56-31

When I add a custom span in SentryTestCommand:

        $spanContext = \Sentry\Tracing\SpanContext::make()
            ->setOp('some_operation')
            ->setDescription('This is a description');
        \Sentry\trace(function () {
            sleep (3);
        }, $spanContext)

The output becomes:

Screenshot from 2025-08-15 10-55-38 Without these changes, the output is similar to the first screenshot.

@Big-Shark
Copy link
Contributor Author

My sentry yaml config

when@prod: &sentry-prod
    parameters:
        sentry.traces_sample_rate: 0.1

    sentry:
        dsn: "%env(SENTRY_DSN)%"
        options:
            environment: "%env(DEPLOYMENT_ENV)%"
            release: '%env(APP_VERSION)%'
            send_default_pii: true
            traces_sample_rate: '%sentry.traces_sample_rate%'
            ignore_exceptions:
                - Symfony\Component\HttpKernel\Exception\NotFoundHttpException
                - Symfony\Component\Messenger\Exception\RejectRedeliveredMessageException
        register_error_listener: false # Disables the ErrorListener to avoid duplicated log in sentry

when@staging:
    <<: *sentry-prod
    parameters:
        sentry.traces_sample_rate: 0.3

when@dev:
    <<: *sentry-prod
    parameters:
        sentry.traces_sample_rate: 1

@Litarnus
Copy link
Contributor

Litarnus commented Sep 2, 2025

Thank you for your reply and sorry for coming back so late to you. I added your custom span to the SentryTestCommand and I got your expected results without your change (minus the event_dispatcher.dispatch). I tested it on the current master branch.

Could you provide a minimal working example where you reproduce the behaviour?

I'm generally a bit reluctant to finish transaction on console termination as this would also finish the transaction once a subcommand terminates.

@Big-Shark
Copy link
Contributor Author

I couldn't reproduce this issue locally on a new project, though last time I did experiment on a clean project.
I'll close the issue and dive into debugging our app; the problem might be there.
Thanks for the help.

@Big-Shark Big-Shark closed this Sep 6, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants