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

Update sentry library #71

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all 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
50 changes: 50 additions & 0 deletions .github/workflows/php.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
name: PHP Tests

on:
push:
branches: [ master ]
pull_request:
branches: [ master ]

jobs:
build:
runs-on: ${{ matrix.operating-system }}
strategy:
matrix:
operating-system: [ ubuntu-latest, macOS-latest ]
php-versions: [ '8.1', '8.2', '8.3' ]
name: PHP ${{ matrix.php-versions }} Test on ${{ matrix.operating-system }}
steps:
- uses: actions/checkout@v2

- name: Install PHP
uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php-versions }}
ini-values: "post_max_size=128M"

- name: Check PHP Version
run: |
php -v
composer --version

- name: Validate composer.json and composer.lock
run: composer validate

- name: Cache Composer packages
id: composer-cache
uses: actions/cache@v2
with:
path: vendor
key: ${{ runner.os }}-php-${{ hashFiles('**/composer.lock') }}
restore-keys: |
${{ runner.os }}-php-
- name: Install dependencies
if: steps.composer-cache.outputs.cache-hit != 'true'
run: composer install --prefer-dist --no-progress --no-suggest

- name: Run PHPCS linter
run: composer run-script lint

- name: Run PHPUnit tests
run: composer run-script test
1 change: 1 addition & 0 deletions LICENSE.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
The MIT License (MIT)

Copyright © 2015 — 2019 Notamedia Ltd. (http://nota.media)
Copyright © 2014 Horat1us

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
15 changes: 9 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,14 +1,17 @@
# [Sentry](https://sentry.io) logger for Yii2

[![Build Status](https://travis-ci.org/notamedia/yii2-sentry.svg)](https://travis-ci.org/notamedia/yii2-sentry)
[![Latest Stable Version](https://poser.pugx.org/notamedia/yii2-sentry/v/stable)](https://packagist.org/packages/notamedia/yii2-sentry)
[![Total Downloads](https://poser.pugx.org/notamedia/yii2-sentry/downloads)](https://packagist.org/packages/notamedia/yii2-sentry)
[![License](https://poser.pugx.org/notamedia/yii2-sentry/license)](https://packagist.org/packages/notamedia/yii2-sentry)
[![Latest Stable Version](https://poser.pugx.org/horat1us/yii2-sentry/v/stable)](https://packagist.org/packages/horat1us/yii2-sentry)
[![Total Downloads](https://poser.pugx.org/horat1us/yii2-sentry/downloads)](https://packagist.org/packages/horat1us/yii2-sentry)
[![License](https://poser.pugx.org/horat1us/yii2-sentry/license)](https://packagist.org/packages/horat1us/yii2-sentry)

This is fork of [notamedia/yii2-sentry](https://github.com/notamedia/yii2-sentry)
with updated [Sentry](https://packagist.org/packages/sentry/sentry)
library: using [sentry/sentry:^4.10](https://github.com/getsentry/sentry-php) package instead of old sentry/sdk:^3.0

## Installation

```bash
composer require notamedia/yii2-sentry
composer require horat1us/yii2-sentry
```

Add target class in the application config:
Expand All @@ -20,7 +23,7 @@ return [
'traceLevel' => YII_DEBUG ? 3 : 0,
'targets' => [
[
'class' => 'notamedia\sentry\SentryTarget',
'class' => \Horat1us\Yii\Sentry\SentryTarget::class,
'dsn' => 'http://2682ybvhbs347:[email protected]/1',
'levels' => ['error', 'warning'],
// Write the context information (the default is true):
Expand Down
2 changes: 1 addition & 1 deletion codeception.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ actor: Tester
bootstrap: bootstrap.php
paths:
tests: tests
log: tests/_output
output: tests/_output
data: tests/_data
support: tests/_support
envs: tests/_envs
Expand Down
36 changes: 20 additions & 16 deletions composer.json
Original file line number Diff line number Diff line change
@@ -1,25 +1,27 @@
{
"name": "notamedia/yii2-sentry",
"description": "Yii2 logger for Sentry",
"name": "horat1us/yii2-sentry",
"description": "Yii2 logger for Sentry (updated)",
"keywords": [
"sentry",
"yii2"
],
"type": "yii2-extension",
"license": "MIT",
"require": {
"php": "^7.2|^8.0",
"yiisoft/yii2": "^2.0",
"sentry/sdk": "^3.0"
"php": "^8.0",
"yiisoft/yii2": "^2.0.51",
"sentry/sentry": "^4.10"
},
"require-dev": {
"codeception/codeception": "^4.0",
"codeception/module-yii2": "^1.1",
"codeception/module-asserts": "^1.3"
"codeception/codeception": "^5.0",
"codeception/module-yii2": "^1.1.10",
"codeception/module-asserts": "^3.0",
"squizlabs/php_codesniffer": "^3.10",
"horat1us/yii2-asset-free": "^1.0"
},
"autoload": {
"psr-4": {
"notamedia\\sentry\\": "src"
"Horat1us\\Yii\\Sentry\\": "src"
}
},
"extra": {
Expand All @@ -28,14 +30,16 @@
},
"asset-pattern-skip-version": "(-build|-patch)"
},
"repositories": [
{
"type": "composer",
"url": "https://asset-packagist.org"
}
],
"scripts": {
"test": "codecept run",
"e2e": "php tests/sentry-fill"
"e2e": "php tests/sentry-fill",
"lint": "./vendor/bin/phpcs --standard=PSR12 ./src ./tests",
"phpcbf": "./vendor/bin/phpcbf --standard=PSR12 ./src ./tests"
},
"config": {
"allow-plugins": {
"php-http/discovery": true,
"yiisoft/yii2-composer": true
}
}
}
17 changes: 10 additions & 7 deletions src/SentryTarget.php
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
<?php

/**
* For the full copyright and license information, please view the LICENSE.md
* file that was distributed with this source code.
*/

namespace notamedia\sentry;
namespace Horat1us\Yii\Sentry;

use Sentry\ClientBuilder;
use Sentry\Event;
Expand Down Expand Up @@ -34,19 +35,20 @@ class SentryTarget extends Target
/**
* @var string Sentry client key.
*/
public $dsn;
public ?string $dsn = null;
/**
* @var array Options of the \Sentry.
*/
public $clientOptions = [];
public array $clientOptions = [];
/**
* @var bool Write the context information. The default implementation will dump user information, system variables, etc.
* @var bool Write the context information
* The default implementation will dump user information, system variables, etc.
*/
public $context = true;
public bool $context = true;
/**
* @var callable Callback function that can modify extra's array
*/
public $extraCallback;
public ?\Closure $extraCallback = null;

/**
* @inheritDoc
Expand Down Expand Up @@ -113,7 +115,8 @@ public function export()
if ($user && ($identity = $user->getIdentity(false))) {
$data['userData']['id'] = $identity->getId();
}
} catch (Throwable $e) {}
} catch (Throwable $e) {
}

\Sentry\withScope(function (Scope $scope) use ($text, $level, $data) {
if (is_array($text)) {
Expand Down
3 changes: 1 addition & 2 deletions tests/_support/E2eTester.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
<?php

<?php // phpcs:ignoreFile

/**
* Inherited Methods
Expand Down
2 changes: 1 addition & 1 deletion tests/_support/Helper/Unit.php
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
<?php

namespace Helper;

// here you can define custom actions
// all public methods declared in helper class will be available in $I

class Unit extends \Codeception\Module
{

}
3 changes: 1 addition & 2 deletions tests/_support/UnitTester.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
<?php

<?php // phpcs:ignoreFile

/**
* Inherited Methods
Expand Down
2 changes: 1 addition & 1 deletion tests/bootstrap.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<?php
<?php // phpcs:ignoreFile

// ensure we get report on all possible php errors
error_reporting(-1);
Expand Down
4 changes: 2 additions & 2 deletions tests/commands/SentryController.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,15 +47,15 @@ protected function logsProvider()
[
'level' => Logger::LEVEL_ERROR,
'message' => [
'msg' => new RuntimeException('Connection error', 999, new \Exception),
'msg' => new RuntimeException('Connection error', 999, new \Exception()),
'extra' => 'Hello, World!',
'tags' => ['db-name' => 'bulling'],
],
'category' => 'dbms',
],
[
'level' => Logger::LEVEL_ERROR,
'message' => new RuntimeException('Oops... This is exception.', 999, new \Exception),
'message' => new RuntimeException('Oops... This is exception.', 999, new \Exception()),
'category' => 'exceptions',
'user' => new User([
'id' => 47,
Expand Down
2 changes: 1 addition & 1 deletion tests/sentry-fill
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ $application = new \yii\web\Application([
'class' => \yii\log\FileTarget::class,
],
[
'class' => \notamedia\sentry\SentryTarget::class,
'class' => \Horat1us\Yii\Sentry\SentryTarget::class,
'dsn' => $params['sentryDsn'],
],
],
Expand Down
48 changes: 33 additions & 15 deletions tests/unit/SentryTargetTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
use Sentry\State\Scope;
use Codeception\Test\Unit;
use Sentry\ClientInterface;
use notamedia\sentry\SentryTarget;
use Horat1us\Yii\Sentry\SentryTarget;

/**
* Unit-tests for SentryTarget
Expand Down Expand Up @@ -57,13 +57,22 @@ public function testExceptionPassing()
$client = $this->createMock(ClientInterface::class);
$client->expects($this->once())
->method('captureEvent')
->willReturnCallback(function (Event $event, ?EventHint $hint = null, ?Scope $scope = null) use ($logData, &$messageWasSent): ?EventId {
$messageWasSent = true;
$this->assertSame($logData['exception'], $hint->exception);
$this->assertSame($logData['message'], $event->getMessage());

return EventId::generate();
});
->willReturnCallback(
function (
Event $event,
?EventHint $hint = null,
?Scope $scope = null
) use (
$logData,
&$messageWasSent
): ?EventId {
$messageWasSent = true;
$this->assertSame($logData['exception'], $hint->exception);
$this->assertSame($logData['message'], $event->getMessage());

return EventId::generate();
}
);

SentrySdk::getCurrentHub()->bindClient($client);

Expand Down Expand Up @@ -94,13 +103,22 @@ public function testMessageConverting($expectedMessageText, $loggedMessage)

$client = $this->createMock(ClientInterface::class);
$client->expects($this->once())
->method('captureEvent')
->willReturnCallback(function (Event $event, ?EventHint $hint = null, ?Scope $scope = null) use ($expectedMessageText, &$messageWasSent): ?EventId {
$messageWasSent = true;
$this->assertSame($expectedMessageText, $event->getMessage());

return EventId::generate();
});
->method('captureEvent')
->willReturnCallback(
function (
Event $event,
?EventHint $hint = null,
?Scope $scope = null
) use (
$expectedMessageText,
&$messageWasSent
): ?EventId {
$messageWasSent = true;
$this->assertSame($expectedMessageText, $event->getMessage());

return EventId::generate();
}
);

SentrySdk::getCurrentHub()->bindClient($client);

Expand Down
1 change: 1 addition & 0 deletions tests/unit/bootstrap.php
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
<?php

// Here you can initialize variables that will be available to your tests