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

Add support symfony7 #41

Merged
merged 13 commits into from
Mar 15, 2024
Merged
Show file tree
Hide file tree
Changes from 12 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 19 additions & 26 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,41 +7,34 @@ on:

jobs:
run:
runs-on: ubuntu-18.04
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
php:
- '7.4'
- '8.0'
- '8.1'
symfony-versions: ['none']
- '8.2'
coverage: ['none']
symfony-versions:
- '5.4.*'
- '6.0.*'
- '6.1.*'
- '6.2.*'
- '7.0.*'
exclude:
- php: '8.1'
symfony-versions: '7.0.*'
include:
- symfony-versions: '4.4.*'
php: '7.4'
- symfony-versions: '4.4.*'
php: '8.0'
- symfony-versions: '4.4.*'
php: '8.1'
- symfony-versions: '5.3.*'
php: '7.4'
- symfony-versions: '5.3.*'
php: '8.0'
- symfony-versions: '5.3.*'
php: '8.1'
- symfony-versions: '5.4.*'
php: '8.0'
- symfony-versions: '5.4.*'
php: '8.1'
- symfony-versions: '6.0.*'
php: '8.0'
- symfony-versions: '6.0.*'
php: '8.1'
- description: 'Log Code Coverage'
- php: '8.1'
coverage: 'none'
symfony-versions: 'none'
- php: '8.2'
coverage: 'none'
symfony-versions: 'none'
php: '8.1'
- description: 'Log Code Coverage'
php: '8.2'
coverage: 'xdebug'
symfony-versions: 'none'

name: PHP ${{ matrix.php }} Symfony ${{ matrix.symfony-versions }} ${{ matrix.description }}
steps:
Expand Down
16 changes: 0 additions & 16 deletions .github/workflows/gitleaks.yaml

This file was deleted.

14 changes: 8 additions & 6 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
"description": "Sentry monolog logging bundle",
"homepage": "https://github.com/MacPaw/sentry-monolog-adapter",
"type": "symfony-bundle",
"version": "1.0.0",
"keywords": [
"MacPaw",
"Symfony",
Expand All @@ -27,17 +28,18 @@
],
"require": {
"php": "^7.4 || ^8.0",
"symfony/console": "^4.4 || ^5.0 || ^6.0",
"symfony/dotenv": "^4.4 || ^5.0 || ^6.0",
"symfony/console": "^4.4 || ^5.0 || ^6.0 || ^7.0",
"symfony/dotenv": "^4.4 || ^5.0 || ^6.0 || ^7.0",
"symfony/monolog-bundle": "^3.0",
"sentry/sentry-symfony": "^4.0",
"symfony/messenger": "^4.4 || ^5.0 || ^6.0"
"symfony/messenger": "^4.4 || ^5.0 || ^6.0 || ^7.0",
"doctrine/dbal": "^3.0"
},
"require-dev": {
"phpstan/phpstan": "0.12.*",
"phpstan/phpstan": "^1.3",
"squizlabs/php_codesniffer": "3.5.*",
"symfony/phpunit-bridge": "^4.4 || ^5.0 || ^6.0",
"symfony/yaml": "^4.4 || ^5.0 || ^6.0"
"symfony/phpunit-bridge": "^4.4 || ^5.0 || ^6.0 || ^7.0",
"symfony/yaml": "^4.4 || ^5.0 || ^6.0 || ^7.0"
},
"autoload": {
"psr-4": {
Expand Down
2 changes: 1 addition & 1 deletion phpunit.xml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
<server name="APP_DEBUG" value="0" force="true"/>
<server name="SHELL_VERBOSITY" value="-1"/>
<server name="SYMFONY_PHPUNIT_REMOVE" value=""/>
<server name="SYMFONY_PHPUNIT_VERSION" value="9"/>
<server name="SYMFONY_PHPUNIT_VERSION" value="9.6.13"/>
<env name="SYMFONY_DEPRECATIONS_HELPER" value="disabled" />
</php>

Expand Down
6 changes: 3 additions & 3 deletions src/DependencyInjection/SentryMonologAdapterExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
class SentryMonologAdapterExtension extends Extension
{
/**
* @param array<array> $configs
* @param array<string, mixed> $configs
*
* {@inheritdoc}
*/
Expand All @@ -28,7 +28,7 @@ public function load(array $configs, ContainerBuilder $container): void
}

/**
* @param array<array> $config
* @param array<string, array<mixed>> $config
*/
private function loadMessengerLoggingMiddleware(
array $config,
Expand All @@ -55,7 +55,7 @@ private function loadMessengerLoggingMiddleware(
}

/**
* @param array<array> $config
* @param array<string, array<mixed>> $config
*/
private function loadMonologHandlerDecorator(
array $config,
Expand Down
18 changes: 9 additions & 9 deletions src/Monolog/Handler/MonologHandlerDecorator.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,13 @@
namespace SentryMonologAdapter\Monolog\Handler;

use Monolog\Handler\AbstractProcessingHandler;
use Monolog\LogRecord;
use Sentry\Monolog\Handler;
use Sentry\State\HubInterface;
use Sentry\State\Scope;

use function Sentry\withScope;

/**
* @phpstan-import-type FormattedRecord from \Monolog\Handler\AbstractProcessingHandler
*/
class MonologHandlerDecorator extends AbstractProcessingHandler
{
private Handler $sentryHandler;
Expand All @@ -27,19 +25,21 @@ public function __construct(HubInterface $hub, Handler $sentryHandler)
}

/**
* @phpstan-param FormattedRecord $record
* @phpstan-param LogRecord $record
*/
protected function write(array $record): void
protected function write(LogRecord $record): void
{
$this->hub->withScope(function (Scope $scope) use ($record): void {
if (isset($record['context']['extra']) && \is_array($record['context']['extra'])) {
foreach ($record['context']['extra'] as $key => $value) {
$context = $record->context;

if (isset($context['extra']) && \is_array($context['extra'])) {
foreach ($context['extra'] as $key => $value) {
$scope->setExtra((string) $key, $value);
}
}

if (isset($record['context']['tags']) && \is_array($record['context']['tags'])) {
foreach ($record['context']['tags'] as $key => $value) {
if (isset($context['tags']) && \is_array($context['tags'])) {
foreach ($context['tags'] as $key => $value) {
$scope->setTag($key, $value);
}
}
Expand Down
10 changes: 5 additions & 5 deletions src/Processor/ExceptionProcessor.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@
class ExceptionProcessor
{
/**
* @param array<string, mixed> $record
* @param array<mixed> $record
*
* @return array[]
* @return array<mixed>
*/
public function __invoke(array $record): array
{
Expand All @@ -36,10 +36,10 @@ public function __invoke(array $record): array
/**
* setExtra.
*
* @param array[] $record
* @param array[] $parameters
* @param array<string, array<mixed>> $record
* @param array<string, mixed> $parameters
*
* @return array[]
* @return array<string, array<mixed>>
*/
private function setExtra(array $record, array $parameters): array
{
Expand Down
1 change: 0 additions & 1 deletion src/SentryMonologAdapterBundle.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,4 @@

class SentryMonologAdapterBundle extends Bundle
{

}
42 changes: 22 additions & 20 deletions tests/Integration/Messenger/MonologHandlerDecoratorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@

namespace SentryMonologAdapter\Tests\Integration\Messenger;

use Monolog\Level;
use Monolog\Logger;
use Monolog\LogRecord;
use PHPUnit\Framework\TestCase;
use Sentry\ClientInterface;
use Sentry\Event;
Expand All @@ -16,14 +18,14 @@
class MonologHandlerDecoratorTest extends TestCase
{
/**
* @param array $record
* @param array $expectedExtra
* @param array $expectedTags
* @param LogRecord $record
* @param array $expectedExtra
* @param array $expectedTags
*
* @dataProvider handleDataProvider
*/
public function testHandle(
array $record,
LogRecord $record,
array $expectedExtra,
array $expectedTags
): void {
Expand Down Expand Up @@ -55,12 +57,12 @@ public function handleDataProvider(): array
{
return [
[
[
'message' => 'test',
'level' => Logger::DEBUG,
'level_name' => Logger::getLevelName(Logger::DEBUG),
'channel' => 'channel.test',
'context' => [
new LogRecord(
new \DateTimeImmutable(),
'channel.test',
Level::Debug,
'test',
[
'extra' => [
'id' => 'test_id',
'message' => 'test_message'
Expand All @@ -69,8 +71,8 @@ public function handleDataProvider(): array
'test_key' => 'test_value'
]
],
'extra' => []
],
[]
),
[
'id' => 'test_id',
'message' => 'test_message',
Expand All @@ -82,14 +84,14 @@ public function handleDataProvider(): array
]
],
[
[
'message' => 'test',
'level' => Logger::DEBUG,
'level_name' => Logger::getLevelName(Logger::DEBUG),
'channel' => 'channel.test',
'context' => [],
'extra' => []
],
new LogRecord(
new \DateTimeImmutable(),
'channel.test',
Level::Debug,
'test',
[],
[]
),
[
'monolog.channel' => 'channel.test',
'monolog.level' => Logger::getLevelName(Logger::DEBUG),
Expand Down
Loading