Skip to content

Commit 48c5fc7

Browse files
committed
Propose a new way to continue a trace
1 parent 7066f86 commit 48c5fc7

2 files changed

Lines changed: 64 additions & 0 deletions

File tree

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,4 @@ For creating a new RFC see [workflow](text/0001-workflow.md).
77

88
* [0001-workflow](text/0001-workflow.md): the workflow RFC
99
* [0004-import-reorg](text/0004-import-reorg.md): Sentry import reorganization
10+
* [0014-continue-traces](text/00XX-continue-traces.md): Continue trace on `start_transaction`

text/0014-continue-traces.md

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
* Start Date: 2022-09-26
2+
* RFC Type: feature
3+
* RFC PR: https://github.com/getsentry/rfcs/pull/14
4+
5+
# Summary
6+
7+
This RFC proposes a new way to continue a trace when creating nested transactions.
8+
9+
# Motivation
10+
11+
The current way we propagate `sentry-trace` and `baggage`, is to pass a correctly populated `TransactionContext` as the first argument to `startTransaction()`.
12+
13+
```php
14+
use Sentry\Tracing\TransactionContext;
15+
use function Sentry\startTransaction;
16+
17+
$transactionContext = TransactionContext::continueFromHeaders($sentryTraceHeader, $baggageHeader);
18+
$transaction = startTransaction($transactionContext);
19+
20+
```
21+
22+
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.
23+
24+
# Options Considered
25+
26+
## Add TransactionContext::fromParent()
27+
28+
```php
29+
use Sentry\Tracing\TransactionContext;
30+
use function Sentry\startTransaction;
31+
32+
$transactionContext = TransactionContext::fromParent($transaction);
33+
$transaction = startTransaction($transactionContext);
34+
35+
public static function fromParent(Transaction $transaction)
36+
{
37+
$context = new self();
38+
$context->traceId = $transaction->getTraceId();
39+
$context->parentSpanId = $transaction->getParentSpanId();
40+
$context->sampled = $transaction->getSampled();
41+
$context->getMetadata()->setBaggage($transaction->getBaggage());
42+
43+
return $context;
44+
}
45+
```
46+
47+
## Add a third argument to `startTransaction()`
48+
49+
```php
50+
use Sentry\Tracing\TransactionContext;
51+
use function Sentry\startTransaction;
52+
53+
$transactionContext = new TransactionContext();
54+
$transaction = startTransaction($transactionContext, [], bool $continueTrace = true);
55+
```
56+
57+
This would require making the SDKs aware of the current request.
58+
In PHP, we could rely on `$_SERVER['HTTP_SENTRY_TRACE]` and `$_SERVER['HTTP_BAGGAGE]`, but this is not possible in all languages.
59+
60+
# Unresolved questions
61+
62+
* Can we rely on `SentrySdk::getCurrentHub()->getTransaction()` to fetch the current transaction to be passed into `TransactionContext::fromParent()` ?
63+
* How would we make `TransactionContext::__construct()` aware of the current request?

0 commit comments

Comments
 (0)