Skip to content

Commit 4fc9efe

Browse files
committed
Merge branch 'master' into test-php8.5
2 parents 4b510bf + e76b71f commit 4fc9efe

File tree

11 files changed

+248
-10
lines changed

11 files changed

+248
-10
lines changed

.github/workflows/ci.yaml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,8 @@ jobs:
161161
# friendsofphp/php-cs-fixer: No need for this package to run phpunit and it conflicts with older Laravel versions
162162
# livewire/livewire: Only supported on Laravel 7.0 and above
163163
# laravel/folio: Only supported on PHP 8.1 + Laravel 10.0 and above
164-
composer remove friendsofphp/php-cs-fixer livewire/livewire laravel/folio --dev --no-interaction --no-update
164+
# laravel/pennant: Only supported on PHP 8.1 + Laravel 10.0 and above
165+
composer remove friendsofphp/php-cs-fixer livewire/livewire laravel/folio laravel/pennant --dev --no-interaction --no-update
165166
166167
# Require the correct versions we want to run phpunit for
167168
composer require \

CHANGELOG.md

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,60 @@
11
# Changelog
22

3+
## 4.19.0
4+
5+
The Sentry SDK team is happy to announce the immediate availability of Sentry Laravel SDK v4.19.0.
6+
7+
### Features
8+
9+
- Add Laravel Pennant feature flags [(#1061)](https://github.com/getsentry/sentry-laravel/pull/1061)
10+
11+
The SDK will now automatically capture feature flags resolved using [Laravel Pennant](https://laravel.com/docs/12.x/pennant) and attach them to events and spans.
12+
13+
### Bug Fixes
14+
15+
- Do not try to detect the session key on the CLI [(#1058)](https://github.com/getsentry/sentry-laravel/pull/1058)
16+
17+
## 4.18.0
18+
19+
The Sentry SDK team is happy to announce the immediate availability of Sentry Laravel SDK v4.18.0.
20+
21+
### Bug Fixes
22+
23+
- Ensure we flush logs when the application unexpectedly terminates [(#1052)](https://github.com/getsentry/sentry-laravel/pull/1052)
24+
25+
### Misc
26+
27+
- Use `SENTRY_LOG_LEVEL` environment variable instead of `SENTRY_LOGS_LEVEL` to be more consistent (`SENTRY_LOGS_LEVEL` will keep working as an alias for backward compatibility). [(#1051)](https://github.com/getsentry/sentry-laravel/pull/1051)
28+
- Bump the PHP SDK to version `4.16.0` [(#1053)](https://github.com/getsentry/sentry-laravel/pull/1053)
29+
30+
## 4.17.0
31+
32+
The Sentry SDK team is happy to announce the immediate availability of Sentry Laravel SDK v4.17.0.
33+
34+
### Features
35+
36+
- Auto configure Sentry log channels. [(#1042)](https://github.com/getsentry/sentry-laravel/pull/1042)
37+
38+
Configuring the channel is no longer required. To enable logs for Sentry, the following environment variables
39+
need to be configured:
40+
```bash
41+
LOG_CHANNEL=stack
42+
LOG_STACK=single,sentry_logs
43+
SENTRY_ENABLE_LOGS=true
44+
```
45+
46+
Sentry will use `LOG_LEVEL` to determine the minimum log level, but it's possible to overwrite it just for Sentry
47+
using `SENTRY_LOG_LEVEL`.
48+
49+
```bash
50+
LOG_LEVEL=info
51+
SENTRY_LOG_LEVEL=warning
52+
```
53+
54+
### Misc
55+
56+
- Add `sentry.origin` attribute to `LogsHandler`. [(#1041)](https://github.com/getsentry/sentry-laravel/pull/1041)
57+
358
## 4.16.0
459

560
The Sentry SDK team is happy to announce the immediate availability of Sentry Laravel SDK v4.16.0.

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ If you need help setting up or configuring the Laravel SDK (or anything else in
130130
- [![Documentation](https://img.shields.io/badge/documentation-sentry.io-green.svg)](https://docs.sentry.io/quickstart/)
131131
- [![Discord](https://img.shields.io/discord/621778831602221064)](https://discord.gg/Ww9hbqr)
132132
- [![Stack Overflow](https://img.shields.io/badge/stack%20overflow-sentry-green.svg)](http://stackoverflow.com/questions/tagged/sentry)
133-
- [![Twitter Follow](https://img.shields.io/twitter/follow/getsentry?label=getsentry&style=social)](https://twitter.com/intent/follow?screen_name=getsentry)
133+
- [![X Follow](https://img.shields.io/twitter/follow/sentry?label=sentry&style=social)](https://x.com/intent/follow?screen_name=sentry)
134134

135135
## License
136136

composer.json

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
"require": {
2626
"php": "^7.2 | ^8.0",
2727
"illuminate/support": "^6.0 | ^7.0 | ^8.0 | ^9.0 | ^10.0 | ^11.0 | ^12.0",
28-
"sentry/sentry": "^4.15.2",
28+
"sentry/sentry": "^4.18.0",
2929
"symfony/psr-http-message-bridge": "^1.0 | ^2.0 | ^6.0 | ^7.0",
3030
"nyholm/psr7": "^1.0"
3131
},
@@ -35,15 +35,16 @@
3535
}
3636
},
3737
"require-dev": {
38-
"phpunit/phpunit": "^8.4 | ^9.3 | ^10.4 | ^11.5",
38+
"friendsofphp/php-cs-fixer": "^3.11",
39+
"guzzlehttp/guzzle": "^7.2",
40+
"laravel/folio": "^1.1",
3941
"laravel/framework": "^6.0 | ^7.0 | ^8.0 | ^9.0 | ^10.0 | ^11.0 | ^12.0",
42+
"laravel/pennant": "^1.0",
4043
"livewire/livewire": "^2.0 | ^3.0",
41-
"orchestra/testbench": "^4.7 | ^5.1 | ^6.0 | ^7.0 | ^8.0 | ^9.0 | ^10.0",
42-
"friendsofphp/php-cs-fixer": "^3.11",
4344
"mockery/mockery": "^1.3",
45+
"orchestra/testbench": "^4.7 | ^5.1 | ^6.0 | ^7.0 | ^8.0 | ^9.0 | ^10.0",
4446
"phpstan/phpstan": "^1.10",
45-
"laravel/folio": "^1.1",
46-
"guzzlehttp/guzzle": "^7.2"
47+
"phpunit/phpunit": "^8.4 | ^9.3 | ^10.4 | ^11.5"
4748
},
4849
"autoload-dev": {
4950
"psr-4": {

config/sentry.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@
3636
'enable_logs' => env('SENTRY_ENABLE_LOGS', false),
3737

3838
// The minimum log level that will be sent to Sentry as logs using the `sentry_logs` logging channel
39-
'logs_channel_level' => env('SENTRY_LOGS_LEVEL', env('LOG_LEVEL', 'debug')),
39+
'logs_channel_level' => env('SENTRY_LOG_LEVEL', env('SENTRY_LOGS_LEVEL', env('LOG_LEVEL', 'debug'))),
4040

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

src/Sentry/Laravel/Features/CacheIntegration.php

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
namespace Sentry\Laravel\Features;
44

55
use Illuminate\Cache\Events;
6+
use Illuminate\Foundation\Application;
67
use Illuminate\Contracts\Events\Dispatcher;
78
use Illuminate\Contracts\Session\Session;
89
use Illuminate\Redis\Events as RedisEvents;
@@ -22,6 +23,15 @@ class CacheIntegration extends Feature
2223
{
2324
use WorksWithSpans, TracksPushedScopesAndSpans, ResolvesEventOrigin;
2425

26+
/**
27+
* Indicates whether to attempt to detect the session key when running in the console.
28+
*
29+
* @internal this is mainly intended for testing purposes.
30+
*
31+
* @var bool
32+
*/
33+
public static $detectSessionKeyOnConsole = false;
34+
2535
public function isApplicable(): bool
2636
{
2737
return $this->isTracingFeatureEnabled('redis_commands', false)
@@ -259,7 +269,17 @@ private function maybeHandleCacheEventAsEndOfSpan(Events\CacheEvent $event): boo
259269
*/
260270
private function getSessionKey(): ?string
261271
{
272+
$container = $this->container();
273+
262274
try {
275+
// A session key is highly unusal to be available when running in the console
276+
// So we skip trying to get the session key in that case to prevent booting up the session store unnecessarily
277+
// Doing this anyway can result in unnecessary database connections for example
278+
// See: https://github.com/getsentry/sentry-laravel/issues/1057
279+
if (!self::$detectSessionKeyOnConsole && $container instanceof Application && $container->runningInConsole()) {
280+
return null;
281+
}
282+
263283
/** @var Session $sessionStore */
264284
$sessionStore = $this->container()->make('session.store');
265285

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
<?php
2+
3+
namespace Sentry\Laravel\Features;
4+
5+
use Sentry\State\Scope;
6+
use Illuminate\Contracts\Events\Dispatcher;
7+
use Sentry\SentrySdk;
8+
use Laravel\Pennant\Feature as Pennant;
9+
use Laravel\Pennant\Events\FeatureResolved;
10+
use Laravel\Pennant\Events\FeatureRetrieved;
11+
12+
class PennantPackageIntegration extends Feature
13+
{
14+
private const FEATURE_KEY = 'pennant';
15+
16+
public function isApplicable(): bool
17+
{
18+
return class_exists(Pennant::class);
19+
}
20+
21+
public function onBoot(Dispatcher $events): void
22+
{
23+
$events->listen(FeatureRetrieved::class, [$this, 'handleFeatureRetrieved']);
24+
}
25+
26+
public function handleFeatureRetrieved($feature): void
27+
{
28+
SentrySdk::getCurrentHub()->configureScope(function (Scope $scope) use ($feature) {
29+
// The value of the feature is not always a bool (Rich Feature Values) but only bools are supported.
30+
// The feature is considered "active" if its value is not explicitly false following Pennant's logic.
31+
$scope->addFeatureFlag($feature->feature, $feature->value !== false);
32+
});
33+
}
34+
}

src/Sentry/Laravel/ServiceProvider.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
namespace Sentry\Laravel;
44

5+
use Sentry\Logs\Logs;
56
use Illuminate\Contracts\Config\Repository;
67
use Illuminate\Contracts\Container\BindingResolutionException;
78
use Illuminate\Contracts\Events\Dispatcher;
@@ -73,6 +74,7 @@ class ServiceProvider extends BaseServiceProvider
7374
Features\HttpClientIntegration::class,
7475
Features\FolioPackageIntegration::class,
7576
Features\NotificationsIntegration::class,
77+
Features\PennantPackageIntegration::class,
7678
Features\LivewirePackageIntegration::class,
7779
Features\ConsoleSchedulingIntegration::class,
7880
];
@@ -163,6 +165,15 @@ protected function bindEvents(): void
163165
if (isset($userConfig['send_default_pii']) && $userConfig['send_default_pii'] !== false) {
164166
$handler->subscribeAuthEvents($dispatcher);
165167
}
168+
169+
if (isset($userConfig['enable_logs']) && $userConfig['enable_logs'] === true && method_exists($this->app, 'terminating')) {
170+
// Listen to the terminating event to flush the logs before the application ends
171+
// This ensures that all logs are sent to Sentry even if the application ends unexpectedly
172+
// We need to check for method existence here for Lumen since this method was only introduced in Lumen 9.1.4
173+
$this->app->terminating(static function () {
174+
Logs::getInstance()->flush();
175+
});
176+
}
166177
} catch (BindingResolutionException $e) {
167178
// If we cannot resolve the event dispatcher we also cannot listen to events
168179
}

src/Sentry/Laravel/Version.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,5 @@
55
final class Version
66
{
77
public const SDK_IDENTIFIER = 'sentry.php.laravel';
8-
public const SDK_VERSION = '4.16.0';
8+
public const SDK_VERSION = '4.19.0';
99
}

test/Sentry/Features/CacheIntegrationTest.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,22 @@
66
use Illuminate\Support\Facades\Cache;
77
use Sentry\Laravel\Tests\TestCase;
88
use Sentry\Tracing\Span;
9+
use Sentry\Laravel\Features\CacheIntegration;
910

1011
class CacheIntegrationTest extends TestCase
1112
{
1213
protected $defaultSetupConfig = [
1314
'session.driver' => 'array',
1415
];
1516

17+
protected function setUp(): void
18+
{
19+
parent::setUp();
20+
21+
// Ensure that session keys can be detected in the tests that are running from the console
22+
CacheIntegration::$detectSessionKeyOnConsole = true;
23+
}
24+
1625
public function testCacheBreadcrumbForWriteAndHitIsRecorded(): void
1726
{
1827
Cache::put($key = 'foo', 'bar');

0 commit comments

Comments
 (0)