Skip to content

Commit fbe610c

Browse files
feat(develop/span-first): Add more implementation guidelines and Dart example (#15754)
## DESCRIBE YOUR PR Adds more implementation details to Span First and Dart code example ## 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) ## LEGAL BOILERPLATE <!-- Sentry employees and contractors can delete or ignore this section. --> Look, I get it. The entity doing business as "Sentry" was incorporated in the State of Delaware in 2015 as Functional Software, Inc. and is gonna need some rights from me in order to utilize my contributions in this here PR. So here's the deal: I retain all rights, title and interest in and to my contributions, and by keeping this boilerplate intact I confirm that Sentry can use, modify, copy, and redistribute my contributions, under Sentry's choice of terms. ## EXTRA RESOURCES - [Sentry Docs contributor guide](https://docs.sentry.io/contributing/) --------- Co-authored-by: Ivana Kellyer <ivana.kellyer@sentry.io>
1 parent 6dc6337 commit fbe610c

File tree

2 files changed

+65
-4
lines changed

2 files changed

+65
-4
lines changed

develop-docs/sdk/telemetry/spans/implementation.mdx

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,24 @@ If you're implementing Span-First (as a PoC) in your SDK, take an iterative appr
4848
To do: This section needs a few guidelines and implementation hints, including:
4949
- how to set a span active and remove it from the scope once it ends
5050
- languages having to deal with async context management
51-
- edge cases (e.g. adding a span with an explicit parent span that already ended)
51+
52+
### `parentSpan` option for `startSpan`
53+
54+
SDKs MUST expose a `parentSpan` option on the `startSpan` API which allows users to explicitly set the parent span of the new span.
55+
56+
The `parentSpan` parameter has three distinct states: `undefined`, `null` and a span instance. See the [Span API documentation](../span-api) for the semantics.
57+
58+
For languages that do not support an `undefined` state, SDKs SHOULD model this three-state behavior using platform-appropriate mechanisms.
59+
Prefer solutions that preserve the semantic distinction between `undefined` and `null`, such as:
60+
61+
- method/constructor overloading (e.g., an overload without `parentSpan`, and another accepting `parentSpan: Span?`),
62+
- a default sentinel value/object representing `undefined`,
63+
- or other idiomatic platform mechanisms (e.g., enum types).
64+
65+
### Edge Cases
66+
67+
- If `parentSpan` references a span that has already ended, the SDK SHOULD still create the new span and send it as a child of `parentSpan`.
68+
- Handling and presentation of these relationships is deferred to downstream processing and the frontend/UI.
5269

5370
## Single-Span Processing Pipeline
5471

@@ -119,12 +136,13 @@ Some rough pointers:
119136
- SDKs SHOULD follow one of the backend, mobile or browser telemetry buffer specifications.
120137
- It is expected and fine to implement the proper, weighted buffering logic as a final step in the Span-First project.
121138
Intermediate buffers MAY be simpler, for example disregard the priority logic and just buffer until a certain span length, size or time interval is reached.
139+
122140
## Release
123141

124-
The initial PoC implementation of Span-First **SHOULD** be released in a **minor version** of the SDK.
142+
The initial PoC implementation of Span-First SHOULD be released in a minor version of the SDK.
125143

126-
- This feature is entirely opt-in via `traceLifecycle = 'stream'` and therefore does **not** introduce breaking changes to existing users.
144+
- This feature is entirely opt-in via `traceLifecycle = 'stream'` and therefore does not introduce breaking changes to existing users.
127145
- The default tracing behavior (transaction-based) MUST remain unchanged until Span-First becomes the default in a future major release.
128146
- Release notes and user facing documentation SHOULD clearly describe:
129147
- the availability of Span-First behind the opt-in flag
130-
- any known limitations
148+
- any known limitations

develop-docs/sdk/telemetry/spans/span-api.mdx

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -195,3 +195,46 @@ with sentry_sdk.start_span(name="checkout", attributes={"user.id": "123"}) as ch
195195
log_order()
196196
span.end()
197197
```
198+
199+
```Dart {tabTitle:Dart}
200+
final checkoutSpan = Sentry.startSpan(
201+
'on-checkout-click',
202+
attributes: {
203+
'user.id': SentryAttribute.string('123'),
204+
},
205+
);
206+
207+
final validationSpan = Sentry.startSpan('validate-shopping-cart');
208+
209+
startFormValidation().then((result) {
210+
validationSpan.setAttribute('valid-form-data', SentryAttribute.bool(result.success));
211+
validationSpan.end();
212+
});
213+
214+
final processSpan = Sentry.startSpan(
215+
'process-order',
216+
parentSpan: checkoutSpan,
217+
);
218+
219+
processOrder().then((result) {
220+
processSpan.setAttribute('order-processed', SentryAttribute.bool(result.success));
221+
processSpan.end();
222+
}).catchError((error) {
223+
processSpan.status = SpanV2Status.error;
224+
processSpan.setAttribute('order-processed', SentryAttribute.string('error'));
225+
processSpan.end();
226+
});
227+
228+
final unrelatedSpan = Sentry.startSpan(
229+
'log-order',
230+
parentSpan: null,
231+
);
232+
233+
logOrder();
234+
235+
unrelatedSpan.end();
236+
237+
on('checkout-finished', (timestamp) {
238+
checkoutSpan.end(endTimestamp: timestamp);
239+
});
240+
```

0 commit comments

Comments
 (0)