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
31 changes: 30 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,10 @@ Some changes do not cause an error, so nothing will point you to them. Check eac
- The send_default_pii option is gone, and the defaults of the data_collection option collect more
data than before, whichever value send_default_pii had. What gets collected is a privacy decision
that is mine to make: apply the restrictive configuration from the guide, which is the closest to
the old behavior, and list what I could enable on top of it.
the old behavior, and list what I could enable on top of it. This only applies if the project
does not set the data_collection option yet. If it already does, send_default_pii was already
ignored and the existing data_collection configuration keeps applying, so only remove
send_default_pii.
- The client is never null anymore. Remove the null checks, and tell me where one of them was used
to detect that the SDK is not initialized.
- Sentry\Metrics\Metrics and \Sentry\metrics() still exist, but they are a different API now. Code
Expand Down Expand Up @@ -130,6 +133,32 @@ a span_id instead of the sentry.trace.parent_span_id attribute.
- Fix the argument names of closures in stack frames. [(#2370)](https://github.com/getsentry/sentry-php/pull/2370)
- Omit the `unit` of a metric and of a crontab monitor schedule when it is not set. [(#2373)](https://github.com/getsentry/sentry-php/pull/2373), [(#2374)](https://github.com/getsentry/sentry-php/pull/2374)

## 4.38.0

The Sentry SDK team is happy to announce the immediate availability of Sentry PHP SDK v4.38.0.

### Features

- Add `Scope::setUserResolver()` to resolve the user lazily each time it is read, instead of setting it upfront. User data set with `Scope::setUser()` takes precedence over the data the resolver returns. [(#2396)](https://github.com/getsentry/sentry-php/pull/2396)

```php
\Sentry\configureScope(static function (\Sentry\State\Scope $scope): void {
$scope->setUserResolver(static function (): ?\Sentry\UserDataBag {
// Return null as long as the user is not known yet
return \Sentry\UserDataBag::createFromUserIdentifier('1234');
});
});
```

## 4.37.1

The Sentry SDK team is happy to announce the immediate availability of Sentry PHP SDK v4.37.1.

### Bug Fixes

- Write the HTTP status code into the `http.response.status_code` data of a span in `Span::setHttpStatus()`, so that the `trace_ignore_status_codes` option also applies to transactions whose status is set this way. [(#2384)](https://github.com/getsentry/sentry-php/pull/2384)
- Fix a `TypeError` when the response of the HTTP client contains a header with a numeric name. [(#2366)](https://github.com/getsentry/sentry-php/pull/2366)

## 4.37.0

The Sentry SDK team is happy to announce the immediate availability of Sentry PHP SDK v4.37.0.
Expand Down
892 changes: 104 additions & 788 deletions analysis-baseline.toml

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
"psr/log": "^1.0|^2.0|^3.0"
},
"require-dev": {
"carthage-software/mago": "1.30.0",
"carthage-software/mago": "1.60.2",
"friendsofphp/php-cs-fixer": "^3.4",
"guzzlehttp/guzzle": "^7.0|^8.0",
"guzzlehttp/promises": "^2.0.3|^3.0.0",
Expand Down
3 changes: 2 additions & 1 deletion mago.toml
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
[source]
paths = ["src"]
includes = ["vendor"]
includes = ["vendor", "stubs"]
excludes = [
"tests/resources/**",
"tests/Fixtures/**",
"src/Util/ClockMock.php",
"vendor/open-telemetry/gen-otlp-protobuf/GPBMetadata/**",
]
extensions = ["php", "stub"]

[analyzer]
baseline = "analysis-baseline.toml"
Expand Down
12 changes: 0 additions & 12 deletions phpstan-baseline.neon
Original file line number Diff line number Diff line change
Expand Up @@ -396,12 +396,6 @@ parameters:
count: 1
path: src/Serializer/AbstractSerializer.php

-
message: '#^Parameter \#3 \$value of function curl_setopt expects int, float given\.$#'
identifier: argument.type
count: 2
path: src/Spotlight/SpotlightClient.php

-
message: '#^Parameter \#3 \$value of function curl_setopt expects non\-empty\-string, string given\.$#'
identifier: argument.type
Expand Down Expand Up @@ -438,12 +432,6 @@ parameters:
count: 1
path: src/UserDataBag.php

-
message: '#^PHPDoc tag @var with type list\<array\{function\?\: string, line\?\: int, file\?\: string, class\?\: class\-string, type\?\: string, args\?\: array\<mixed\>\}\> is not subtype of native type list\<array\{function\: string, line\?\: int, file\?\: string, class\?\: class\-string, type\?\: ''\-\>''\|''\:\:'', args\?\: list\<mixed\>, object\?\: object\}\>\.$#'
identifier: varTag.nativeType
count: 1
path: src/Util/CodeLocationResolver.php

-
message: '#^Instanceof between mixed and __PHP_Incomplete_Class will always evaluate to false\.$#'
identifier: instanceof.alwaysFalse
Expand Down
8 changes: 4 additions & 4 deletions src/Attachment/Attachment.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,17 +42,17 @@ public function getContentType(): string
* If no low overhead way exists, then the result should be cached so that calling it multiple times
* does not decrease performance.
*
* @return int the size in bytes or null if the length could not be determined, for example if the file
* does not exist
* @return int|null the size in bytes or null if the length could not be determined, for example if the file
* does not exist
*/
abstract public function getSize(): ?int;

/**
* Fetches and returns the data. Calling this can have a non-trivial impact on memory usage, depending
* on the type and size of attachment.
*
* @return string the content as bytes or null if the content could not be retrieved, for example if the file
* does not exist
* @return string|null the content as bytes or null if the content could not be retrieved, for example if the
* file does not exist
*/
abstract public function getData(): ?string;

Expand Down
2 changes: 1 addition & 1 deletion src/ClientReport/ClientReportAggregator.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ class ClientReportAggregator
* ]
*```
*
* @var array<array<string, int>>
* @var array<string, array<string, int>>
*/
private $reports = [];

Expand Down
2 changes: 1 addition & 1 deletion src/Dsn.php
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ public static function createFromString(string $value): self
}

foreach (['scheme', 'host', 'path', 'user'] as $component) {
if (!isset($parsedDsn[$component]) || (isset($parsedDsn[$component]) && empty($parsedDsn[$component]))) {
if (empty($parsedDsn[$component])) {
throw new \InvalidArgumentException(\sprintf('The "%s" DSN must contain a scheme, a host, a user and a path component.', $value));
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/Spotlight/SpotlightClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ public static function sendRequest(Request $request, string $url): Response
curl_setopt($curlHandle, \CURLOPT_HTTPHEADER, [
'Content-Type: application/x-sentry-envelope',
]);
curl_setopt($curlHandle, \CURLOPT_TIMEOUT, 2.0);
curl_setopt($curlHandle, \CURLOPT_CONNECTTIMEOUT, 1.0);
curl_setopt($curlHandle, \CURLOPT_TIMEOUT, 2);
curl_setopt($curlHandle, \CURLOPT_CONNECTTIMEOUT, 1);
curl_setopt($curlHandle, \CURLOPT_ENCODING, '');
curl_setopt($curlHandle, \CURLOPT_POST, true);
curl_setopt($curlHandle, \CURLOPT_POSTFIELDS, $requestData);
Expand Down
16 changes: 16 additions & 0 deletions src/State/MutableScope.php
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,22 @@ public function setUser($user): self
return $this;
}

/**
* Sets a callable that resolves the user each time it is read, which
* happens for every event, log and metric, so it should be cheap. The
* data set on the scope takes precedence over the data it returns.
*
* @param callable(): (UserDataBag|null) $userResolver
*
* @return $this
*/
public function setUserResolver(callable $userResolver): self
{
$this->scopeData->setUserResolver($userResolver);

return $this;
}

/**
* Removes all data of the user context.
*
Expand Down
49 changes: 48 additions & 1 deletion src/State/ScopeData.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,11 @@ class ScopeData
*/
private $user;

/**
* @var (callable(): (UserDataBag|null))|null The callable that resolves the user each time it is read
*/
private $userResolver;

/**
* @var array<string, array<string, mixed>> The list of contexts associated to this scope
*/
Expand Down Expand Up @@ -135,7 +140,45 @@ public function clearBreadcrumbs(): void

public function getUser(): ?UserDataBag
{
return $this->user;
if ($this->userResolver === null) {
return $this->user;
}

$userResolver = $this->userResolver;
// unset the callback to prevent recursion in case getUser is called in the callback
$this->userResolver = null;

try {
$resolvedUser = $userResolver();
} catch (\Throwable $exception) {
$resolvedUser = null;
} finally {
$this->userResolver = $userResolver;
}

if ($resolvedUser === null) {
return $this->user;
}

if ($this->user === null) {
return clone $resolvedUser;
}

$user = clone $this->user;
$user->setId($user->getId() ?? $resolvedUser->getId());
$user->setEmail($user->getEmail() ?? $resolvedUser->getEmail());
$user->setUsername($user->getUsername() ?? $resolvedUser->getUsername());
$user->setIpAddress($user->getIpAddress() ?? $resolvedUser->getIpAddress());

return (clone $resolvedUser)->merge($user);
}

/**
* @param callable(): (UserDataBag|null) $userResolver
*/
public function setUserResolver(callable $userResolver): void
{
$this->userResolver = $userResolver;
}

/**
Expand All @@ -161,6 +204,7 @@ public function setUser($user): void
public function removeUser(): void
{
$this->user = null;
$this->userResolver = null;
}

/**
Expand Down Expand Up @@ -328,6 +372,7 @@ public function addAttachment(Attachment $attachment): void
public function clear(): void
{
$this->user = null;
$this->userResolver = null;
$this->level = null;
$this->fingerprint = [];
$this->breadcrumbs = [];
Expand Down Expand Up @@ -363,6 +408,8 @@ public function merge(self $other): self
$merged->user = clone $this->user;
}

$merged->userResolver = $other->userResolver ?? $this->userResolver;

$merged->level = $other->level ?? $this->level;
$merged->fingerprint = array_merge($this->fingerprint, $other->fingerprint);
$merged->breadcrumbs = self::mergeBreadcrumbs($this->breadcrumbs, $other->breadcrumbs);
Expand Down
7 changes: 1 addition & 6 deletions src/Tracing/Transaction.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,6 @@ final class Transaction extends Span
*/
private $scope;

/**
* @var Transaction The transaction
*/
protected $transaction;

/**
* @var TransactionMetadata
*/
Expand Down Expand Up @@ -104,7 +99,7 @@ public function getDynamicSamplingContext(): DynamicSamplingContext
return $this->metadata->getDynamicSamplingContext();
}

$samplingContext = DynamicSamplingContext::fromTransaction($this->transaction, SentrySdk::getClient($this->scope));
$samplingContext = DynamicSamplingContext::fromTransaction($this, SentrySdk::getClient($this->scope));
$this->getMetadata()->setDynamicSamplingContext($samplingContext);

return $samplingContext;
Expand Down
3 changes: 3 additions & 0 deletions src/Transport/HttpTransport.php
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,9 @@ public function send(Event $event): Result
['exception' => $exception, 'event' => $event]
);

// No response was received, so this is recorded like a failed connection
ClientReportAggregator::getInstance()->addEvent($event, Reason::networkError());

return new Result(ResultStatus::failed());
}

Expand Down
2 changes: 1 addition & 1 deletion src/Util/CodeLocationResolver.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public function __construct(Options $options, RepresentationSerializerInterface
*/
public function resolve(int $limit = 20): ?array
{
/** @var list<StacktraceFrame> $backtrace */
/** @var list<array{function: string, line?: int, file?: string, class?: class-string, type?: '->'|'::'}> $backtrace */
$backtrace = debug_backtrace(\DEBUG_BACKTRACE_IGNORE_ARGS, $limit);

return $this->resolveFromBacktrace($backtrace);
Expand Down
Loading