captureEvent method

Future<SentryId> captureEvent(
  1. SentryEvent event, {
  2. dynamic stackTrace,
  3. Hint? hint,
  4. ScopeCallback? withScope,
})

Captures the event.

Implementation

Future<SentryId> captureEvent(
  SentryEvent event, {
  dynamic stackTrace,
  Hint? hint,
  ScopeCallback? withScope,
}) async {
  var sentryId = SentryId.empty();

  if (!_isEnabled) {
    _options.logger(
      SentryLevel.warning,
      "Instance is disabled and this 'captureEvent' call is a no-op.",
    );
  } else {
    final item = _peek();
    late Scope scope;
    final s = _cloneAndRunWithScope(item.scope, withScope);
    if (s is Future<Scope>) {
      scope = await s;
    } else {
      scope = s;
    }

    try {
      if (_options.isTracingEnabled()) {
        event = _assignTraceContext(event);
      }

      sentryId = await item.client.captureEvent(
        event,
        stackTrace: stackTrace,
        scope: scope,
        hint: hint,
      );
    } catch (exception, stackTrace) {
      _options.logger(
        SentryLevel.error,
        'Error while capturing event with id: ${event.eventId}',
        exception: exception,
        stackTrace: stackTrace,
      );
    } finally {
      _lastEventId = sentryId;
    }
  }
  return sentryId;
}