Cloud

Sentry Logging Service

SentryLoggingService

  • Implements LoggingService.
  • Provides methods which implements sentry services for event, exception, and transaction.

Configuration

  • To configure sentry for your project you just have to pass sentryConfig in environment config.
    • You will have to add sentry dsn in sentryConfig.
    • And you can configure SampleRate to trace uncaught errors. Value of tracesSampleRate (in sentryConfig) can be between 0 and 1. if value of tracesSampleRate is 0.4 then it will record 40% of uncaught errors, if it's 1 it will record 100% of uncaught errors.
  • Check this video for, how to get config values.
  • Check this also for other sentry integration (PERFORMANCE).

Source code

import 'package:sentry_flutter/sentry_flutter.dart';

import './logging_service.dart';
import '../models/log.dart';

abstract class SentryLoggingService implements LoggingService {
  static logEvent({
    required String message,
    SentryLevel? level,
    Object? data,
  }) {
    final SentryEvent event = SentryEvent(message: SentryMessage(message), level: level);
    Sentry.captureEvent(
      event,
      hint: data == null ? null : Hint.withMap({'data': data}),
    );
  }

  static logException(
    dynamic throwable, {
    dynamic stackTrace,
    dynamic hint,
  }) {
    Sentry.captureException(throwable, stackTrace: stackTrace, hint: hint);
  }

  static logTransaction({
    required Function execute,
    required TransactionDetails details,
  }) async {
    final ISentrySpan transaction = Sentry.startTransaction(details.name, details.operation);
    await execute();
    await transaction.finish();
  }
}

Copyright © 2024