Skip to content

Commit

Permalink
refactor: change envelope-item data factory to FutureOr
Browse files Browse the repository at this point in the history
  • Loading branch information
vaind committed Nov 25, 2024
1 parent 49cb755 commit a85b3ed
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 10 deletions.
5 changes: 3 additions & 2 deletions 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 All @@ -133,7 +134,7 @@ class SentryEnvelope {
}

yield newLineData;
yield utf8.encode(jsonEncode(await item.header.toJson(data.length)));
yield utf8JsonEncoder.convert(await item.header.toJson(data.length));
yield newLineData;
yield data;
} catch (_) {
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 a85b3ed

Please sign in to comment.