SentryEnvelope.fromEvent constructor

SentryEnvelope.fromEvent(
  1. SentryEvent event,
  2. SdkVersion sdkVersion, {
  3. String? dsn,
  4. SentryTraceContextHeader? traceContext,
  5. List<SentryAttachment>? attachments,
})

Create a SentryEnvelope containing one SentryEnvelopeItem which holds the SentryEvent data.

Implementation

factory SentryEnvelope.fromEvent(
  SentryEvent event,
  SdkVersion sdkVersion, {
  String? dsn,
  SentryTraceContextHeader? traceContext,
  List<SentryAttachment>? attachments,
}) {
  bool containsUnhandledException = false;

  if (event.exceptions != null && event.exceptions!.isNotEmpty) {
    // Check all exceptions for any unhandled ones
    containsUnhandledException = event.exceptions!.any((exception) {
      return exception.mechanism?.handled == false;
    });
  }

  return SentryEnvelope(
    SentryEnvelopeHeader(
      event.eventId,
      sdkVersion,
      dsn: dsn,
      traceContext: traceContext,
    ),
    [
      SentryEnvelopeItem.fromEvent(event),
      if (attachments != null)
        ...attachments.map((e) => SentryEnvelopeItem.fromAttachment(e))
    ],
    containsUnhandledException: containsUnhandledException,
  );
}