sentry-php icon indicating copy to clipboard operation
sentry-php copied to clipboard

feat: Add support for Dynamic Sampling

Open cleptric opened this issue 3 years ago • 1 comments

Add support for Dynamic Sampling

We decided not to access the request internally and will instead rely on people passing in a correctly populated TransactionContext to be able to use Dynamic Sampling. This is in line with the implementation of the propagation of sentry-trace.

For our Laravel and Symfony SDKs, we can then set this up automatically.

Additional, the following required items for DS were added :

  • The TransactionSource https://develop.sentry.dev/sdk/event-payloads/transaction/#transaction-annotations
  • The user_segment https://develop.sentry.dev/sdk/event-payloads/user/#attributes & https://develop.sentry.dev/sdk/performance/dynamic-sampling-context/#envelope-header
  • An adequately populated envelope header https://develop.sentry.dev/sdk/performance/dynamic-sampling-context/#envelope-header

Usage example:

use Sentry\Tracing\TransactionContext;
use function Sentry\startTransaction;

$sentryTraceHeader = $request->getHeaderLine('sentry-trace');
$baggageHeader = $request->getHeaderLine('baggage');

$transactionContext = TransactionContext::continueFromHeaders($sentryTraceHeader, $baggageHeader);

...
startTransaction($transactionContext);

Co-authored-by: Alex Bouma

cleptric avatar Sep 13 '22 09:09 cleptric

Sure thing, we can split it up once I'm done. Right now, this is more of a dumping ground so CI runs on all PHP versions 😄

cleptric avatar Sep 15 '22 14:09 cleptric

Thanks for the feedback everyone. I'm planning to merge this tomorrow.

cleptric avatar Sep 26 '22 12:09 cleptric

@ste93cry Next time, please don’t update my branches without consulting me first. You are always welcome to branch off from my branch and propose your changes in a separate PR.

While I appreciate the updates to the test suite, I’ll have to revert your last commit partially, as my team and I agree on not adding further deprecation warnings to the code base. We added an @deprecated annotation, we will point this out more clearly in the changelog and will cover this as well in the migration guide for v4.0.

cleptric avatar Sep 27 '22 14:09 cleptric

We added an @deprecated annotation, we will point this out more clearly in the changelog and will cover this as well in the migration guide for v4.0.

People don't care about docblocks, they don't even see them in their day-to-day work and there is no way for them to know that something got deprecated if they don't look specifically at each doblock each time. @trigger_error is the standard way nowadays in PHP projects to let them know that some method is gonna be deprecated and removed.

as my team and I agree on not adding further deprecation warnings to the code base

I would love to hear the reasons behind this choice. Furthermore, I would like to add that, while we're at it, we're all in the same team, and so if such a decision was taken, at least it should have been communicated to the most active contributors of this project :sweat_smile:

ste93cry avatar Sep 27 '22 14:09 ste93cry

Nothing is wrong if people continue using TransactionContext::fromSentryTrace, if they don't want to use Dynamic Sampling. We will likely release this before Symfony and Laravel, so I rather not add deprecation warnings to people's apps, without a way for them to fix it.

We discussed this in our daily, the team is @getsentry/team-web-sdk-backend.

cleptric avatar Sep 27 '22 14:09 cleptric

Having just a @deprecated annotation gets a thumbs up from me, as static analysis tools can easily pick up on these annotations and warn the developer. A deprecation could always be "escalated" later on by adding trigger_error() call, when it's more actionable.

mfb avatar Sep 27 '22 21:09 mfb

I wonder how many notifications https://github.com/deprecated gets because of @deprecated :D

vladanpaunovic avatar Sep 28 '22 12:09 vladanpaunovic