Skip to content

Commit

Permalink
fix API breakage
Browse files Browse the repository at this point in the history
  • Loading branch information
vaind committed Aug 26, 2023
1 parent f50a5df commit b15fbd1
Show file tree
Hide file tree
Showing 11 changed files with 28 additions and 32 deletions.
2 changes: 0 additions & 2 deletions dart/lib/src/hub.dart
Original file line number Diff line number Diff line change
Expand Up @@ -502,7 +502,6 @@ class Hub {
Future<SentryId> captureTransaction(
SentryTransaction transaction, {
SentryTraceContextHeader? traceContext,
ProfileInfo? profileInfo,
}) async {
var sentryId = SentryId.empty();

Expand Down Expand Up @@ -539,7 +538,6 @@ class Hub {
transaction,
scope: item.scope,
traceContext: traceContext,
profileInfo: profileInfo,
);
} catch (exception, stackTrace) {
_options.logger(
Expand Down
3 changes: 1 addition & 2 deletions dart/lib/src/hub_adapter.dart
Original file line number Diff line number Diff line change
Expand Up @@ -98,8 +98,7 @@ class HubAdapter implements Hub {
@override
Future<SentryId> captureTransaction(
SentryTransaction transaction, {
SentryTraceContextHeader? traceContext,
ProfileInfo? profileInfo,
SentryTraceContextHeader? traceContext
}) =>
Sentry.currentHub.captureTransaction(
transaction,
Expand Down
1 change: 0 additions & 1 deletion dart/lib/src/noop_hub.dart
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,6 @@ class NoOpHub implements Hub {
Future<SentryId> captureTransaction(
SentryTransaction transaction, {
SentryTraceContextHeader? traceContext,
ProfileInfo? profileInfo,
}) async =>
SentryId.empty();

Expand Down
30 changes: 15 additions & 15 deletions dart/lib/src/protocol/sentry_transaction.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import 'package:meta/meta.dart';

import '../profiling.dart';
import '../protocol.dart';
import '../sentry_tracer.dart';
import '../utils.dart';
Expand All @@ -11,12 +10,13 @@ class SentryTransaction extends SentryEvent {
late final DateTime startTimestamp;
static const String _type = 'transaction';
late final List<SentrySpan> spans;
final SentryTracer _tracer;
@internal
final SentryTracer tracer;
late final Map<String, SentryMeasurement> measurements;
late final SentryTransactionInfo? transactionInfo;

SentryTransaction(
this._tracer, {
this.tracer, {
SentryId? eventId,
DateTime? timestamp,
String? platform,
Expand All @@ -40,37 +40,37 @@ class SentryTransaction extends SentryEvent {
SentryTransactionInfo? transactionInfo,
}) : super(
eventId: eventId,
timestamp: timestamp ?? _tracer.endTimestamp,
timestamp: timestamp ?? tracer.endTimestamp,
platform: platform,
serverName: serverName,
release: release,
dist: dist,
environment: environment,
transaction: transaction ?? _tracer.name,
throwable: throwable ?? _tracer.throwable,
tags: tags ?? _tracer.tags,
transaction: transaction ?? tracer.name,
throwable: throwable ?? tracer.throwable,
tags: tags ?? tracer.tags,
// ignore: deprecated_member_use_from_same_package
extra: extra ?? _tracer.data,
extra: extra ?? tracer.data,
user: user,
contexts: contexts,
breadcrumbs: breadcrumbs,
sdk: sdk,
request: request,
type: _type,
) {
startTimestamp = _tracer.startTimestamp;
startTimestamp = tracer.startTimestamp;

final spanContext = _tracer.context;
spans = _tracer.children;
final spanContext = tracer.context;
spans = tracer.children;
this.measurements = measurements ?? {};

this.contexts.trace = spanContext.toTraceContext(
sampled: _tracer.samplingDecision?.sampled,
status: _tracer.status,
sampled: tracer.samplingDecision?.sampled,
status: tracer.status,
);

this.transactionInfo = transactionInfo ??
SentryTransactionInfo(_tracer.transactionNameSource.name);
SentryTransactionInfo(tracer.transactionNameSource.name);
}

@override
Expand Down Expand Up @@ -137,7 +137,7 @@ class SentryTransaction extends SentryEvent {
SentryTransactionInfo? transactionInfo,
}) =>
SentryTransaction(
_tracer,
tracer,
eventId: eventId ?? this.eventId,
timestamp: timestamp ?? this.timestamp,
platform: platform ?? this.platform,
Expand Down
4 changes: 2 additions & 2 deletions dart/lib/src/sentry_client.dart
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import 'dart:async';
import 'dart:math';
import 'package:meta/meta.dart';
import 'profiling.dart';
import 'sentry_attachment/sentry_attachment.dart';

import 'event_processor.dart';
Expand Down Expand Up @@ -285,7 +284,6 @@ class SentryClient {
SentryTransaction transaction, {
Scope? scope,
SentryTraceContextHeader? traceContext,
ProfileInfo? profileInfo,
}) async {
SentryTransaction? preparedTransaction =
_prepareEvent(transaction) as SentryTransaction;
Expand Down Expand Up @@ -333,6 +331,8 @@ class SentryClient {
traceContext: traceContext,
attachments: attachments,
);

final profileInfo = preparedTransaction.tracer.profileInfo;
if (profileInfo != null) {
envelope.items.add(profileInfo.asEnvelopeItem());

Check warning on line 337 in dart/lib/src/sentry_client.dart

View check run for this annotation

Codecov / codecov/patch

dart/lib/src/sentry_client.dart#L337

Added line #L337 was not covered by tests
}
Expand Down
1 change: 0 additions & 1 deletion dart/lib/src/sentry_envelope_item.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import 'dart:async';
import 'dart:convert';
import 'package:meta/meta.dart';

import 'client_reports/client_report.dart';
import 'protocol.dart';
Expand Down
8 changes: 6 additions & 2 deletions dart/lib/src/sentry_tracer.dart
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,13 @@ class SentryTracer extends ISentrySpan {

SentryTraceContextHeader? _sentryTraceContextHeader;

// Profiler attached to this tracer.
late final Profiler? profiler;

// Resulting profile, after it has been collected. This is later used by
// SentryClient to attach as an envelope item when sending the transaction.
ProfileInfo? profileInfo;

/// If [waitForChildren] is true, this transaction will not finish until all
/// its children are finished.
///
Expand Down Expand Up @@ -141,14 +146,13 @@ class SentryTracer extends ISentrySpan {
final transaction = SentryTransaction(this);
transaction.measurements.addAll(_measurements);

final profileInfo = (status == null || status == SpanStatus.ok())
profileInfo = (status == null || status == SpanStatus.ok())
? await profiler?.finishFor(transaction)
: null;

await _hub.captureTransaction(
transaction,
traceContext: traceContext(),
profileInfo: profileInfo,
);
} finally {
profiler?.dispose();
Expand Down
1 change: 0 additions & 1 deletion dart/test/hub_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import 'package:collection/collection.dart';
import 'package:mockito/mockito.dart';
import 'package:sentry/sentry.dart';
import 'package:sentry/src/client_reports/discard_reason.dart';
import 'package:sentry/src/profiling.dart';
import 'package:sentry/src/sentry_tracer.dart';
import 'package:sentry/src/transport/data_category.dart';
import 'package:test/test.dart';
Expand Down
2 changes: 0 additions & 2 deletions dart/test/mocks/mock_hub.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import 'package:meta/meta.dart';
import 'package:sentry/sentry.dart';
import 'package:sentry/src/profiling.dart';

import '../mocks.dart';
import 'mock_sentry_client.dart';
Expand Down Expand Up @@ -111,7 +110,6 @@ class MockHub with NoSuchMethodProvider implements Hub {
Future<SentryId> captureTransaction(
SentryTransaction transaction, {
SentryTraceContextHeader? traceContext,
ProfileInfo? profileInfo,
}) async {
captureTransactionCalls
.add(CaptureTransactionCall(transaction, traceContext));
Expand Down
2 changes: 0 additions & 2 deletions dart/test/mocks/mock_sentry_client.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import 'package:sentry/sentry.dart';
import 'package:sentry/src/profiling.dart';

import 'no_such_method_provider.dart';

Expand Down Expand Up @@ -85,7 +84,6 @@ class MockSentryClient with NoSuchMethodProvider implements SentryClient {
SentryTransaction transaction, {
Scope? scope,
SentryTraceContextHeader? traceContext,
ProfileInfo? profileInfo,
}) async {
captureTransactionCalls
.add(CaptureTransactionCall(transaction, traceContext));
Expand Down
6 changes: 4 additions & 2 deletions flutter/test/mocks.dart
Original file line number Diff line number Diff line change
Expand Up @@ -269,7 +269,8 @@ class TestMockSentryNative implements SentryNative {
}

@override
Future<dynamic> collectProfile(SentryId traceId, int startTimeNs) {
Future<Map<String, dynamic>?> collectProfile(
SentryId traceId, int startTimeNs) {
numberOfCollectProfileCalls++;
return Future.value(null);
}
Expand Down Expand Up @@ -362,7 +363,8 @@ class MockNativeChannel implements SentryNativeChannel {
}

@override
Future<dynamic> collectProfile(SentryId traceId, int startTimeNs) {
Future<Map<String, dynamic>?> collectProfile(
SentryId traceId, int startTimeNs) {
numberOfCollectProfileCalls++;
return Future.value(null);
}
Expand Down

0 comments on commit b15fbd1

Please sign in to comment.