Skip to content

Commit

Permalink
Change EnvelopeItem dataFactory to FutureOr (#2444)
Browse files Browse the repository at this point in the history
  • Loading branch information
vaind authored Nov 25, 2024
1 parent 5b905e0 commit aecac7d
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 9 deletions.
3 changes: 2 additions & 1 deletion dart/lib/src/sentry_envelope.dart
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,8 @@ class SentryEnvelope {
final newLineData = utf8.encode('\n');
for (final item in items) {
try {
final data = await item.dataFactory();
final dataFuture = item.dataFactory();
final data = dataFuture is Future ? await dataFuture : dataFuture;

// Only attachments should be filtered according to
// SentryOptions.maxAttachmentSize
Expand Down
14 changes: 7 additions & 7 deletions dart/lib/src/sentry_envelope_item.dart
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ class SentryEnvelopeItem {
contentType: 'application/json',
);
return SentryEnvelopeItem(
header, () async => utf8JsonEncoder.convert(transaction.toJson()),
header, () => utf8JsonEncoder.convert(transaction.toJson()),
originalObject: transaction);
}

Expand All @@ -37,15 +37,15 @@ class SentryEnvelopeItem {
);
return SentryEnvelopeItem(
header,
() async => attachment.bytes,
() => attachment.bytes,
originalObject: attachment,
);
}

/// Create a [SentryEnvelopeItem] which sends [SentryUserFeedback].
@Deprecated('Will be removed in a future version.')
factory SentryEnvelopeItem.fromUserFeedback(SentryUserFeedback feedback) {
final dataFactory = () async => utf8JsonEncoder.convert(feedback.toJson());
final dataFactory = () => utf8JsonEncoder.convert(feedback.toJson());

final header = SentryEnvelopeItemHeader(
SentryItemType.userFeedback,
Expand All @@ -65,7 +65,7 @@ class SentryEnvelopeItem {
event.type == 'feedback' ? 'feedback' : SentryItemType.event,
contentType: 'application/json',
),
() async => utf8JsonEncoder.convert(event.toJson()),
() => utf8JsonEncoder.convert(event.toJson()),
originalObject: event,
);
}
Expand All @@ -77,14 +77,14 @@ class SentryEnvelopeItem {
SentryItemType.clientReport,
contentType: 'application/json',
),
() async => utf8JsonEncoder.convert(clientReport.toJson()),
() => utf8JsonEncoder.convert(clientReport.toJson()),
originalObject: clientReport,
);
}

/// Creates a [SentryEnvelopeItem] which holds several [Metric] data.
factory SentryEnvelopeItem.fromMetrics(Map<int, Iterable<Metric>> buckets) {
final dataFactory = () async {
final dataFactory = () {
final statsd = StringBuffer();
// Encode all metrics of a bucket in statsd format, using the bucket key,
// which is the timestamp of the bucket.
Expand All @@ -110,5 +110,5 @@ class SentryEnvelopeItem {
final SentryEnvelopeItemHeader header;

/// Create binary data representation of item data.
final Future<List<int>> Function() dataFactory;
final FutureOr<List<int>> Function() dataFactory;
}
2 changes: 1 addition & 1 deletion flutter/lib/src/profiling.dart
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,6 @@ class SentryNativeProfileInfo implements SentryProfileInfo {
SentryItemType.profile,
contentType: 'application/json',
);
return SentryEnvelopeItem(header, () => Future.value(_data));
return SentryEnvelopeItem(header, () => _data);
}
}

0 comments on commit aecac7d

Please sign in to comment.