Skip to content

Commit

Permalink
Deprecate user segment (#1681)
Browse files Browse the repository at this point in the history
  • Loading branch information
cleptric authored Jan 17, 2024
1 parent 7c2f605 commit 7ac8703
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 28 deletions.
10 changes: 0 additions & 10 deletions src/Tracing/DynamicSamplingContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -182,12 +182,6 @@ public static function fromTransaction(Transaction $transaction, HubInterface $h
}
}

$hub->configureScope(static function (Scope $scope) use ($samplingContext): void {
if ($scope->getUser() !== null && $scope->getUser()->getSegment() !== null) {
$samplingContext->set('user_segment', $scope->getUser()->getSegment());
}
});

if ($transaction->getSampled() !== null) {
$samplingContext->set('sampled', $transaction->getSampled() ? 'true' : 'false');
}
Expand Down Expand Up @@ -218,10 +212,6 @@ public static function fromOptions(Options $options, Scope $scope): self
$samplingContext->set('environment', $options->getEnvironment());
}

if ($scope->getUser() !== null && $scope->getUser()->getSegment() !== null) {
$samplingContext->set('user_segment', $scope->getUser()->getSegment());
}

$samplingContext->freeze();

return $samplingContext;
Expand Down
4 changes: 4 additions & 0 deletions src/UserDataBag.php
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,8 @@ public function setEmail(?string $email): self

/**
* Gets the segement of the user.
*
* @deprecated since version 4.4. To be removed in version 5.0
*/
public function getSegment(): ?string
{
Expand All @@ -193,6 +195,8 @@ public function getSegment(): ?string
* Sets the segment of the user.
*
* @param string|null $segment The segment
*
* @deprecated since version 4.4. To be removed in version 5.0. You may use a custom tag or context instead.
*/
public function setSegment(?string $segment): self
{
Expand Down
19 changes: 1 addition & 18 deletions tests/Tracing/DynamicSamplingContextTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
use Sentry\Tracing\Transaction;
use Sentry\Tracing\TransactionContext;
use Sentry\Tracing\TransactionSource;
use Sentry\UserDataBag;

final class DynamicSamplingContextTest extends TestCase
{
Expand All @@ -29,7 +28,6 @@ public function testFromHeader(
?string $expectedSampleRate,
?string $expectedRelease,
?string $expectedEnvironment,
?string $expectedUserSegment,
?string $expectedTransaction
): void {
$samplingContext = DynamicSamplingContext::fromHeader($header);
Expand All @@ -39,7 +37,6 @@ public function testFromHeader(
$this->assertSame($expectedSampleRate, $samplingContext->get('sample_rate'));
$this->assertSame($expectedRelease, $samplingContext->get('release'));
$this->assertSame($expectedEnvironment, $samplingContext->get('environment'));
$this->assertSame($expectedUserSegment, $samplingContext->get('user_segment'));
$this->assertSame($expectedTransaction, $samplingContext->get('transaction'));
}

Expand All @@ -64,7 +61,6 @@ public static function fromHeaderDataProvider(): \Generator
null,
null,
null,
null,
];

yield [
Expand All @@ -74,7 +70,6 @@ public static function fromHeaderDataProvider(): \Generator
'1',
'1.0.0',
'test',
'my_segment',
'<unlabeled transaction>',
];
}
Expand All @@ -90,13 +85,7 @@ public function testFromTransaction(): void
'environment' => 'test',
]));

$user = new UserDataBag();
$user->setSegment('my_segment');

$scope = new Scope();
$scope->setUser($user);

$hub = new Hub($client, $scope);
$hub = new Hub($client);

$transactionContext = new TransactionContext();
$transactionContext->setName('foo');
Expand All @@ -112,7 +101,6 @@ public function testFromTransaction(): void
$this->assertSame('public', $samplingContext->get('public_key'));
$this->assertSame('1.0.0', $samplingContext->get('release'));
$this->assertSame('test', $samplingContext->get('environment'));
$this->assertSame('my_segment', $samplingContext->get('user_segment'));
$this->assertTrue($samplingContext->isFrozen());
}

Expand Down Expand Up @@ -143,11 +131,7 @@ public function testFromOptions(): void
$propagationContext = PropagationContext::fromDefaults();
$propagationContext->setTraceId(new TraceId('21160e9b836d479f81611368b2aa3d2c'));

$user = new UserDataBag();
$user->setSegment('my_segment');

$scope = new Scope();
$scope->setUser($user);
$scope->setPropagationContext($propagationContext);

$samplingContext = DynamicSamplingContext::fromOptions($options, $scope);
Expand All @@ -157,7 +141,6 @@ public function testFromOptions(): void
$this->assertSame('public', $samplingContext->get('public_key'));
$this->assertSame('1.0.0', $samplingContext->get('release'));
$this->assertSame('test', $samplingContext->get('environment'));
$this->assertSame('my_segment', $samplingContext->get('user_segment'));
$this->assertTrue($samplingContext->isFrozen());
}

Expand Down

0 comments on commit 7ac8703

Please sign in to comment.