You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
feat(native): transactions as automatic trace boundaries (#14586)
This PR adds documentation for the behavior introduced in
getsentry/sentry-native#1270.
This PR should be merged/deployed after the Native SDK release `0.10.0`.
## IS YOUR CHANGE URGENT?
Help us prioritize incoming PRs by letting us know when the change needs
to go live.
- [ ] Urgent deadline (GA date, etc.): <!-- ENTER DATE HERE -->
- [ ] Other deadline: <!-- ENTER DATE HERE -->
- [x] None: Not urgent, can wait up to 1 week+
## SLA
- Teamwork makes the dream work, so please add a reviewer to your PRs.
- Please give the docs team up to 1 week to review your PR unless you've
added an urgent due date to it.
Thanks in advance for your help!
## PRE-MERGE CHECKLIST
*Make sure you've checked the following before merging your changes:*
- [ ] Checked Vercel preview for correctness, including links
- [ ] PR was reviewed and approved by any necessary SMEs (subject matter
experts)
- [ ] PR was reviewed and approved by a member of the [Sentry docs
team](https://github.com/orgs/getsentry/teams/docs)
## EXTRA RESOURCES
- [Sentry Docs contributor guide](https://docs.sentry.io/contributing/)
---------
Co-authored-by: JoshuaMoelans <[email protected]>
Copy file name to clipboardExpand all lines: platform-includes/performance/add-spans-example/native.mdx
+48-6Lines changed: 48 additions & 6 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -38,26 +38,68 @@ void perform_checkout() {
38
38
39
39
This example will send a transaction named `checkout` to Sentry. The transaction will contain a `validation` span that measures how long `validate_shopping_cart()` took and a `process` span that measures `process_shopping_cart()`. Finally, the call to `sentry_transaction_finish()` will finish the transaction and send it to Sentry.
40
40
41
-
## Trace Boundaries
42
-
By default, events, transactions, and spans will inherit the `trace_id` from the `propagation_context` as generated during SDK initialization. These values can be overridden by a downstream SDK that calls `sentry_set_trace(trace_id, parent_span_id)`, or by a user who can manually create a trace boundary using `sentry_generate_trace()`:
41
+
## Automatic Trace Boundaries
43
42
44
-
```c
43
+
By default, events will inherit the `trace_id` from the `propagation_context` as generated during SDK initialization.
44
+
45
+
Transactions act as automatic trace boundaries, meaning whenever you create a transaction, it will start a new trace, which the SDK will apply as soon as you scope it. Once you finish the transaction, the SDK will move the trace to the `propagation_context`, from which the trace will affect any event until you scope a new transaction:
46
+
47
+
```C
45
48
// Upon init, generates a random trace_id and span_id in the propagation_context
46
49
sentry_options_t *options = sentry_options_new();
47
50
sentry_init(options);
48
-
// Events, transactions and spans will inherit the trace data from this propagation_context
49
-
initialize_store();
51
+
52
+
// Events will inherit the trace data from this propagation_context
53
+
54
+
// the transaction inside perform_checkout() will lead to a new trace in the propgation_context
55
+
perform_checkout();
56
+
57
+
// After perform_checkout() events will inherit the trace created in perform_checkout() from the propagation_context
58
+
```
59
+
60
+
## Manual Trace Boundaries
61
+
62
+
The SDK will turn off managing automatic trace boundaries via transactions once manual management of trace boundaries
63
+
was requested by either a downstream SDK (using `sentry_set_trace(trace_id, parent_span_id)`) or a direct user of the
64
+
Native SDK (via `sentry_regenerate_trace()`):
65
+
66
+
```C
67
+
sentry_options_t *options = sentry_options_new();
68
+
sentry_init(options);
50
69
51
70
// trace_id and parent_span_id usually originate from a downstream SDK
52
71
// (which should be the one calling `sentry_set_trace`)
// Set the trace propagation_context with the given data
75
+
// Set the trace propagation_context with the given data.
76
+
// Downstream SDKs should do this as early as possible.
57
77
sentry_set_trace(trace_id, parent_span_id);
78
+
79
+
// Events, transactions and spans inside authenticate_user() will be part
80
+
// of a different trace than the one created during initialization.
58
81
authenticate_user();
82
+
```
83
+
84
+
```C
85
+
sentry_options_t *options = sentry_options_new();
86
+
sentry_init(options);
59
87
60
88
// Generates a new random trace and span id onto the propagation_context
61
89
sentry_regenerate_trace();
90
+
authenticate_user();
91
+
92
+
sentry_regenerate_trace();
93
+
// Events, transactions, and spans inside perform_checkout() will be part of
94
+
// a different trace than the ones inside authenticate_user()
62
95
perform_checkout();
63
96
```
97
+
98
+
After the client called either function, the following transactions inherit that trace from the `propagation_context` and no longer act as trace boundaries.
0 commit comments