Skip to content

Commit

Permalink
Propose a new way to continue a trace
Browse files Browse the repository at this point in the history
  • Loading branch information
cleptric committed Sep 26, 2022
1 parent 7066f86 commit 5f9650b
Show file tree
Hide file tree
Showing 2 changed files with 64 additions and 0 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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`
63 changes: 63 additions & 0 deletions text/0014-continue-traces.md
Original file line number Diff line number Diff line change
@@ -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::continueFromHeaders($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.

# 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);
```

This would require making the SDKs aware of the current request.
In PHP, we could rely on `$_SERVER['HTTP_SENTRY_TRACE]` and `$_SERVER['HTTP_BAGGAGE]`, but this is not possible in all languages.

# Unresolved questions

* Can we rely on `SentrySdk::getCurrentHub()->getTransaction()` to fetch the current transaction to be passed into `TransactionContext::fromParent()` ?
* How would we make `TransactionContext::__construct()` aware of the current request?

0 comments on commit 5f9650b

Please sign in to comment.