Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[opentelemetry-php-contrib]: OpenTelemetry Laravel Auto-Instrumentation is not detecting jobs #1475

Open
Nelwhix opened this issue Jan 11, 2025 · 12 comments
Assignees
Labels
bug Something isn't working

Comments

@Nelwhix
Copy link

Nelwhix commented Jan 11, 2025

Describe your environment Hi there, I set up laravel auto-instrumentation. and it is correctly detecting the http request, the calls to DB, but not the jobs.

Steps to reproduce
The entire code is in a docker container here

What is the expected behavior?
I expected to see some spans for the job

What is the actual behavior?
Screenshot 2025-01-11 at 19-39-13 Zipkin

More Context: I have a separate container for the api and the queue worker. The jobs are detected when I set QUEUE_CONNECTION to sync but not when it is set to database

@Nelwhix Nelwhix added the bug Something isn't working label Jan 11, 2025
@Nelwhix
Copy link
Author

Nelwhix commented Jan 11, 2025

@ChrisLightfootWild Hi Chris, Thanks for your work on the laravel auto instrumentation package, I am sure I am just misconfiguring something so please if you could point me in the right direction. I would appreaciate🙏.

@ChrisLightfootWild
Copy link
Contributor

@ChrisLightfootWild Hi Chris, Thanks for your work on the laravel auto instrumentation package, I am sure I am just misconfiguring something so please if you could point me in the right direction. I would appreaciate🙏.

Hey @Nelwhix 👋

Thanks for raising the issue. Based on your example repo, it looks like the database driver is being used for your queue. I wonder if this relates to long-running queues again 🤔. If you make several requests to the orders endpoint over a few seconds, I wonder if you might see the batch processor emit some of the telemetry that should be captured.

I will try to find some time to test this.

@ChrisLightfootWild ChrisLightfootWild self-assigned this Jan 13, 2025
@alexandrecruz
Copy link

@Nelwhix running queue with sync invokes the job synchronously with your code.

if you use Redis or database drive, the workers are handling the Job.
Since that's happening, the trace won't display the Job metrics (which you should check separately).

This behavior is also similar to other proprietary APMs like new Relic, Elastic & others.
I don't see any errors based on the provided description.

@Nelwhix
Copy link
Author

Nelwhix commented Feb 5, 2025

Hi @alexandrecruz. So what if I want the job to display traces, how do I configure that?

@alexandrecruz
Copy link

alexandrecruz commented Feb 5, 2025

@Nelwhix I don't think that's possible for an async job since it's not running within the request cycle.
Instead, it is running as a separate thread/process in the background.

There might be a way to associate them, but again, since the job is running outside of the request cycle I don't believe the trace will be displaying it or affecting its metrics (CPU, RAM, time, etc)

@alexandrecruz
Copy link

I did not particularly test this solution, but Spatie has a TraceAware job that seems to send the same trace ID when running the job to combine results. You can check the approach and source code at: https://spatie.be/docs/laravel-open-telemetry/v1/basic-usage/measuring-queued-jobs

IMO: if the job is not part of the request cycle itself, it should be measured separately.
It can be useful to see them together but in reality, they are two separate things.

@Nelwhix
Copy link
Author

Nelwhix commented Feb 5, 2025

I actually want them separately, I tried the spatie package first..it wasn't working

@ChrisLightfootWild
Copy link
Contributor

@Nelwhix running queue with sync invokes the job synchronously with your code.

if you use Redis or database drive, the workers are handling the Job. Since that's happening, the trace won't display the Job metrics (which you should check separately).

This behavior is also similar to other proprietary APMs like new Relic, Elastic & others. I don't see any errors based on the provided description.

My understanding may have been off then, but it should currently serialize the job payload when writing to the jobs table in the database.

I was planning on checking into that, but have not had any free time to pick it up recently (apologies for anybody waiting on me here!).

@gmhafiz
Copy link

gmhafiz commented Feb 7, 2025

@Nelwhix Instead of php artisan queue:work, try php artisan queue:listen and see if there is a difference.

I get one trace when I use queue:work and it looks like this

Image

When I switch to queue:listen, I get a trace within one of those 'Artisan handler' trace.

I am using supervisor to run queue:listen. Maybe something in there could help? https://codeberg.org/gmhafiz/observability/src/commit/8a31169f3011d934e64d8581bd3db4f50811a3b4/laravel/server/supervisord.conf#L19

@Nelwhix
Copy link
Author

Nelwhix commented Feb 7, 2025

Thanks @gmhafiz let me try

@Nelwhix
Copy link
Author

Nelwhix commented Feb 7, 2025

queue:listen works!

Image

@ChrisLightfootWild
Copy link
Contributor

The difference between queue:work and queue:listen, I believe here, is that queue:work is essentially a longer running process and the outer trace is not being wrapped up and exported as desired.

There's a couple of issues around this, I've just not quite had the time to crack it yet!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

4 participants