Skip to content

Commit

Permalink
Merge pull request #1356 from getsentry/release-3.8.0
Browse files Browse the repository at this point in the history
Release 3.8.0
  • Loading branch information
cleptric authored Sep 5, 2022
2 parents c3f235f + ca21a81 commit e4db1c4
Show file tree
Hide file tree
Showing 22 changed files with 415 additions and 67 deletions.
23 changes: 15 additions & 8 deletions .github/workflows/ci.yaml → .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ jobs:
- '7.4'
- '8.0'
- '8.1'
- '8.2'
dependencies:
- lowest
- highest
Expand Down Expand Up @@ -55,23 +56,29 @@ jobs:

- name: Install highest dependencies
run: composer update --no-progress --no-interaction --prefer-dist
if: ${{ matrix.dependencies == 'highest' }}
if: ${{ matrix.dependencies == 'highest' && matrix.php != '8.2' }}

- name: Restrict lowest Symfony version on PHP 8.1
- name: Install highest PHP 8.2 dependencies
run: composer update --no-progress --no-interaction --prefer-dist --ignore-platform-req=php
if: ${{ matrix.dependencies == 'highest' && matrix.php == '8.2' }}

- name: Restrict lowest Symfony version on PHP 8.1 & 8.2
run: composer require symfony/options-resolver:^4.4.30 --no-update
if: ${{ matrix.dependencies == 'lowest' && matrix.php == '8.1' }}
if: ${{ matrix.dependencies == 'lowest' && matrix.php == '8.1' || matrix.php == '8.2' }}

- name: Install lowest dependencies
run: composer update --no-progress --no-interaction --prefer-dist --prefer-lowest
if: ${{ matrix.dependencies == 'lowest' }}
if: ${{ matrix.dependencies == 'lowest' && matrix.php != '8.2' }}

- name: Install lowest PHP 8.2 dependencies
run: composer update --no-progress --no-interaction --prefer-dist --prefer-lowest --ignore-platform-req=php
if: ${{ matrix.dependencies == 'lowest' && matrix.php == '8.2' }}

- name: Run tests
run: vendor/bin/phpunit --coverage-clover=build/coverage-report.xml
run: vendor/bin/phpunit --coverage-clover=coverage.xml

- name: Upload code coverage
uses: codecov/codecov-action@v1
with:
file: build/coverage-report.xml
uses: codecov/codecov-action@v3

- name: Check benchmarks
run: vendor/bin/phpbench run --revs=1 --iterations=1
Expand Down
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,13 @@

## Unreleased

## 3.8.0 (2022-09-05)

- Add `Sentry\Monolog\BreadcrumbHandler`, a Monolog handler to allow registration of logs as breadcrumbs (#1199)
- Do not setup any error handlers if the DSN is null (#1349)
- Add setter for type on the `ExceptionDataBag` (#1347)
- Drop symfony/polyfill-uuid in favour of a standalone implementation (#1346)

## 3.7.0 (2022-07-18)

- Fix `Scope::getTransaction()` so that it returns also unsampled transactions (#1334)
Expand Down
5 changes: 2 additions & 3 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,7 @@
"psr/http-message-implementation": "^1.0",
"psr/log": "^1.0|^2.0|^3.0",
"symfony/options-resolver": "^3.4.43|^4.4.30|^5.0.11|^6.0",
"symfony/polyfill-php80": "^1.17",
"symfony/polyfill-uuid": "^1.13.1"
"symfony/polyfill-php80": "^1.17"
},
"require-dev": {
"friendsofphp/php-cs-fixer": "^2.19|3.4.*",
Expand Down Expand Up @@ -96,7 +95,7 @@
"prefer-stable": true,
"extra": {
"branch-alias": {
"dev-master": "3.7.x-dev"
"dev-master": "3.8.x-dev"
}
}
}
15 changes: 10 additions & 5 deletions phpstan-baseline.neon
Original file line number Diff line number Diff line change
Expand Up @@ -16,27 +16,27 @@ parameters:
path: src/ClientInterface.php

-
message: "#^Offset 'host' does not exist on array\\{scheme\\: 'http'\\|'https', host\\?\\: string, port\\?\\: int, user\\?\\: string, pass\\?\\: string, path\\?\\: string, query\\?\\: string, fragment\\?\\: string\\}\\.$#"
message: "#^Offset 'host' does not exist on array\\{scheme\\: 'http'\\|'https', host\\?\\: string, port\\?\\: int\\<0, 65535\\>, user\\?\\: string, pass\\?\\: string, path\\?\\: string, query\\?\\: string, fragment\\?\\: string\\}\\.$#"
count: 1
path: src/Dsn.php

-
message: "#^Offset 'host'\\|'path'\\|'scheme'\\|'user' on array\\{scheme\\?\\: string, host\\?\\: string, port\\?\\: int, user\\?\\: string, pass\\?\\: string, path\\?\\: string, query\\?\\: string, fragment\\?\\: string\\} in isset\\(\\) always exists and is not nullable\\.$#"
message: "#^Offset 'host'\\|'path'\\|'scheme'\\|'user' on array\\{scheme\\?\\: string, host\\?\\: string, port\\?\\: int\\<0, 65535\\>, user\\?\\: string, pass\\?\\: string, path\\?\\: string, query\\?\\: string, fragment\\?\\: string\\} in isset\\(\\) always exists and is not nullable\\.$#"
count: 1
path: src/Dsn.php

-
message: "#^Offset 'path' does not exist on array\\{scheme\\: 'http'\\|'https', host\\?\\: string, port\\?\\: int, user\\?\\: string, pass\\?\\: string, path\\?\\: string, query\\?\\: string, fragment\\?\\: string\\}\\.$#"
message: "#^Offset 'path' does not exist on array\\{scheme\\: 'http'\\|'https', host\\?\\: string, port\\?\\: int\\<0, 65535\\>, user\\?\\: string, pass\\?\\: string, path\\?\\: string, query\\?\\: string, fragment\\?\\: string\\}\\.$#"
count: 4
path: src/Dsn.php

-
message: "#^Offset 'scheme' does not exist on array\\{scheme\\?\\: string, host\\?\\: string, port\\?\\: int, user\\?\\: string, pass\\?\\: string, path\\?\\: string, query\\?\\: string, fragment\\?\\: string\\}\\.$#"
message: "#^Offset 'scheme' does not exist on array\\{scheme\\?\\: string, host\\?\\: string, port\\?\\: int\\<0, 65535\\>, user\\?\\: string, pass\\?\\: string, path\\?\\: string, query\\?\\: string, fragment\\?\\: string\\}\\.$#"
count: 1
path: src/Dsn.php

-
message: "#^Offset 'user' does not exist on array\\{scheme\\: 'http'\\|'https', host\\?\\: string, port\\?\\: int, user\\?\\: string, pass\\?\\: string, path\\?\\: string, query\\?\\: string, fragment\\?\\: string\\}\\.$#"
message: "#^Offset 'user' does not exist on array\\{scheme\\: 'http'\\|'https', host\\?\\: string, port\\?\\: int\\<0, 65535\\>, user\\?\\: string, pass\\?\\: string, path\\?\\: string, query\\?\\: string, fragment\\?\\: string\\}\\.$#"
count: 1
path: src/Dsn.php

Expand Down Expand Up @@ -95,6 +95,11 @@ parameters:
count: 1
path: src/Integration/RequestIntegration.php

-
message: "#^Parameter \\#1 \\$level of method Monolog\\\\Handler\\\\AbstractHandler\\:\\:__construct\\(\\) expects 100\\|200\\|250\\|300\\|400\\|500\\|550\\|600\\|'ALERT'\\|'alert'\\|'CRITICAL'\\|'critical'\\|'DEBUG'\\|'debug'\\|'EMERGENCY'\\|'emergency'\\|'ERROR'\\|'error'\\|'INFO'\\|'info'\\|'NOTICE'\\|'notice'\\|'WARNING'\\|'warning'\\|Monolog\\\\Level, int\\|Monolog\\\\Level\\|string given\\.$#"
count: 1
path: src/Monolog/BreadcrumbHandler.php

-
message: "#^Method Sentry\\\\Options\\:\\:getBeforeBreadcrumbCallback\\(\\) should return callable\\(Sentry\\\\Breadcrumb\\)\\: Sentry\\\\Breadcrumb\\|null but returns mixed\\.$#"
count: 1
Expand Down
45 changes: 16 additions & 29 deletions psalm-baseline.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<files psalm-version="4.23.0@f1fe6ff483bf325c803df9f510d09a03fd796f88">
<files psalm-version="4.26.0@6998fabb2bf528b65777bf9941920888d23c03ac">
<file src="src/Dsn.php">
<PossiblyUndefinedArrayOffset occurrences="4">
<code>$parsedDsn['host']</code>
Expand All @@ -22,6 +22,21 @@
<code>$userIntegrations</code>
</PossiblyInvalidArgument>
</file>
<file src="src/Monolog/BreadcrumbHandler.php">
<PossiblyInvalidArgument occurrences="4">
<code>$record['channel']</code>
<code>$record['level']</code>
<code>$record['level']</code>
<code>$record['message']</code>
</PossiblyInvalidArgument>
<PossiblyInvalidMethodCall occurrences="1">
<code>getTimestamp</code>
</PossiblyInvalidMethodCall>
<UndefinedDocblockClass occurrences="2">
<code>Level|int</code>
<code>int|string|Level|LogLevel::*</code>
</UndefinedDocblockClass>
</file>
<file src="src/Monolog/CompatibilityProcessingHandlerTrait.php">
<DuplicateClass occurrences="1">
<code>CompatibilityProcessingHandlerTrait</code>
Expand Down Expand Up @@ -80,32 +95,4 @@
<code>startTransaction</code>
</TooManyArguments>
</file>
<file src="vendor/monolog/monolog/src/Monolog/Level.php">
<ParseError occurrences="12">
<code>$name</code>
<code>,</code>
<code>,</code>
<code>,</code>
<code>,</code>
<code>,</code>
<code>,</code>
<code>,</code>
<code>,</code>
<code>,</code>
<code>Level</code>
<code>case</code>
</ParseError>
</file>
<file src="vendor/monolog/monolog/src/Monolog/LogRecord.php">
<ParseError occurrences="1">
<code>\DateTimeImmutable</code>
</ParseError>
</file>
<file src="vendor/monolog/monolog/src/Monolog/Utils.php">
<ParseError occurrences="3">
<code>:</code>
<code>=&gt;</code>
<code>}</code>
</ParseError>
</file>
</files>
6 changes: 5 additions & 1 deletion src/EventId.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

namespace Sentry;

use Sentry\Util\SentryUid;

/**
* This class represents an event ID.
*
Expand Down Expand Up @@ -32,10 +34,12 @@ public function __construct(string $value)

/**
* Generates a new event ID.
*
* @copyright Matt Farina MIT License https://github.com/lootils/uuid/blob/master/LICENSE
*/
public static function generate(): self
{
return new self(str_replace('-', '', uuid_create(UUID_TYPE_RANDOM)));
return new self(SentryUid::generate());
}

public function __toString(): string
Expand Down
14 changes: 11 additions & 3 deletions src/ExceptionDataBag.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
final class ExceptionDataBag
{
/**
* @var class-string<\Throwable> The type of exception, e.g. RuntimeException
* @var string The type of exception, e.g. RuntimeException
*/
private $type;

Expand Down Expand Up @@ -42,14 +42,22 @@ public function __construct(\Throwable $exception, ?Stacktrace $stacktrace = nul

/**
* Gets the type of exception, e.g. RuntimeException.
*
* @return class-string<\Throwable>
*/
public function getType(): string
{
return $this->type;
}

/**
* Sets the type of the exception.
*
* @param string $type The exception type
*/
public function setType(string $type): void
{
$this->type = $type;
}

/**
* Gets the value of the exception.
*/
Expand Down
11 changes: 7 additions & 4 deletions src/Integration/IntegrationRegistry.php
Original file line number Diff line number Diff line change
Expand Up @@ -126,14 +126,17 @@ private function getDefaultIntegrations(Options $options): array
return [];
}

return [
new ExceptionListenerIntegration(),
new ErrorListenerIntegration(),
new FatalErrorListenerIntegration(),
$integrations = [
new RequestIntegration(),
new TransactionIntegration(),
new FrameContextifierIntegration(),
new EnvironmentIntegration(),
];

if (null !== $options->getDsn()) {
array_unshift($integrations, new ExceptionListenerIntegration(), new ErrorListenerIntegration(), new FatalErrorListenerIntegration());
}

return $integrations;
}
}
101 changes: 101 additions & 0 deletions src/Monolog/BreadcrumbHandler.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
<?php

declare(strict_types=1);

namespace Sentry\Monolog;

use Monolog\Handler\AbstractProcessingHandler;
use Monolog\Level;
use Monolog\Logger;
use Monolog\LogRecord;
use Psr\Log\LogLevel;
use Sentry\Breadcrumb;
use Sentry\Event;
use Sentry\State\HubInterface;
use Sentry\State\Scope;

/**
* This Monolog handler logs every message as a {@see Breadcrumb} into the current {@see Scope},
* to enrich any event sent to Sentry.
*/
final class BreadcrumbHandler extends AbstractProcessingHandler
{
/**
* @var HubInterface
*/
private $hub;

/**
* @phpstan-param int|string|Level|LogLevel::* $level
*
* @param HubInterface $hub The hub to which errors are reported
* @param int|string $level The minimum logging level at which this
* handler will be triggered
* @param bool $bubble Whether the messages that are handled can
* bubble up the stack or not
*/
public function __construct(HubInterface $hub, $level = Logger::DEBUG, bool $bubble = true)
{
$this->hub = $hub;

parent::__construct($level, $bubble);
}

/**
* @psalm-suppress MoreSpecificImplementedParamType
*
* @param LogRecord|array{
* level: int,
* channel: string,
* datetime: \DateTimeImmutable,
* message: string,
* extra?: array<string, mixed>
* } $record {@see https://github.com/Seldaek/monolog/blob/main/doc/message-structure.md}
*/
protected function write($record): void
{
$breadcrumb = new Breadcrumb(
$this->getBreadcrumbLevel($record['level']),
$this->getBreadcrumbType($record['level']),
$record['channel'],
$record['message'],
($record['context'] ?? []) + ($record['extra'] ?? []),
$record['datetime']->getTimestamp()
);

$this->hub->addBreadcrumb($breadcrumb);
}

/**
* @param Level|int $level
*/
private function getBreadcrumbLevel($level): string
{
if ($level instanceof Level) {
$level = $level->value;
}

switch ($level) {
case Logger::DEBUG:
return Breadcrumb::LEVEL_DEBUG;
case Logger::INFO:
case Logger::NOTICE:
return Breadcrumb::LEVEL_INFO;
case Logger::WARNING:
return Breadcrumb::LEVEL_WARNING;
case Logger::ERROR:
return Breadcrumb::LEVEL_ERROR;
default:
return Breadcrumb::LEVEL_FATAL;
}
}

private function getBreadcrumbType(int $level): string
{
if ($level >= Logger::ERROR) {
return Breadcrumb::TYPE_ERROR;
}

return Breadcrumb::TYPE_DEFAULT;
}
}
4 changes: 3 additions & 1 deletion src/Tracing/SpanId.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

namespace Sentry\Tracing;

use Sentry\Util\SentryUid;

/**
* This class represents an span ID.
*/
Expand Down Expand Up @@ -33,7 +35,7 @@ public function __construct(string $value)
*/
public static function generate(): self
{
return new self(substr(str_replace('-', '', uuid_create(UUID_TYPE_RANDOM)), 0, 16));
return new self(substr(SentryUid::generate(), 0, 16));
}

/**
Expand Down
Loading

0 comments on commit e4db1c4

Please sign in to comment.