Skip to content

Commit e4db1c4

Browse files
authored
Merge pull request #1356 from getsentry/release-3.8.0
Release 3.8.0
2 parents c3f235f + ca21a81 commit e4db1c4

22 files changed

+415
-67
lines changed

.github/workflows/ci.yaml renamed to .github/workflows/ci.yml

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ jobs:
2323
- '7.4'
2424
- '8.0'
2525
- '8.1'
26+
- '8.2'
2627
dependencies:
2728
- lowest
2829
- highest
@@ -55,23 +56,29 @@ jobs:
5556

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

60-
- name: Restrict lowest Symfony version on PHP 8.1
61+
- name: Install highest PHP 8.2 dependencies
62+
run: composer update --no-progress --no-interaction --prefer-dist --ignore-platform-req=php
63+
if: ${{ matrix.dependencies == 'highest' && matrix.php == '8.2' }}
64+
65+
- name: Restrict lowest Symfony version on PHP 8.1 & 8.2
6166
run: composer require symfony/options-resolver:^4.4.30 --no-update
62-
if: ${{ matrix.dependencies == 'lowest' && matrix.php == '8.1' }}
67+
if: ${{ matrix.dependencies == 'lowest' && matrix.php == '8.1' || matrix.php == '8.2' }}
6368

6469
- name: Install lowest dependencies
6570
run: composer update --no-progress --no-interaction --prefer-dist --prefer-lowest
66-
if: ${{ matrix.dependencies == 'lowest' }}
71+
if: ${{ matrix.dependencies == 'lowest' && matrix.php != '8.2' }}
72+
73+
- name: Install lowest PHP 8.2 dependencies
74+
run: composer update --no-progress --no-interaction --prefer-dist --prefer-lowest --ignore-platform-req=php
75+
if: ${{ matrix.dependencies == 'lowest' && matrix.php == '8.2' }}
6776

6877
- name: Run tests
69-
run: vendor/bin/phpunit --coverage-clover=build/coverage-report.xml
78+
run: vendor/bin/phpunit --coverage-clover=coverage.xml
7079

7180
- name: Upload code coverage
72-
uses: codecov/codecov-action@v1
73-
with:
74-
file: build/coverage-report.xml
81+
uses: codecov/codecov-action@v3
7582

7683
- name: Check benchmarks
7784
run: vendor/bin/phpbench run --revs=1 --iterations=1

CHANGELOG.md

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

33
## Unreleased
44

5+
## 3.8.0 (2022-09-05)
6+
7+
- Add `Sentry\Monolog\BreadcrumbHandler`, a Monolog handler to allow registration of logs as breadcrumbs (#1199)
8+
- Do not setup any error handlers if the DSN is null (#1349)
9+
- Add setter for type on the `ExceptionDataBag` (#1347)
10+
- Drop symfony/polyfill-uuid in favour of a standalone implementation (#1346)
11+
512
## 3.7.0 (2022-07-18)
613

714
- Fix `Scope::getTransaction()` so that it returns also unsampled transactions (#1334)

composer.json

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,7 @@
3535
"psr/http-message-implementation": "^1.0",
3636
"psr/log": "^1.0|^2.0|^3.0",
3737
"symfony/options-resolver": "^3.4.43|^4.4.30|^5.0.11|^6.0",
38-
"symfony/polyfill-php80": "^1.17",
39-
"symfony/polyfill-uuid": "^1.13.1"
38+
"symfony/polyfill-php80": "^1.17"
4039
},
4140
"require-dev": {
4241
"friendsofphp/php-cs-fixer": "^2.19|3.4.*",
@@ -96,7 +95,7 @@
9695
"prefer-stable": true,
9796
"extra": {
9897
"branch-alias": {
99-
"dev-master": "3.7.x-dev"
98+
"dev-master": "3.8.x-dev"
10099
}
101100
}
102101
}

phpstan-baseline.neon

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,27 +16,27 @@ parameters:
1616
path: src/ClientInterface.php
1717

1818
-
19-
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\\}\\.$#"
19+
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\\}\\.$#"
2020
count: 1
2121
path: src/Dsn.php
2222

2323
-
24-
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\\.$#"
24+
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\\.$#"
2525
count: 1
2626
path: src/Dsn.php
2727

2828
-
29-
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\\}\\.$#"
29+
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\\}\\.$#"
3030
count: 4
3131
path: src/Dsn.php
3232

3333
-
34-
message: "#^Offset 'scheme' does not exist on array\\{scheme\\?\\: string, host\\?\\: string, port\\?\\: int, user\\?\\: string, pass\\?\\: string, path\\?\\: string, query\\?\\: string, fragment\\?\\: string\\}\\.$#"
34+
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\\}\\.$#"
3535
count: 1
3636
path: src/Dsn.php
3737

3838
-
39-
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\\}\\.$#"
39+
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\\}\\.$#"
4040
count: 1
4141
path: src/Dsn.php
4242

@@ -95,6 +95,11 @@ parameters:
9595
count: 1
9696
path: src/Integration/RequestIntegration.php
9797

98+
-
99+
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\\.$#"
100+
count: 1
101+
path: src/Monolog/BreadcrumbHandler.php
102+
98103
-
99104
message: "#^Method Sentry\\\\Options\\:\\:getBeforeBreadcrumbCallback\\(\\) should return callable\\(Sentry\\\\Breadcrumb\\)\\: Sentry\\\\Breadcrumb\\|null but returns mixed\\.$#"
100105
count: 1

psalm-baseline.xml

Lines changed: 16 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<?xml version="1.0" encoding="UTF-8"?>
2-
<files psalm-version="4.23.0@f1fe6ff483bf325c803df9f510d09a03fd796f88">
2+
<files psalm-version="4.26.0@6998fabb2bf528b65777bf9941920888d23c03ac">
33
<file src="src/Dsn.php">
44
<PossiblyUndefinedArrayOffset occurrences="4">
55
<code>$parsedDsn['host']</code>
@@ -22,6 +22,21 @@
2222
<code>$userIntegrations</code>
2323
</PossiblyInvalidArgument>
2424
</file>
25+
<file src="src/Monolog/BreadcrumbHandler.php">
26+
<PossiblyInvalidArgument occurrences="4">
27+
<code>$record['channel']</code>
28+
<code>$record['level']</code>
29+
<code>$record['level']</code>
30+
<code>$record['message']</code>
31+
</PossiblyInvalidArgument>
32+
<PossiblyInvalidMethodCall occurrences="1">
33+
<code>getTimestamp</code>
34+
</PossiblyInvalidMethodCall>
35+
<UndefinedDocblockClass occurrences="2">
36+
<code>Level|int</code>
37+
<code>int|string|Level|LogLevel::*</code>
38+
</UndefinedDocblockClass>
39+
</file>
2540
<file src="src/Monolog/CompatibilityProcessingHandlerTrait.php">
2641
<DuplicateClass occurrences="1">
2742
<code>CompatibilityProcessingHandlerTrait</code>
@@ -80,32 +95,4 @@
8095
<code>startTransaction</code>
8196
</TooManyArguments>
8297
</file>
83-
<file src="vendor/monolog/monolog/src/Monolog/Level.php">
84-
<ParseError occurrences="12">
85-
<code>$name</code>
86-
<code>,</code>
87-
<code>,</code>
88-
<code>,</code>
89-
<code>,</code>
90-
<code>,</code>
91-
<code>,</code>
92-
<code>,</code>
93-
<code>,</code>
94-
<code>,</code>
95-
<code>Level</code>
96-
<code>case</code>
97-
</ParseError>
98-
</file>
99-
<file src="vendor/monolog/monolog/src/Monolog/LogRecord.php">
100-
<ParseError occurrences="1">
101-
<code>\DateTimeImmutable</code>
102-
</ParseError>
103-
</file>
104-
<file src="vendor/monolog/monolog/src/Monolog/Utils.php">
105-
<ParseError occurrences="3">
106-
<code>:</code>
107-
<code>=&gt;</code>
108-
<code>}</code>
109-
</ParseError>
110-
</file>
11198
</files>

src/EventId.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44

55
namespace Sentry;
66

7+
use Sentry\Util\SentryUid;
8+
79
/**
810
* This class represents an event ID.
911
*
@@ -32,10 +34,12 @@ public function __construct(string $value)
3234

3335
/**
3436
* Generates a new event ID.
37+
*
38+
* @copyright Matt Farina MIT License https://github.com/lootils/uuid/blob/master/LICENSE
3539
*/
3640
public static function generate(): self
3741
{
38-
return new self(str_replace('-', '', uuid_create(UUID_TYPE_RANDOM)));
42+
return new self(SentryUid::generate());
3943
}
4044

4145
public function __toString(): string

src/ExceptionDataBag.php

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
final class ExceptionDataBag
1414
{
1515
/**
16-
* @var class-string<\Throwable> The type of exception, e.g. RuntimeException
16+
* @var string The type of exception, e.g. RuntimeException
1717
*/
1818
private $type;
1919

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

4343
/**
4444
* Gets the type of exception, e.g. RuntimeException.
45-
*
46-
* @return class-string<\Throwable>
4745
*/
4846
public function getType(): string
4947
{
5048
return $this->type;
5149
}
5250

51+
/**
52+
* Sets the type of the exception.
53+
*
54+
* @param string $type The exception type
55+
*/
56+
public function setType(string $type): void
57+
{
58+
$this->type = $type;
59+
}
60+
5361
/**
5462
* Gets the value of the exception.
5563
*/

src/Integration/IntegrationRegistry.php

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -126,14 +126,17 @@ private function getDefaultIntegrations(Options $options): array
126126
return [];
127127
}
128128

129-
return [
130-
new ExceptionListenerIntegration(),
131-
new ErrorListenerIntegration(),
132-
new FatalErrorListenerIntegration(),
129+
$integrations = [
133130
new RequestIntegration(),
134131
new TransactionIntegration(),
135132
new FrameContextifierIntegration(),
136133
new EnvironmentIntegration(),
137134
];
135+
136+
if (null !== $options->getDsn()) {
137+
array_unshift($integrations, new ExceptionListenerIntegration(), new ErrorListenerIntegration(), new FatalErrorListenerIntegration());
138+
}
139+
140+
return $integrations;
138141
}
139142
}

src/Monolog/BreadcrumbHandler.php

Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Sentry\Monolog;
6+
7+
use Monolog\Handler\AbstractProcessingHandler;
8+
use Monolog\Level;
9+
use Monolog\Logger;
10+
use Monolog\LogRecord;
11+
use Psr\Log\LogLevel;
12+
use Sentry\Breadcrumb;
13+
use Sentry\Event;
14+
use Sentry\State\HubInterface;
15+
use Sentry\State\Scope;
16+
17+
/**
18+
* This Monolog handler logs every message as a {@see Breadcrumb} into the current {@see Scope},
19+
* to enrich any event sent to Sentry.
20+
*/
21+
final class BreadcrumbHandler extends AbstractProcessingHandler
22+
{
23+
/**
24+
* @var HubInterface
25+
*/
26+
private $hub;
27+
28+
/**
29+
* @phpstan-param int|string|Level|LogLevel::* $level
30+
*
31+
* @param HubInterface $hub The hub to which errors are reported
32+
* @param int|string $level The minimum logging level at which this
33+
* handler will be triggered
34+
* @param bool $bubble Whether the messages that are handled can
35+
* bubble up the stack or not
36+
*/
37+
public function __construct(HubInterface $hub, $level = Logger::DEBUG, bool $bubble = true)
38+
{
39+
$this->hub = $hub;
40+
41+
parent::__construct($level, $bubble);
42+
}
43+
44+
/**
45+
* @psalm-suppress MoreSpecificImplementedParamType
46+
*
47+
* @param LogRecord|array{
48+
* level: int,
49+
* channel: string,
50+
* datetime: \DateTimeImmutable,
51+
* message: string,
52+
* extra?: array<string, mixed>
53+
* } $record {@see https://github.com/Seldaek/monolog/blob/main/doc/message-structure.md}
54+
*/
55+
protected function write($record): void
56+
{
57+
$breadcrumb = new Breadcrumb(
58+
$this->getBreadcrumbLevel($record['level']),
59+
$this->getBreadcrumbType($record['level']),
60+
$record['channel'],
61+
$record['message'],
62+
($record['context'] ?? []) + ($record['extra'] ?? []),
63+
$record['datetime']->getTimestamp()
64+
);
65+
66+
$this->hub->addBreadcrumb($breadcrumb);
67+
}
68+
69+
/**
70+
* @param Level|int $level
71+
*/
72+
private function getBreadcrumbLevel($level): string
73+
{
74+
if ($level instanceof Level) {
75+
$level = $level->value;
76+
}
77+
78+
switch ($level) {
79+
case Logger::DEBUG:
80+
return Breadcrumb::LEVEL_DEBUG;
81+
case Logger::INFO:
82+
case Logger::NOTICE:
83+
return Breadcrumb::LEVEL_INFO;
84+
case Logger::WARNING:
85+
return Breadcrumb::LEVEL_WARNING;
86+
case Logger::ERROR:
87+
return Breadcrumb::LEVEL_ERROR;
88+
default:
89+
return Breadcrumb::LEVEL_FATAL;
90+
}
91+
}
92+
93+
private function getBreadcrumbType(int $level): string
94+
{
95+
if ($level >= Logger::ERROR) {
96+
return Breadcrumb::TYPE_ERROR;
97+
}
98+
99+
return Breadcrumb::TYPE_DEFAULT;
100+
}
101+
}

src/Tracing/SpanId.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44

55
namespace Sentry\Tracing;
66

7+
use Sentry\Util\SentryUid;
8+
79
/**
810
* This class represents an span ID.
911
*/
@@ -33,7 +35,7 @@ public function __construct(string $value)
3335
*/
3436
public static function generate(): self
3537
{
36-
return new self(substr(str_replace('-', '', uuid_create(UUID_TYPE_RANDOM)), 0, 16));
38+
return new self(substr(SentryUid::generate(), 0, 16));
3739
}
3840

3941
/**

0 commit comments

Comments
 (0)