Skip to content

Commit 33cf796

Browse files
committed
refactor(span): Simplify span error handling in Hub class
Removed the _endActiveSpan method and integrated its functionality directly into the error handling of startSpan. Now, spans are ended and their status is set to error in the catch block, improving code clarity and reducing redundancy.
1 parent 10a2306 commit 33cf796

File tree

1 file changed

+8
-16
lines changed

1 file changed

+8
-16
lines changed

packages/dart/lib/src/hub.dart

Lines changed: 8 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -673,11 +673,13 @@ class Hub {
673673
() => callback(recordingSpan),
674674
zoneValues: {_scopeKey: forkedScope},
675675
);
676-
_endActiveSpan(recordingSpan, forkedScope);
677676
return result;
678677
} catch (_) {
679-
_endActiveSpan(recordingSpan, forkedScope, isError: true);
678+
span.status = SentrySpanStatusV2.error;
680679
rethrow;
680+
} finally {
681+
span.end();
682+
forkedScope.removeActiveSpan(span);
681683
}
682684
}();
683685
}
@@ -714,11 +716,13 @@ class Hub {
714716
() => callback(recordingSpan),
715717
zoneValues: {_scopeKey: forkedScope},
716718
);
717-
_endActiveSpan(recordingSpan, forkedScope);
718719
return result;
719720
} catch (_) {
720-
_endActiveSpan(recordingSpan, forkedScope, isError: true);
721+
span.status = SentrySpanStatusV2.error;
721722
rethrow;
723+
} finally {
724+
span.end();
725+
forkedScope.removeActiveSpan(span);
722726
}
723727
}
724728
}
@@ -728,18 +732,6 @@ class Hub {
728732
return parentScope.clone()..setActiveSpan(span);
729733
}
730734

731-
void _endActiveSpan(
732-
RecordingSentrySpanV2 span,
733-
Scope forkedScope, {
734-
bool isError = false,
735-
}) {
736-
if (isError) {
737-
span.status = SentrySpanStatusV2.error;
738-
}
739-
span.end();
740-
forkedScope.removeActiveSpan(span);
741-
}
742-
743735
SentrySpanV2 startInactiveSpan(
744736
String name, {
745737
Map<String, SentryAttribute>? attributes,

0 commit comments

Comments
 (0)