-
-
Notifications
You must be signed in to change notification settings - Fork 277
[Span First #3]: Add active span parenting behaviour and more api scaffolding #3377
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
Codecov Report❌ Patch coverage is Additional details and impacted files@@ Coverage Diff @@
## feat/span-first #3377 +/- ##
==================================================
Coverage ? 88.64%
==================================================
Files ? 295
Lines ? 10077
Branches ? 0
==================================================
Hits ? 8933
Misses ? 1144
Partials ? 0 ☔ View full report in Codecov by Sentry. |
|
cursor review |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Bug: Scope clear() does not reset active spans list
The Scope.clear() method, intended to reset the scope, doesn't clear the _activeSpans list. This leaves stale spans, leading to incorrect parenting for new spans and inconsistency with other cleared collection fields.
packages/dart/lib/src/scope.dart#L297-L316
sentry-dart/packages/dart/lib/src/scope.dart
Lines 297 to 316 in 144405e
| /// Resets the Scope to its default state | |
| Future<void> clear() async { | |
| clearAttachments(); | |
| level = null; | |
| span = null; | |
| _transaction = null; | |
| _fingerprint = []; | |
| _tags.clear(); | |
| _extra.clear(); | |
| _eventProcessors.clear(); | |
| _replayId = null; | |
| propagationContext = PropagationContext(); | |
| _attributes.clear(); | |
| _clearBreadcrumbsSync(); | |
| _setUserSync(null); | |
| await clearBreadcrumbs(); | |
| await setUser(null); | |
| } |
packages/dart/lib/src/scope.dart#L45-L78
sentry-dart/packages/dart/lib/src/scope.dart
Lines 45 to 78 in 144405e
| final List<Span> _activeSpans = []; | |
| @visibleForTesting | |
| List<Span> get activeSpans => List.unmodifiable(_activeSpans); | |
| /// Returns the currently active span, or `null` if no span is active. | |
| /// | |
| /// The active span is the most recently set span via [setActiveSpan]. | |
| /// When starting a new span with `active: true` (the default), the new span | |
| /// becomes a child of this active span. | |
| @internal | |
| Span? getActiveSpan() { | |
| return _activeSpans.lastOrNull; | |
| } | |
| /// Sets the given [span] as the currently active span. | |
| /// | |
| /// Active spans are used to automatically parent new spans. | |
| /// When a new span is started with `active: true` (the default), it becomes | |
| /// a child of the currently active span. | |
| @internal | |
| void setActiveSpan(Span span) { | |
| _activeSpans.add(span); | |
| } | |
| /// Removes the given [span] from the active spans list. | |
| /// | |
| /// This should be called when a span ends to remove it from the active | |
| /// span hierarchy. | |
| @internal | |
| void removeActiveSpan(Span span) { | |
| _activeSpans.remove(span); | |
| } |
…ove attribute management. Added spanId to SimpleSpan and NoOpSpan, and updated UnsetSpan to throw errors for unimplemented methods. Enhanced tests to verify spanId creation.
- Introduced a test to verify that a finished span can be used as a parent for a new span. - Added a test to ensure that when tracing is disabled, starting a span results in a NoOpSpan and does not affect active spans.
|
cursor review |
…span finalization - Added a check in the `end` method of `SimpleSpan` to prevent multiple calls from altering the end timestamp after the span is finished. - Introduced a new test to verify that calling `end` on an already finished span does not change its state or timestamp. - Updated existing tests to use a consistent method for obtaining the hub instance.
|
cursor review |
…tting isFinished flag
- Removed redundant comment about parent span being null in the Span interface. - Enhanced documentation for the attributes getter to specify the use of Map.unmodifiable. - Cleaned up the hub_span_test by removing an incomplete test case regarding finished spans as parents. - Updated scope_test to include assertions for active spans in the cloned state.
- Updated the end method to convert the endTimestamp to UTC correctly. - Added a test to verify that endTimestamp is set as UTC when the end method is called.
- Modified the test to convert the end timestamp to UTC before passing it to the span's end method, ensuring consistency with the expected behavior.
📜 Description
Span first initiative
💡 Motivation and Context
Part of #3331
💚 How did you test it?
Unit tests
📝 Checklist
sendDefaultPiiis enabled🔮 Next steps
#skip-changelog