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

[BUG] Logs are not sent in Laravel queues #95

Open
antoinelame opened this issue Mar 20, 2021 · 7 comments
Open

[BUG] Logs are not sent in Laravel queues #95

antoinelame opened this issue Mar 20, 2021 · 7 comments
Assignees
Labels

Comments

@antoinelame
Copy link

antoinelame commented Mar 20, 2021

Description

Logs from an asynchronous job in a Laravel queue are not sent to CloudWatch until you shutdown the queue process.

This is because php artisan queue:work does not close the process. Queue workers do not "reboot" the framework before processing each job.

How to reproduce

  1. Create a new job:
<?php

namespace App\Jobs;

use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Foundation\Bus\Dispatchable;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Queue\SerializesModels;
use Illuminate\Support\Facades\Log;

class TestJob implements ShouldQueue
{
    use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;

    public function handle()
    {
        Log::info('The job has been executed');
    }
}
  1. Create a new route:
use App\Jobs\TestJob;

Route::get('dispatch-job', function () {
    TestJob::dispatch();
});
  1. Run the queue:
php artisan queue:work

Note: make sure that in your .env you do not use the sync queue driver.

  1. Call GET /dispatch-job

You will receive the logs in CloudWatch only when you'll interrupt the queue:work command. Not before.

Related GitHub issues

@mugisham
Copy link

mugisham commented Aug 31, 2021

Running php artisan queue:listen. seems to work but this is a less than ideal solution. This closes after each job and sends the logs, is there a way it can keep working without closing after each job as done by php artisan queue:work

@ninjacoder96
Copy link

any update on this? we are encountering this as well.

@olivier1208
Copy link

Finally found THE trick
Change the buffer size to 1 !!
That's it !

@mugisham
Copy link

Finally found THE trick

Change the buffer size to 1 !!

That's it !

What do you mean?

@olivier1208
Copy link

olivier1208 commented Nov 23, 2021

$handler = new CloudWatch($client, $groupName, $streamName, $retentionDays, 10000, $tags);
to
$handler = new CloudWatch($client, $groupName, $streamName, $retentionDays, 1, $tags);

If you look at the protected function write in Cloudwatch.php in the package you'll see the following

if (count($this->buffer) >= $this->batchSize) { $this->flushBuffer(); }

That's why

@mugisham
Copy link

Does this affect performance sending a log at a time

@mugisham
Copy link

https://stackoverflow.com/questions/46931742/cloudwatch-agent-batch-size-equal-to-1-is-it-a-bad-idea

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

5 participants