startSpanSync<T> static method
- String name,
- T callback(
- SentrySpanV2 span
- Map<
String, SentryAttribute> ? attributes, - SentrySpanV2? parentSpan = const UnsetSentrySpanV2(),
- DateTime? startTimestamp,
Starts a new span, executes a synchronous callback, and ends the span
before returning the callback result.
The span is set as the active span within the callback's scope via
zones, so any nested startSpan or startSpanSync calls will
automatically parent to it.
If the callback throws, the span's status is set to
SentrySpanStatusV2.error before ending.
Use startSpan when the work is asynchronous.
Both variants can be freely nested — parent-child relationships resolve correctly across sync/async boundaries.
When the span is not sent — due to sampling or ignore rules — the
callback still executes but receives a NoOpSentrySpanV2. All
operations on it (e.g. SentrySpanV2.setAttribute) are safe no-ops.
By default, the span is created as a child of the currently active span.
Pass a SentrySpanV2 as parentSpan to override the parent, or pass
null to create a root span.
Implementation
static T startSpanSync<T>(
String name,
T Function(SentrySpanV2 span) callback, {
Map<String, SentryAttribute>? attributes,
SentrySpanV2? parentSpan = const UnsetSentrySpanV2(),
DateTime? startTimestamp,
}) =>
_hub.startSpanSync(name, callback,
attributes: attributes,
parentSpan: parentSpan,
startTimestamp: startTimestamp);