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

Context gets cleared before logging #907

Closed
Lotuashvili opened this issue Jun 15, 2024 · 6 comments · Fixed by #910
Closed

Context gets cleared before logging #907

Lotuashvili opened this issue Jun 15, 2024 · 6 comments · Fixed by #910
Labels

Comments

@Lotuashvili
Copy link

Lotuashvili commented Jun 15, 2024

Octane Version

2.3.7

Laravel Version

11.10

PHP Version

8.3

What server type are you using?

Swoole

Server Version

AWS

Database Driver & Version

MySQL 8

Description

While using Laravel Octane and Context variables, it gets cleared before the log entry is created. I can successfully access my data by Context::get('name') in the app, but it's not being included in logs.

I tried to run this application without Octane (php artisan serve), and the context is working as expected.

Steps To Reproduce

Create a test route in web.php: (As shown here)

use Illuminate\Support\Facades\Context;
use Illuminate\Support\Facades\Log;

Route::get('test', function () {
    Context::add('global_context', 'value');

    Log::info('test', ['local_data' => 'local']);

    return response('test');
});

In laravel.log file, you will get only local_data.

[2024-06-15 10:45:51] local.INFO: test {"local_data":true}
@sy-records
Copy link
Contributor

🤔️ Maybe in octane you need to use Log::shareContext(['global_context' => 'value']);

@Lotuashvili
Copy link
Author

@sy-records Yeah that works!

@driesvints
Copy link
Member

Thanks @sy-records

@Lotuashvili
Copy link
Author

@driesvints I didn't close this issue on purpose, because that is a workaround and not a solution/fix. In this case I really needed it for logging purpose, but I will also need Context as a data storing mechanism for different parts of application. It's still going to be cleared before getting to logs. So I would really suggest to debug why it's being cleared by Octane.

@driesvints
Copy link
Member

@Lotuashvili ah gotcha. I thought you were happy with the workaround. I'll try to see if this one is solvable.

@timacdonald
Copy link
Member

Thanks for reporting this one.

I've opened a PR to fix this issue: #910

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

Successfully merging a pull request may close this issue.

4 participants