Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# Changelog

## Unreleased

### Features

- Tag all spans with thread info ([#3101](https://github.com/getsentry/sentry-dart/pull/3101))

## 9.6.0

Note: this release might require updating your Android Gradle Plugin version to at least `8.1.4`.
Expand Down
16 changes: 0 additions & 16 deletions dart/lib/src/hub.dart
Original file line number Diff line number Diff line change
Expand Up @@ -650,22 +650,6 @@ class Hub {

SentryProfilerFactory? _profilerFactory;

@internal
Map<Type, List<Function>> get lifecycleCallbacks =>
_peek().client.lifeCycleRegistry.lifecycleCallbacks;

@internal
void registerSdkLifecycleCallback<T extends SdkLifecycleEvent>(
SdkLifecycleCallback<T> callback) {
_peek().client.lifeCycleRegistry.registerCallback<T>(callback);
}

@internal
void removeSdkLifecycleCallback<T extends SdkLifecycleEvent>(
SdkLifecycleCallback<T> callback) {
_peek().client.lifeCycleRegistry.removeCallback<T>(callback);
}

SentryEvent _assignTraceContext(SentryEvent event) {
// assign trace context
if (event.throwable != null && event.contexts.trace == null) {
Expand Down
17 changes: 0 additions & 17 deletions dart/lib/src/hub_adapter.dart
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import 'profiling.dart';
import 'protocol.dart';
import 'protocol/sentry_feedback.dart';
import 'scope.dart';
import 'sdk_lifecycle_hooks.dart';
import 'sentry.dart';
import 'sentry_client.dart';
import 'sentry_options.dart';
Expand Down Expand Up @@ -200,20 +199,4 @@ class HubAdapter implements Hub {

@override
FutureOr<void> captureLog(SentryLog log) => Sentry.currentHub.captureLog(log);

@override
Map<Type, List<Function>> get lifecycleCallbacks =>
Sentry.currentHub.lifecycleCallbacks;

@override
void registerSdkLifecycleCallback<T extends SdkLifecycleEvent>(
SdkLifecycleCallback<T> callback) {
Sentry.currentHub.registerSdkLifecycleCallback(callback);
}

@override
void removeSdkLifecycleCallback<T extends SdkLifecycleEvent>(
SdkLifecycleCallback<T> callback) {
Sentry.currentHub.removeSdkLifecycleCallback(callback);
}
}
2 changes: 1 addition & 1 deletion dart/lib/src/logs_enricher_integration.dart
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ class LogsEnricherIntegration extends Integration<SentryOptions> {
@override
FutureOr<void> call(Hub hub, SentryOptions options) {
if (options.enableLogs) {
hub.registerSdkLifecycleCallback<OnBeforeCaptureLog>(
options.lifecycleRegistry.registerCallback<OnBeforeCaptureLog>(
(event) async {
final os = getSentryOperatingSystem();

Expand Down
12 changes: 0 additions & 12 deletions dart/lib/src/noop_hub.dart
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import 'profiling.dart';
import 'protocol.dart';
import 'protocol/sentry_feedback.dart';
import 'scope.dart';
import 'sdk_lifecycle_hooks.dart';
import 'sentry_client.dart';
import 'sentry_options.dart';
import 'tracing.dart';
Expand Down Expand Up @@ -145,15 +144,4 @@ class NoOpHub implements Hub {

@override
Scope get scope => Scope(_options);

@override
Map<Type, List<Function>> get lifecycleCallbacks => {};

@override
void registerSdkLifecycleCallback<T extends SdkLifecycleEvent>(
SdkLifecycleCallback<T> callback) {}

@override
void removeSdkLifecycleCallback<T extends SdkLifecycleEvent>(
SdkLifecycleCallback<T> callback) {}
}
7 changes: 0 additions & 7 deletions dart/lib/src/noop_sentry_client.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,8 @@ import 'hint.dart';
import 'protocol.dart';
import 'protocol/sentry_feedback.dart';
import 'scope.dart';
import 'sdk_lifecycle_hooks.dart';
import 'sentry_client.dart';
import 'sentry_envelope.dart';
import 'sentry_options.dart';
import 'sentry_trace_context_header.dart';

class NoOpSentryClient implements SentryClient {
Expand Down Expand Up @@ -71,9 +69,4 @@ class NoOpSentryClient implements SentryClient {

@override
FutureOr<void> captureLog(SentryLog log, {Scope? scope}) async {}

final _lifeCycleRegistry = SdkLifecycleRegistry(SentryOptions.empty());

@override
SdkLifecycleRegistry get lifeCycleRegistry => _lifeCycleRegistry;
}
8 changes: 8 additions & 0 deletions dart/lib/src/sdk_lifecycle_hooks.dart
Original file line number Diff line number Diff line change
Expand Up @@ -71,3 +71,11 @@ class OnBeforeSendEvent extends SdkLifecycleEvent {
final SentryEvent event;
final Hint hint;
}

/// Dispatched when a sampled span is started.
@internal
class OnSpanStart extends SdkLifecycleEvent {
OnSpanStart(this.span);

final ISentrySpan span;
}
14 changes: 3 additions & 11 deletions dart/lib/src/sentry_client.dart
Original file line number Diff line number Diff line change
Expand Up @@ -46,12 +46,6 @@ class SentryClient {

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

late final SdkLifecycleRegistry _lifecycleRegistry;

/// Allows registration and dispatching of callbacks outside of SentryClient
@internal
SdkLifecycleRegistry get lifeCycleRegistry => _lifecycleRegistry;

SentryExceptionFactory get _exceptionFactory => _options.exceptionFactory;
SentryStackTraceFactory get _stackTraceFactory => _options.stackTraceFactory;

Expand Down Expand Up @@ -89,9 +83,7 @@ class SentryClient {

/// Instantiates a client using [SentryOptions]
SentryClient._(this._options)
: _random = _options.sampleRate == null ? null : Random() {
_lifecycleRegistry = SdkLifecycleRegistry(_options);
}
: _random = _options.sampleRate == null ? null : Random();

/// Reports an [event] to Sentry.io.
Future<SentryId> captureEvent(
Expand Down Expand Up @@ -172,7 +164,7 @@ class SentryClient {
}

// Event is fully processed and ready to be sent
await _lifecycleRegistry
await _options.lifecycleRegistry
.dispatchCallback(OnBeforeSendEvent(preparedEvent, hint));

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

if (processedLog != null) {
await _lifecycleRegistry
await _options.lifecycleRegistry
.dispatchCallback(OnBeforeCaptureLog(processedLog));
_options.logBatcher.addLog(processedLog);
} else {
Expand Down
3 changes: 3 additions & 0 deletions dart/lib/src/sentry_options.dart
Original file line number Diff line number Diff line change
Expand Up @@ -412,6 +412,9 @@ class SentryOptions {
@internal
late ClientReportRecorder recorder = NoOpClientReportRecorder();

@internal
late SdkLifecycleRegistry lifecycleRegistry = SdkLifecycleRegistry(this);

/// List of strings/regex controlling to which outgoing requests
/// the SDK will attach tracing headers.
///
Expand Down
6 changes: 6 additions & 0 deletions dart/lib/src/sentry_tracer.dart
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ class SentryTracer extends ISentrySpan {
collector.onSpanStarted(_rootSpan);
}
}
_dispatchOnSpanStart(_rootSpan);
}

@override
Expand Down Expand Up @@ -271,6 +272,7 @@ class SentryTracer extends ISentrySpan {
collector.onSpanStarted(child);
}
}
_dispatchOnSpanStart(child);

return child;
}
Expand Down Expand Up @@ -435,4 +437,8 @@ class SentryTracer extends ISentrySpan {
});
}
}

void _dispatchOnSpanStart(ISentrySpan span) {
_hub.options.lifecycleRegistry.dispatchCallback(OnSpanStart(span));
}
}
5 changes: 5 additions & 0 deletions dart/lib/src/span_data_convention.dart
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,10 @@ class SpanDataConvention {
static const frozenFrames = 'frames.frozen';
static const framesDelay = 'frames.delay';

// Thread/Isolate data keys according to Sentry span data conventions
// https://develop.sentry.dev/sdk/telemetry/traces/span-data-conventions/#thread
static const threadId = 'thread.id';
static const threadName = 'thread.name';

// TODO: eventually add other data keys here as well
}
6 changes: 4 additions & 2 deletions dart/test/sentry_client_lifecycle_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,8 @@ void main() {
final client = fixture.getSut();
fixture.options.logBatcher = MockLogBatcher();

client.lifeCycleRegistry.registerCallback<OnBeforeCaptureLog>((event) {
fixture.options.lifecycleRegistry
.registerCallback<OnBeforeCaptureLog>((event) {
event.log.attributes['test'] =
SentryLogAttribute.string('test-value');
});
Expand Down Expand Up @@ -74,7 +75,8 @@ void main() {
final client = fixture.getSut();
fixture.options.logBatcher = MockLogBatcher();

client.lifeCycleRegistry.registerCallback<OnBeforeSendEvent>((event) {
fixture.options.lifecycleRegistry
.registerCallback<OnBeforeSendEvent>((event) {
event.event.release = '999';
});

Expand Down
6 changes: 4 additions & 2 deletions dart/test/sentry_client_sdk_lifecycle_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,8 @@ void main() {
final client = fixture.getSut();
fixture.options.logBatcher = MockLogBatcher();

client.lifeCycleRegistry.registerCallback<OnBeforeCaptureLog>((event) {
fixture.options.lifecycleRegistry
.registerCallback<OnBeforeCaptureLog>((event) {
event.log.attributes['test'] =
SentryLogAttribute.string('test-value');
});
Expand Down Expand Up @@ -74,7 +75,8 @@ void main() {
final client = fixture.getSut();
fixture.options.logBatcher = MockLogBatcher();

client.lifeCycleRegistry.registerCallback<OnBeforeSendEvent>((event) {
fixture.options.lifecycleRegistry
.registerCallback<OnBeforeSendEvent>((event) {
event.event.release = '999';
});

Expand Down
3 changes: 2 additions & 1 deletion dart/test/sentry_client_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2007,7 +2007,8 @@ void main() {
final client = fixture.getSut();
fixture.options.logBatcher = MockLogBatcher();

client.lifeCycleRegistry.registerCallback<OnBeforeCaptureLog>((event) {
fixture.options.lifecycleRegistry
.registerCallback<OnBeforeCaptureLog>((event) {
event.log.attributes['test'] = SentryLogAttribute.string('test-value');
});

Expand Down
Loading
Loading