Skip to content

This package provide the interface for a common uses of Diagnostic Tools

License

Notifications You must be signed in to change notification settings

coolosos/diagnostic

Repository files navigation

Table of Contents


Overview

Using diagnostic tools such as Firebase Analytic with Firebase Crashlytics, Sentry, CloudWatch or others or interchanging between them is a common practice in software development. Switching from one sdk to another often causes headaches as they are used or handled in very different ways.

For this purpose there is this development package, it provides an interface for the implementation of the different sdk, favoring the change and/or the use between them.

For the multiple use it is also provided a DiagnosticManager that is in charge of initializing all the Diagnostic of a project and send the events to each one of them.

Translated with DeepL.com (free version)

Getting Started

The first step is to implement the Diagnostic interface for the corresponding diagnostic sdk.

import 'package:complicate_diagnostic_tool/complicate_diagnostic_tool.dart';

final class AwesomeDiagnostic implements Diagnostic {
    const AwesomeDiagnostic({required this.options});

    ...

    ComplicateDiagnosticTool get _diagnostic => ComplicateDiagnosticTool.instance;

    @override
    Future<void> init() async {
      await ComplicateDiagnosticTool.initializeApp(
        options: options.defaultComplicateOptions,
      );
    }

    @override
    FutureOr<void> captureException({required DiagnosticExpection exception}) {
      if (!options.mustCaptureExceptions) return null;

      _diagnostic.captureException( exception,
          stackTrace: stackTrace,
          withScope: (scope) {
            arguments?.forEach((key, value) {
              scope.setTag(key, value);
            });
          },
        );
    }

    @override
    FutureOr<void> sendAnalyticEvent({required DiagnosticAnalyticEvent event}) {
      if (!options.mustSendAnalyticsEvents) return null;

      _diagnostic.logEvent(
        name: event.name,
        parameters: event.parameters,
      );
    }

    @override
    FutureOr<void> sendLogEvent({required DiagnosticLogsEvent event}) {
      if (!options.mustSendLogsEvents) return null;

      _diagnostic.logEvent(
        name: event.name,
        parameters: {
          'category': event.category ?? 'event.track',
          'level': event.level.name,
          ...(event.parameters ?? {}),
          ...(_defaultParameters ?? {}),
        },
      );
    }

}

Once it is initialized, it can be used by instantiating the class and launching the init function before its use through a DiagnosticManager.

DiagnosticManager already has a basic implementation of how it works so that it can be used in the project directly by providing it with a list of Diagnostic. You can also extend the DiagnosticManager if other behavior is desired.

Usage

Once the Diagnostic and/or its DiagnosticManager have been created, the different tools can be used with the same interface, facilitating their use and future changes.

License

MIT © Coolosos

About

This package provide the interface for a common uses of Diagnostic Tools

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages