Skip to content

Commit 6f53ba6

Browse files
fix(native): Update Trace Boundaries documentation (#14201)
<!-- Use this checklist to make sure your PR is ready for merge. You may delete any sections you don't need. --> [Current docs](https://docs.sentry.io/platforms/native/tracing/instrumentation/custom-instrumentation/) [Updated docs (vercel preview)](https://sentry-docs-git-joshua-settraceclarification.sentry.dev/platforms/native/tracing/instrumentation/custom-instrumentation/#trace-boundaries) ## DESCRIBE YOUR PR Adding some more detailed explanation on the Native handling of trace boundaries & when/how to set a new trace. Only merge after getsentry/sentry-native#1293 ToDo - [x] add better explanation - [x] ? provide example of generating new trace/span ID? - we don't really have an API for this (yet), but we could reuse `sentry_uuid_t uid = sentry_uuid_new_v4();`? -> added in getsentry/sentry-native#1293 ## 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+ --------- Co-authored-by: Mischan Toosarani-Hausberger <mischan@abovevacant.com>
1 parent 0e28b54 commit 6f53ba6

File tree

1 file changed

+16
-3
lines changed
  • platform-includes/performance/add-spans-example

1 file changed

+16
-3
lines changed

platform-includes/performance/add-spans-example/native.mdx

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,13 +38,26 @@ void perform_checkout() {
3838

3939
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.
4040

41-
By default, transactions will inherit the `trace_id` and `parent_span_id` from the `propagation_context` as generated during SDK initialization. These values can be overridden by calling `sentry_set_trace()`, for example from a downstream SDK or to define a manual trace boundary:
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()`:
4243

4344
```c
44-
// Set the trace propagation_context which will be used
45-
// for all events and transactions/spans
45+
// Upon init, generates a random trace_id and span_id in the propagation_context
46+
sentry_options_t *options = sentry_options_new();
47+
sentry_init(options);
48+
// Events, transactions and spans will inherit the trace data from this propagation_context
49+
initialize_store();
50+
51+
// trace_id and parent_span_id usually originate from a downstream SDK
52+
// (which should be the one calling `sentry_set_trace`)
4653
const char *trace_id = "2674eb52d5874b13b560236d6c79ce8a";
4754
const char *parent_span_id = "a0f9fdf04f1a63df";
4855

56+
// Set the trace propagation_context with the given data
4957
sentry_set_trace(trace_id, parent_span_id);
58+
authenticate_user();
59+
60+
// Generates a new random trace and span id onto the propagation_context
61+
sentry_regenerate_trace();
62+
perform_checkout();
5063
```

0 commit comments

Comments
 (0)