Skip to content

Commit 7cfbbd6

Browse files
authored
Tag all spans with thread info (#3101)
1 parent 1b5be17 commit 7cfbbd6

24 files changed

+654
-243
lines changed

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
# Changelog
22

3+
## Unreleased
4+
5+
### Features
6+
7+
- Tag all spans with thread info ([#3101](https://github.com/getsentry/sentry-dart/pull/3101))
8+
39
## 9.6.0
410

511
Note: this release might require updating your Android Gradle Plugin version to at least `8.1.4`.

dart/lib/src/hub.dart

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -650,22 +650,6 @@ class Hub {
650650

651651
SentryProfilerFactory? _profilerFactory;
652652

653-
@internal
654-
Map<Type, List<Function>> get lifecycleCallbacks =>
655-
_peek().client.lifeCycleRegistry.lifecycleCallbacks;
656-
657-
@internal
658-
void registerSdkLifecycleCallback<T extends SdkLifecycleEvent>(
659-
SdkLifecycleCallback<T> callback) {
660-
_peek().client.lifeCycleRegistry.registerCallback<T>(callback);
661-
}
662-
663-
@internal
664-
void removeSdkLifecycleCallback<T extends SdkLifecycleEvent>(
665-
SdkLifecycleCallback<T> callback) {
666-
_peek().client.lifeCycleRegistry.removeCallback<T>(callback);
667-
}
668-
669653
SentryEvent _assignTraceContext(SentryEvent event) {
670654
// assign trace context
671655
if (event.throwable != null && event.contexts.trace == null) {

dart/lib/src/hub_adapter.dart

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ import 'profiling.dart';
88
import 'protocol.dart';
99
import 'protocol/sentry_feedback.dart';
1010
import 'scope.dart';
11-
import 'sdk_lifecycle_hooks.dart';
1211
import 'sentry.dart';
1312
import 'sentry_client.dart';
1413
import 'sentry_options.dart';
@@ -200,20 +199,4 @@ class HubAdapter implements Hub {
200199

201200
@override
202201
FutureOr<void> captureLog(SentryLog log) => Sentry.currentHub.captureLog(log);
203-
204-
@override
205-
Map<Type, List<Function>> get lifecycleCallbacks =>
206-
Sentry.currentHub.lifecycleCallbacks;
207-
208-
@override
209-
void registerSdkLifecycleCallback<T extends SdkLifecycleEvent>(
210-
SdkLifecycleCallback<T> callback) {
211-
Sentry.currentHub.registerSdkLifecycleCallback(callback);
212-
}
213-
214-
@override
215-
void removeSdkLifecycleCallback<T extends SdkLifecycleEvent>(
216-
SdkLifecycleCallback<T> callback) {
217-
Sentry.currentHub.removeSdkLifecycleCallback(callback);
218-
}
219202
}

dart/lib/src/logs_enricher_integration.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ class LogsEnricherIntegration extends Integration<SentryOptions> {
1515
@override
1616
FutureOr<void> call(Hub hub, SentryOptions options) {
1717
if (options.enableLogs) {
18-
hub.registerSdkLifecycleCallback<OnBeforeCaptureLog>(
18+
options.lifecycleRegistry.registerCallback<OnBeforeCaptureLog>(
1919
(event) async {
2020
final os = getSentryOperatingSystem();
2121

dart/lib/src/noop_hub.dart

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ import 'profiling.dart';
88
import 'protocol.dart';
99
import 'protocol/sentry_feedback.dart';
1010
import 'scope.dart';
11-
import 'sdk_lifecycle_hooks.dart';
1211
import 'sentry_client.dart';
1312
import 'sentry_options.dart';
1413
import 'tracing.dart';
@@ -145,15 +144,4 @@ class NoOpHub implements Hub {
145144

146145
@override
147146
Scope get scope => Scope(_options);
148-
149-
@override
150-
Map<Type, List<Function>> get lifecycleCallbacks => {};
151-
152-
@override
153-
void registerSdkLifecycleCallback<T extends SdkLifecycleEvent>(
154-
SdkLifecycleCallback<T> callback) {}
155-
156-
@override
157-
void removeSdkLifecycleCallback<T extends SdkLifecycleEvent>(
158-
SdkLifecycleCallback<T> callback) {}
159147
}

dart/lib/src/noop_sentry_client.dart

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,8 @@ import 'hint.dart';
44
import 'protocol.dart';
55
import 'protocol/sentry_feedback.dart';
66
import 'scope.dart';
7-
import 'sdk_lifecycle_hooks.dart';
87
import 'sentry_client.dart';
98
import 'sentry_envelope.dart';
10-
import 'sentry_options.dart';
119
import 'sentry_trace_context_header.dart';
1210

1311
class NoOpSentryClient implements SentryClient {
@@ -71,9 +69,4 @@ class NoOpSentryClient implements SentryClient {
7169

7270
@override
7371
FutureOr<void> captureLog(SentryLog log, {Scope? scope}) async {}
74-
75-
final _lifeCycleRegistry = SdkLifecycleRegistry(SentryOptions.empty());
76-
77-
@override
78-
SdkLifecycleRegistry get lifeCycleRegistry => _lifeCycleRegistry;
7972
}

dart/lib/src/sdk_lifecycle_hooks.dart

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,3 +71,11 @@ class OnBeforeSendEvent extends SdkLifecycleEvent {
7171
final SentryEvent event;
7272
final Hint hint;
7373
}
74+
75+
/// Dispatched when a sampled span is started.
76+
@internal
77+
class OnSpanStart extends SdkLifecycleEvent {
78+
OnSpanStart(this.span);
79+
80+
final ISentrySpan span;
81+
}

dart/lib/src/sentry_client.dart

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -46,12 +46,6 @@ class SentryClient {
4646

4747
static final _emptySentryId = Future.value(SentryId.empty());
4848

49-
late final SdkLifecycleRegistry _lifecycleRegistry;
50-
51-
/// Allows registration and dispatching of callbacks outside of SentryClient
52-
@internal
53-
SdkLifecycleRegistry get lifeCycleRegistry => _lifecycleRegistry;
54-
5549
SentryExceptionFactory get _exceptionFactory => _options.exceptionFactory;
5650
SentryStackTraceFactory get _stackTraceFactory => _options.stackTraceFactory;
5751

@@ -89,9 +83,7 @@ class SentryClient {
8983

9084
/// Instantiates a client using [SentryOptions]
9185
SentryClient._(this._options)
92-
: _random = _options.sampleRate == null ? null : Random() {
93-
_lifecycleRegistry = SdkLifecycleRegistry(_options);
94-
}
86+
: _random = _options.sampleRate == null ? null : Random();
9587

9688
/// Reports an [event] to Sentry.io.
9789
Future<SentryId> captureEvent(
@@ -172,7 +164,7 @@ class SentryClient {
172164
}
173165

174166
// Event is fully processed and ready to be sent
175-
await _lifecycleRegistry
167+
await _options.lifecycleRegistry
176168
.dispatchCallback(OnBeforeSendEvent(preparedEvent, hint));
177169

178170
var attachments = List<SentryAttachment>.from(scope?.attachments ?? []);
@@ -579,7 +571,7 @@ class SentryClient {
579571
}
580572

581573
if (processedLog != null) {
582-
await _lifecycleRegistry
574+
await _options.lifecycleRegistry
583575
.dispatchCallback(OnBeforeCaptureLog(processedLog));
584576
_options.logBatcher.addLog(processedLog);
585577
} else {

dart/lib/src/sentry_options.dart

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -412,6 +412,9 @@ class SentryOptions {
412412
@internal
413413
late ClientReportRecorder recorder = NoOpClientReportRecorder();
414414

415+
@internal
416+
late SdkLifecycleRegistry lifecycleRegistry = SdkLifecycleRegistry(this);
417+
415418
/// List of strings/regex controlling to which outgoing requests
416419
/// the SDK will attach tracing headers.
417420
///

dart/lib/src/sentry_tracer.dart

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,7 @@ class SentryTracer extends ISentrySpan {
8888
collector.onSpanStarted(_rootSpan);
8989
}
9090
}
91+
_dispatchOnSpanStart(_rootSpan);
9192
}
9293

9394
@override
@@ -271,6 +272,7 @@ class SentryTracer extends ISentrySpan {
271272
collector.onSpanStarted(child);
272273
}
273274
}
275+
_dispatchOnSpanStart(child);
274276

275277
return child;
276278
}
@@ -435,4 +437,8 @@ class SentryTracer extends ISentrySpan {
435437
});
436438
}
437439
}
440+
441+
void _dispatchOnSpanStart(ISentrySpan span) {
442+
_hub.options.lifecycleRegistry.dispatchCallback(OnSpanStart(span));
443+
}
438444
}

0 commit comments

Comments
 (0)