Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
56 commits
Select commit Hold shift + click to select a range
f87224c
WIP
stayallive Aug 16, 2022
f569973
Merge branch 'develop' into dsc
cleptric Aug 19, 2022
053513f
feat: Add support for Dynamic Sampling
cleptric Aug 19, 2022
3860d0d
Merge branch 'develop' into dsc
cleptric Sep 19, 2022
6a9b291
Add failing test
cleptric Sep 19, 2022
3d588e1
Possible phpstan fixes
cleptric Sep 19, 2022
8e4a141
Revert visiblity change
cleptric Sep 19, 2022
b84c615
Add a transaction property
cleptric Sep 19, 2022
ff23c1f
Add missing Span::toBaggage test
cleptric Sep 19, 2022
86021df
Merge branch 'develop' into dsc
cleptric Sep 20, 2022
a9e52a3
Update psalm-baseline.xml
cleptric Sep 20, 2022
e8f87e0
Fix DynamicSamplingContextTest::testFromTransaction()
stayallive Sep 21, 2022
db89201
Fix syntax error
cleptric Sep 21, 2022
010de1f
Do not assign variable in if statement
cleptric Sep 23, 2022
49ebab8
Change var name and update comments
cleptric Sep 23, 2022
d7ca5dd
Merge branch 'develop' into dsc
cleptric Sep 23, 2022
54c228f
Use rawurldecode instead of urldecode
cleptric Sep 23, 2022
561c67c
Fix comment
cleptric Sep 26, 2022
0736fea
Update src/Serializer/PayloadSerializer.php
cleptric Sep 26, 2022
abcdd48
Change array order
cleptric Sep 26, 2022
e181fbd
Update src/Serializer/PayloadSerializer.php
cleptric Sep 26, 2022
d473337
Update comment format
cleptric Sep 26, 2022
c9b1ce0
Update src/Tracing/DynamicSamplingContext.php
cleptric Sep 26, 2022
cd4012c
Update tests/Tracing/DynamicSamplingContextTest.php
cleptric Sep 26, 2022
6c03d86
Update tests/Tracing/DynamicSamplingContextTest.php
cleptric Sep 26, 2022
faea722
Update tests/Tracing/DynamicSamplingContextTest.php
cleptric Sep 26, 2022
aa4420c
Change visibility & update constructor
cleptric Sep 26, 2022
49dc6bc
CS
cleptric Sep 26, 2022
5d8402c
Use property diretcly
cleptric Sep 26, 2022
927f830
Remove superfluous if condition
cleptric Sep 26, 2022
860e3f5
Add return type hint
cleptric Sep 26, 2022
e7d141b
CS
cleptric Sep 26, 2022
7a75703
Rename $dsc to $samplingContext
cleptric Sep 26, 2022
dd1cc1e
CS
cleptric Sep 26, 2022
65daf54
CS
cleptric Sep 26, 2022
6cb6c58
Update src/Event.php
cleptric Sep 26, 2022
e8a7e18
Merge branch 'develop' into dsc
cleptric Sep 26, 2022
a6d9db0
Add changelog
cleptric Sep 26, 2022
ee1613e
Fix psalm
cleptric Sep 26, 2022
d08c5a8
CS
cleptric Sep 26, 2022
48dd102
CS
cleptric Sep 26, 2022
6bcb1c3
Update test signature
cleptric Sep 26, 2022
498ec1b
Simplyfy test
cleptric Sep 26, 2022
b47a030
Change test signature
cleptric Sep 26, 2022
14134ec
Fix php 7.2
cleptric Sep 26, 2022
ee2a4b6
Simplyfy __toString
cleptric Sep 26, 2022
abc1eb2
CS
cleptric Sep 26, 2022
a5f26db
Use substr
cleptric Sep 26, 2022
4a4e1f7
Update test
cleptric Sep 26, 2022
7c78062
CS
cleptric Sep 26, 2022
27c3d59
General coding style improvements
ste93cry Sep 26, 2022
b256753
Return a `DynamicSamplingContext` object from `DynamicSamplingContext…
ste93cry Sep 26, 2022
564fba8
Use `str_starts_with()` instead of `strpos()`
ste93cry Sep 26, 2022
56ae991
Trigger a deprecation error from the `TransactionContext::fromSentryT…
ste93cry Sep 26, 2022
f9703b2
Partly revert “Trigger a deprecation error from the `TransactionConte…
cleptric Sep 27, 2022
511b3c9
Update CHANGELOG.md
cleptric Sep 28, 2022
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
6 changes: 5 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,11 @@

## Unreleased

- Expose a function to retrieve the URL of the CSP endpoint (#1378)
- feat: Expose a function to retrieve the URL of the CSP endpoint (#1378)
- feat: Add support for Dynamic Sampling (#1360)
- Add `segment` to `UserDataBag`
- Add `TransactionSource`, to set information about the transaction name
- Deprecate `TransactionContext::fromSentryTrace()` in favor of `TransactionContext::fromHeaders()`

## 3.8.1 (2022-09-21)

Expand Down
6 changes: 3 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
gc -am .PHONY: test

develop: update-submodules
composer install --dev
composer install
make setup-git

update-submodules:
git submodule init
git submodule update

cs:
vendor/bin/php-cs-fixer fix --config=.php_cs --verbose --diff
vendor/bin/php-cs-fixer fix --verbose --diff

cs-dry-run:
vendor/bin/php-cs-fixer fix --config=.php_cs --verbose --diff --dry-run
vendor/bin/php-cs-fixer fix --verbose --diff --dry-run

cs-fix:
vendor/bin/php-cs-fixer fix
Expand Down
5 changes: 5 additions & 0 deletions phpstan-baseline.neon
Original file line number Diff line number Diff line change
Expand Up @@ -340,6 +340,11 @@ parameters:
count: 1
path: src/UserDataBag.php

-
message: "#^Parameter \\#1 \\$segment of method Sentry\\\\UserDataBag\\:\\:setSegment\\(\\) expects string\\|null, mixed given\\.$#"
count: 1
path: src/UserDataBag.php

-
message: "#^Method Sentry\\\\Util\\\\JSON\\:\\:encode\\(\\) should return string but returns string\\|false\\.$#"
count: 1
Expand Down
7 changes: 6 additions & 1 deletion 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.26.0@6998fabb2bf528b65777bf9941920888d23c03ac">
<files psalm-version="4.27.0@faf106e717c37b8c81721845dba9de3d8deed8ff">
<file src="src/Dsn.php">
<PossiblyUndefinedArrayOffset occurrences="4">
<code>$parsedDsn['host']</code>
Expand Down Expand Up @@ -87,6 +87,11 @@
<code>new static()</code>
</UnsafeInstantiation>
</file>
<file src="src/Tracing/Transaction.php">
<NonInvariantDocblockPropertyType occurrences="1">
<code>$transaction</code>
</NonInvariantDocblockPropertyType>
</file>
<file src="src/functions.php">
<TooManyArguments occurrences="4">
<code>captureException</code>
Expand Down
39 changes: 39 additions & 0 deletions src/Event.php
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,14 @@ final class Event
*/
private $stacktrace;

/**
* A place to stash data which is needed at some point in the SDK's
* event processing pipeline but which shouldn't get sent to Sentry.
*
* @var array<string, mixed>
*/
private $sdkMetadata = [];
Comment thread
cleptric marked this conversation as resolved.
Resolved

/**
* @var string The Sentry SDK identifier
*/
Expand Down Expand Up @@ -671,6 +679,37 @@ public function getType(): EventType
return $this->type;
}

/**
* Sets the SDK metadata with the given name.
*
* @param string $name The name that uniquely identifies the SDK metadata
* @param mixed $data The data of the SDK metadata
Comment thread
cleptric marked this conversation as resolved.
Resolved
*/
public function setSdkMetadata(string $name, $data): void
{
$this->sdkMetadata[$name] = $data;
}

/**
* Gets the SDK metadata.
*
* @return mixed
Comment thread
cleptric marked this conversation as resolved.
Resolved
*
* @psalm-template T of string|null
*
* @psalm-param T $name
*
* @psalm-return (T is string ? mixed : array<string, mixed>|null)
*/
public function getSdkMetadata(?string $name = null)
{
if (null !== $name) {
return $this->sdkMetadata[$name] ?? null;
}

return $this->sdkMetadata;
}

/**
* Gets a timestamp representing when the measuring of a transaction started.
*/
Expand Down
45 changes: 40 additions & 5 deletions src/Serializer/PayloadSerializer.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,10 @@
use Sentry\EventType;
use Sentry\ExceptionDataBag;
use Sentry\Frame;
use Sentry\Options;
use Sentry\Tracing\DynamicSamplingContext;
use Sentry\Tracing\Span;
use Sentry\Tracing\TransactionMetadata;
use Sentry\Util\JSON;

/**
Expand All @@ -20,6 +23,16 @@
*/
final class PayloadSerializer implements PayloadSerializerInterface
{
/**
* @var Options The SDK client options
*/
private $options;

public function __construct(Options $options)
{
$this->options = $options;
}

/**
* {@inheritdoc}
*/
Expand Down Expand Up @@ -106,6 +119,7 @@ public function toArray(Event $event): array
'username' => $user->getUsername(),
'email' => $user->getEmail(),
'ip_address' => $user->getIpAddress(),
'segment' => $user->getSegment(),
]);
}

Expand Down Expand Up @@ -160,6 +174,11 @@ public function toArray(Event $event): array

if (EventType::transaction() === $event->getType()) {
$result['spans'] = array_values(array_map([$this, 'serializeSpan'], $event->getSpans()));
$transactionMetadata = $event->getSdkMetadata('transaction_metadata');

if ($transactionMetadata instanceof TransactionMetadata) {
$result['transaction_info']['source'] = (string) $transactionMetadata->getSource();
}
}

$stacktrace = $event->getStacktrace();
Expand All @@ -175,17 +194,33 @@ public function toArray(Event $event): array

private function serializeAsEnvelope(Event $event): string
{
$envelopeHeader = JSON::encode([
// @see https://develop.sentry.dev/sdk/envelopes/#envelope-headers
$envelopeHeader = [
'event_id' => (string) $event->getId(),
'sent_at' => gmdate('Y-m-d\TH:i:s\Z'),
]);
'dsn' => (string) $this->options->getDsn(),
'sdk' => [
'name' => $event->getSdkIdentifier(),
'version' => $event->getSdkVersion(),
],
];

$dynamicSamplingContext = $event->getSdkMetadata('dynamic_sampling_context');

if ($dynamicSamplingContext instanceof DynamicSamplingContext) {
$entries = $dynamicSamplingContext->getEntries();

$itemHeader = JSON::encode([
if (!empty($entries)) {
$envelopeHeader['trace'] = $entries;
}
}

$itemHeader = [
'type' => (string) $event->getType(),
'content_type' => 'application/json',
]);
];

return sprintf("%s\n%s\n%s", $envelopeHeader, $itemHeader, $this->serializeAsEvent($event));
return sprintf("%s\n%s\n%s", JSON::encode($envelopeHeader), JSON::encode($itemHeader), $this->serializeAsEvent($event));
}

/**
Expand Down
13 changes: 10 additions & 3 deletions src/State/Hub.php
Original file line number Diff line number Diff line change
Expand Up @@ -234,16 +234,23 @@ public function startTransaction(TransactionContext $context, array $customSampl
$tracesSampler = $options->getTracesSampler();

if (null === $transaction->getSampled()) {
$sampleRate = null !== $tracesSampler
? $tracesSampler($samplingContext)
: $this->getSampleRate($samplingContext->getParentSampled(), $options->getTracesSampleRate());
if (null !== $tracesSampler) {
Comment thread
cleptric marked this conversation as resolved.
Resolved
$sampleRate = $tracesSampler($samplingContext);
} else {
$sampleRate = $this->getSampleRate(
$samplingContext->getParentSampled(),
$options->getTracesSampleRate()
);
}

if (!$this->isValidSampleRate($sampleRate)) {
$transaction->setSampled(false);

return $transaction;
}

$transaction->getMetadata()->setSamplingRate($sampleRate);

if (0.0 === $sampleRate) {
$transaction->setSampled(false);

Expand Down
8 changes: 8 additions & 0 deletions src/State/Scope.php
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,14 @@ public function setExtras(array $extras): self
return $this;
}

/**
* Get the user context.
*/
public function getUser(): ?UserDataBag
{
return $this->user;
}

/**
* Merges the given data in the user context.
*
Expand Down
Loading