diff --git a/README.md b/README.md index b5a058ca..2a288cb0 100644 --- a/README.md +++ b/README.md @@ -7,3 +7,4 @@ For creating a new RFC see [workflow](text/0001-workflow.md). * [0001-workflow](text/0001-workflow.md): the workflow RFC * [0004-import-reorg](text/0004-import-reorg.md): Sentry import reorganization +* [0014-continue-traces](text/0014-continue-traces.md): Continue trace on `start_transaction` diff --git a/text/0014-continue-traces.md b/text/0014-continue-traces.md new file mode 100644 index 00000000..32e51d5d --- /dev/null +++ b/text/0014-continue-traces.md @@ -0,0 +1,63 @@ +* Start Date: 2022-09-26 +* RFC Type: feature +* RFC PR: https://github.com/getsentry/rfcs/pull/14 + +# Summary + +This RFC proposes a new way to continue a trace when creating nested transactions. + +# Motivation + +The current way we propagate `sentry-trace` and `baggage`, is to pass a correctly populated `TransactionContext` as the first argument to `startTransaction()`. + +```php +use Sentry\Tracing\TransactionContext; +use function Sentry\startTransaction; + +$transactionContext = TransactionContext::fromHeaders($sentryTraceHeader, $baggageHeader); +$transaction = startTransaction($transactionContext); + +``` + +In case someone starts another nested transaction without passing in any context, a new trace will be started and the Dynamic Sampling Context is lost as well. +Using transactions inside transactions was a workaround as the span summary view was not available back then. + +# Options Considered + +## Add TransactionContext::fromParent() + +```php +use Sentry\Tracing\TransactionContext; +use function Sentry\startTransaction; + +$transactionContext = TransactionContext::fromParent($transaction); +$transaction = startTransaction($transactionContext); + +public static function fromParent(Transaction $transaction) +{ + $context = new self(); + $context->traceId = $transaction->getTraceId(); + $context->parentSpanId = $transaction->getParentSpanId(); + $context->sampled = $transaction->getSampled(); + $context->getMetadata()->setBaggage($transaction->getBaggage()); + + return $context; +} +``` + +## Add a third argument to `startTransaction()` + +```php +use Sentry\Tracing\TransactionContext; +use function Sentry\startTransaction; + +$transactionContext = new TransactionContext(); +$transaction = startTransaction($transactionContext, [], bool $continueTrace = true); +``` + +Inside `TransactionContext::__contruct`, we could check for an ongoing transaction on the Hub and continue the trace automatically. + +# Drawbacks/Impact + +- This will increase the public API surface of our SDKs +- Depending on the option, it's either more complex or more magical. \ No newline at end of file