Skip to content
Merged
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
18 changes: 18 additions & 0 deletions .github/workflows/changelog-preview.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
name: Changelog Preview
on:
pull_request:
types:
- opened
- synchronize
- reopened
- edited
- labeled
- unlabeled
permissions:
contents: write
pull-requests: write

jobs:
changelog-preview:
uses: getsentry/craft/.github/workflows/changelog-preview.yml@v2
secrets: inherit
18 changes: 9 additions & 9 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,15 +27,15 @@ jobs:
- ubuntu-latest
- windows-latest
php:
- { version: '7.2', phpunit: '^8.5.40' }
- { version: '7.3', phpunit: '^9.6.21' }
- { version: '7.4', phpunit: '^9.6.21' }
- { version: '8.0', phpunit: '^9.6.21' }
- { version: '8.1', phpunit: '^9.6.21' }
- { version: '8.2', phpunit: '^9.6.21' }
- { version: '8.3', phpunit: '^9.6.21' }
- { version: '8.4', phpunit: '^9.6.21' }
- { version: '8.5', phpunit: '^9.6.25' }
- { version: '7.2', phpunit: '^8.5.52' }
- { version: '7.3', phpunit: '^9.6.34' }
- { version: '7.4', phpunit: '^9.6.34' }
- { version: '8.0', phpunit: '^9.6.34' }
- { version: '8.1', phpunit: '^9.6.34' }
- { version: '8.2', phpunit: '^9.6.34' }
- { version: '8.3', phpunit: '^9.6.34' }
- { version: '8.4', phpunit: '^9.6.34' }
- { version: '8.5', phpunit: '^9.6.34' }
dependencies:
- lowest
- highest
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/publish-release.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ jobs:
steps:
- name: Get auth token
id: token
uses: actions/create-github-app-token@7e473efe3cb98aa54f8d4bac15400b15fad77d94 # v2.2.0
uses: actions/create-github-app-token@29824e69f54612133e76f7eaac726eef6c875baf # v2.2.1
with:
app-id: ${{ vars.SENTRY_RELEASE_BOT_CLIENT_ID }}
private-key: ${{ secrets.SENTRY_RELEASE_BOT_PRIVATE_KEY }}
Expand All @@ -35,7 +35,7 @@ jobs:
fetch-depth: 0

- name: Prepare release
uses: getsentry/action-prepare-release@v1
uses: getsentry/craft@c6e2f04939b6ee67030588afbb5af76b127d8203
env:
GITHUB_TOKEN: ${{ steps.token.outputs.token }}
with:
Expand Down
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,6 @@ package.xml
.phpunit.result.cache
docs/_build
tests/clover.xml

# Local Claude Code settings that should not be committed
.claude/settings.local.json
1 change: 1 addition & 0 deletions .php-cs-fixer.dist.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
],
'no_whitespace_before_comma_in_array' => false, // Should be dropped when we drop support for PHP 7.x
'stringable_for_to_string' => false,
'modern_serialization_methods' => false, // Could be re-enabled when we drop support for PHP 7.3 and lower
])
->setRiskyAllowed(true)
->setFinder(
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
"monolog/monolog": "^1.6|^2.0|^3.0",
"phpbench/phpbench": "^1.0",
"phpstan/phpstan": "^1.3",
"phpunit/phpunit": "^8.5|^9.6",
"phpunit/phpunit": "^8.5.52|^9.6.34",
"vimeo/psalm": "^4.17"
},
"suggest": {
Expand Down
2 changes: 1 addition & 1 deletion src/HttpClient/HttpClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ public function sendRequest(Request $request, Options $options): Response
}

$responseHeaders = [];
$responseHeaderCallback = function ($curlHandle, $headerLine) use (&$responseHeaders): int {
$responseHeaderCallback = static function ($curlHandle, $headerLine) use (&$responseHeaders): int {
return Http::parseResponseHeaders($headerLine, $responseHeaders);
};

Expand Down
4 changes: 2 additions & 2 deletions src/Logs/LogsAggregator.php
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ public function add(
$log->setAttribute('sentry.sdk.version', $client->getSdkVersion());
}

$hub->configureScope(function (Scope $scope) use ($log) {
$hub->configureScope(static function (Scope $scope) use ($log) {
$user = $scope->getUser();
if ($user !== null) {
if ($user->getId() !== null) {
Expand Down Expand Up @@ -181,7 +181,7 @@ private function getTraceId(HubInterface $hub): string

$traceId = '';

$hub->configureScope(function (Scope $scope) use (&$traceId) {
$hub->configureScope(static function (Scope $scope) use (&$traceId) {
$traceId = (string) $scope->getPropagationContext()->getTraceId();
});

Expand Down
4 changes: 2 additions & 2 deletions src/Metrics/MetricsAggregator.php
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ public function add(
];

if ($options->shouldSendDefaultPii()) {
$hub->configureScope(function (Scope $scope) use (&$defaultAttributes) {
$hub->configureScope(static function (Scope $scope) use (&$defaultAttributes) {
$user = $scope->getUser();
if ($user !== null) {
if ($user->getId() !== null) {
Expand Down Expand Up @@ -111,7 +111,7 @@ public function add(
$spanId = $span->getSpanId();
$traceId = $span->getTraceId();
} else {
$hub->configureScope(function (Scope $scope) use (&$traceId, &$spanId) {
$hub->configureScope(static function (Scope $scope) use (&$traceId, &$spanId) {
$propagationContext = $scope->getPropagationContext();
$traceId = $propagationContext->getTraceId();
$spanId = $propagationContext->getSpanId();
Expand Down
23 changes: 18 additions & 5 deletions src/Monolog/LogsHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,9 @@ class LogsHandler implements HandlerInterface
/**
* The minimum logging level at which this handler will be triggered.
*
* @var LogLevel
* @psalm-suppress UndefinedDocblockClass
*
* @var LogLevel|\Monolog\Level|int
*/
private $logLevel;

Expand All @@ -32,21 +34,32 @@ class LogsHandler implements HandlerInterface
/**
* Creates a new Monolog handler that converts Monolog logs to Sentry logs.
*
* @param LogLevel|null $logLevel the minimum logging level at which this handler will be triggered and collects the logs
* @param bool $bubble whether the messages that are handled can bubble up the stack or not
* @psalm-suppress UndefinedDocblockClass
*
* @param LogLevel|\Monolog\Level|int|null $logLevel the minimum logging level at which this handler will be triggered and collects the logs
* @param bool $bubble whether the messages that are handled can bubble up the stack or not
*/
public function __construct(?LogLevel $logLevel = null, bool $bubble = true)
public function __construct($logLevel = null, bool $bubble = true)
{
$this->logLevel = $logLevel ?? LogLevel::debug();
$this->bubble = $bubble;
}

/**
* @psalm-suppress UndefinedDocblockClass
* @psalm-suppress UndefinedClass
*
* @param array<string, mixed>|LogRecord $record
*/
public function isHandling($record): bool
{
return self::getSentryLogLevelFromMonologLevel($record['level'])->getPriority() >= $this->logLevel->getPriority();
if ($this->logLevel instanceof LogLevel) {
return self::getSentryLogLevelFromMonologLevel($record['level'])->getPriority() >= $this->logLevel->getPriority();
} elseif ($this->logLevel instanceof \Monolog\Level) {
return $record['level'] >= $this->logLevel->value;
}

return $record['level'] >= $this->logLevel;
}

/**
Expand Down
18 changes: 18 additions & 0 deletions src/SentrySdk.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

namespace Sentry;

use Sentry\Logs\Logs;
use Sentry\Metrics\TraceMetrics;
use Sentry\State\Hub;
use Sentry\State\HubInterface;

Expand Down Expand Up @@ -64,4 +66,20 @@ public static function setCurrentHub(HubInterface $hub): HubInterface

return $hub;
}

/**
* Flushes all buffered telemetry data.
*
* This is a convenience facade that forwards the flush operation to all
* internally managed components.
*
* Calling this method is equivalent to invoking `flush()` on each component
* individually. It does not change flushing behavior, improve performance,
* or reduce the number of network requests.
*/
public static function flush(): void
{
Logs::getInstance()->flush();
TraceMetrics::getInstance()->flush();
}
}
2 changes: 1 addition & 1 deletion src/Tracing/Span.php
Original file line number Diff line number Diff line change
Expand Up @@ -299,7 +299,7 @@ public function setStatus(?SpanStatus $status)
*/
public function setHttpStatus(int $statusCode)
{
SentrySdk::getCurrentHub()->configureScope(function (Scope $scope) use ($statusCode) {
SentrySdk::getCurrentHub()->configureScope(static function (Scope $scope) use ($statusCode) {
$scope->setContext('response', [
'status_code' => $statusCode,
]);
Expand Down
28 changes: 22 additions & 6 deletions src/functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
use Sentry\Tracing\SpanContext;
use Sentry\Tracing\Transaction;
use Sentry\Tracing\TransactionContext;
use Sentry\Transport\TransportInterface;

/**
* Creates a new Client and Hub which will be set as current.
Expand Down Expand Up @@ -61,7 +62,7 @@
* trace_propagation_targets?: array<string>|null,
* traces_sample_rate?: float|int|null,
* traces_sampler?: callable|null,
* transport?: callable,
* transport?: TransportInterface|null,
* } $options The client options
*/
function init(array $options = []): void
Expand Down Expand Up @@ -247,7 +248,7 @@ function startTransaction(TransactionContext $context, array $customSamplingCont
*/
function trace(callable $trace, SpanContext $context)
{
return SentrySdk::getCurrentHub()->withScope(function (Scope $scope) use ($context, $trace) {
return SentrySdk::getCurrentHub()->withScope(static function (Scope $scope) use ($context, $trace) {
$parentSpan = $scope->getSpan();

// If there is a span set on the scope and it's sampled there is an active transaction.
Expand Down Expand Up @@ -289,7 +290,7 @@ function getTraceparent(): string
}

$traceParent = '';
$hub->configureScope(function (Scope $scope) use (&$traceParent) {
$hub->configureScope(static function (Scope $scope) use (&$traceParent) {
$traceParent = $scope->getPropagationContext()->toTraceparent();
});

Expand All @@ -314,7 +315,7 @@ function getBaggage(): string
}

$baggage = '';
$hub->configureScope(function (Scope $scope) use (&$baggage) {
$hub->configureScope(static function (Scope $scope) use (&$baggage) {
$baggage = $scope->getPropagationContext()->toBaggage();
});

Expand All @@ -330,7 +331,7 @@ function getBaggage(): string
function continueTrace(string $sentryTrace, string $baggage): TransactionContext
{
$hub = SentrySdk::getCurrentHub();
$hub->configureScope(function (Scope $scope) use ($sentryTrace, $baggage) {
$hub->configureScope(static function (Scope $scope) use ($sentryTrace, $baggage) {
$propagationContext = PropagationContext::fromHeaders($sentryTrace, $baggage);
$scope->setPropagationContext($propagationContext);
});
Expand All @@ -357,7 +358,22 @@ function trace_metrics(): TraceMetrics
*/
function addFeatureFlag(string $name, bool $result): void
{
SentrySdk::getCurrentHub()->configureScope(function (Scope $scope) use ($name, $result) {
SentrySdk::getCurrentHub()->configureScope(static function (Scope $scope) use ($name, $result) {
$scope->addFeatureFlag($name, $result);
});
}

/**
* Flushes all buffered telemetry data.
*
* This is a convenience facade that forwards the flush operation to all
* internally managed components.
*
* Calling this method is equivalent to invoking `flush()` on each component
* individually. It does not change flushing behavior, improve performance,
* or reduce the number of network requests.
*/
function flush(): void
{
SentrySdk::flush();
}
2 changes: 1 addition & 1 deletion tests/ClientTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -980,7 +980,7 @@ public function testAttachStacktrace(): void
$transport = $this->createMock(TransportInterface::class);
$transport->expects($this->once())
->method('send')
->with($this->callback(function (Event $event): bool {
->with($this->callback(static function (Event $event): bool {
$result = $event->getStacktrace();

return $result !== null;
Expand Down
10 changes: 5 additions & 5 deletions tests/FrameBuilderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -290,7 +290,7 @@ public function testGetFunctionArgumentsWithVariadicParameters(): void
$options = new Options([]);
$frameBuilder = new FrameBuilder($options, new RepresentationSerializer($options));

$testFunction = function (string $first, int $second, ...$rest) {
$testFunction = static function (string $first, int $second, ...$rest) {
};

$backtraceFrame = [
Expand Down Expand Up @@ -325,7 +325,7 @@ public function testGetFunctionArgumentsWithOnlyVariadicParameters(): void
$options = new Options([]);
$frameBuilder = new FrameBuilder($options, new RepresentationSerializer($options));

$testFunction = function (...$args) {
$testFunction = static function (...$args) {
};

$backtraceFrame = [
Expand All @@ -352,7 +352,7 @@ public function testGetFunctionArgumentsWithEmptyVariadicParameters(): void
$options = new Options([]);
$frameBuilder = new FrameBuilder($options, new RepresentationSerializer($options));

$testFunction = function (string $first, ...$rest) {
$testFunction = static function (string $first, ...$rest) {
};

$backtraceFrame = [
Expand Down Expand Up @@ -381,7 +381,7 @@ public function testGetFunctionArgumentsWithNullValues(): void
$options = new Options([]);
$frameBuilder = new FrameBuilder($options, new RepresentationSerializer($options));

$testFunction = function (string $first, $second, ...$rest) {
$testFunction = static function (string $first, $second, ...$rest) {
};

$backtraceFrame = [
Expand Down Expand Up @@ -411,7 +411,7 @@ public function testGetFunctionArgumentsWithGapsInBacktraceArrayIndices(): void
$options = new Options([]);
$frameBuilder = new FrameBuilder($options, new RepresentationSerializer($options));

$testFunction = function (string $first, int $second, ...$rest) {
$testFunction = static function (string $first, int $second, ...$rest) {
};

$backtraceFrameArgs = [];
Expand Down
Loading