Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions config/sentry.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,9 @@
// @see: https://docs.sentry.io/platforms/php/guides/laravel/configuration/options/#enable_logs
'enable_logs' => env('SENTRY_ENABLE_LOGS', false),

// The minimum log level that will be sent to Sentry as logs using the `sentry_logs` logging channel
'logs_channel_level' => env('SENTRY_LOGS_LEVEL', env('LOG_LEVEL', 'debug')),
Comment on lines +38 to +39
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We need this otherwise we cannot get the env() call to work with config caching. This gives us some flexibility where we can limit the log level just for Sentry if needed. Since configurations are merged with existing user configuration this key will not need to be added on upgrade of existing users and works out of the box.

The debug default comes from: https://github.com/laravel/laravel/blob/12.x/config/logging.php


// @see: https://docs.sentry.io/platforms/php/guides/laravel/configuration/options/#send_default_pii
'send_default_pii' => env('SENTRY_SEND_DEFAULT_PII', false),

Expand Down
28 changes: 28 additions & 0 deletions src/Sentry/Laravel/ServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace Sentry\Laravel;

use Illuminate\Contracts\Config\Repository;
use Illuminate\Contracts\Container\BindingResolutionException;
use Illuminate\Contracts\Events\Dispatcher;
use Illuminate\Contracts\Http\Kernel as HttpKernelInterface;
Expand Down Expand Up @@ -44,6 +45,8 @@ class ServiceProvider extends BaseServiceProvider
'breadcrumbs',
// We resolve the integrations through the container later, so we initially do not pass it to the SDK yet
'integrations',
// We have this setting to allow us to capture the .env LOG_LEVEL for the sentry_logs channel
'logs_channel_level',
// This is kept for backwards compatibility and can be dropped in a future breaking release
'breadcrumbs.sql_bindings',

Expand Down Expand Up @@ -134,6 +137,8 @@ public function register(): void
$this->configureAndRegisterClient();

$this->registerFeatures();

$this->registerLogChannels();
}

/**
Expand Down Expand Up @@ -185,6 +190,29 @@ protected function registerFeatures(): void
}
}

/**
* Register the log channels.
*/
protected function registerLogChannels(): void
{
$config = $this->app->make(Repository::class);

$logChannels = $config->get('logging.channels', []);

if (!array_key_exists('sentry', $logChannels)) {
$config->set('logging.channels.sentry', [
'driver' => 'sentry',
]);
}

if (!array_key_exists('sentry_logs', $logChannels)) {
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

They array_key_exists check is here to ensure we do not overwrite the custom configuration by the user if it's present. We only register if it's not already added by the user.

$config->set('logging.channels.sentry_logs', [
'driver' => 'sentry_logs',
'level' => $config->get('sentry.logs_channel_level', 'debug'),
]);
}
}

/**
* Boot all the features.
*/
Expand Down