Pip.Services Logo
Observability Component definitions for Dart

This module is a part of the Pip.Services polyglot microservices toolkit.

The Observability module contains observability component definitions that can be used to build applications and services.

The module contains the following packages:

  • Count - performance counters
  • Log - basic logging components that provide console and composite logging, as well as an interface for developing custom loggers
  • Trace - tracing components

Quick links:

Use

Add this to your package's pubspec.yaml file:

dependencies:
  pip_services4_observability: version

Now you can install package from the command line:

pub get

Example how to use Logging and Performance counters. Here we are going to use CompositeLogger and CompositeCounters components. They will pass through calls to loggers and counters that are set in references.

import 'package:pip_services4_components/src/config/ConfigParams.dart';
import 'package:pip_services4_components/src/config/IConfigurable.dart';
import 'package:pip_services4_components/src/refer/IReferences.dart';
import 'package:pip_services4_components/src/refer/IReferenceable.dart';
import 'package:pip_services4_observability/src/log/CompositeLogger.dart';
import 'package:pip_services4_observability/src/count/CompositeCounters.dart';
import 'package:pip_services4_observability/src/count/Timing.dart';


class MyComponent implements IConfigurable, IReferenceable {
  CompositeLogger _logger = CompositeLogger();
  CompositeCounters _counters = CompositeCounters();
  
  configure(ConfigParams config) {
    this._logger.configure(config);
  }
  
  setReferences(IReferences refs) {
    this._logger.setReferences(refs);
    this._counters.setReferences(refs);
  }
  
  myMethod(IContext context, dynamic param1) {
    try{
      this._logger.trace(context, "Executed method mycomponent.mymethod");
      this._counters.increment("mycomponent.mymethod.exec_count", 1);
      Timing timing = this._counters.beginTiming("mycomponent.mymethod.exec_time");
      ....
      timing.endTiming();
    } catch(e) {
      this._logger.error(context, e, "Failed to execute mycomponent.mymethod");
      this._counters.increment("mycomponent.mymethod.error_count", 1);
    }
  }
}

Develop

For development you shall install the following prerequisites:

  • Dart SDK 3
  • Visual Studio Code or another IDE of your choice
  • Docker

Install dependencies:

pub get

Run automated tests:

pub run test

Generate API documentation:

./docgen.ps1

Before committing changes run dockerized build and test as:

./build.ps1
./test.ps1
./clear.ps1

Contacts

The library is created and maintained by Sergey Seroukhov and Levichev Dmitry.

The documentation is written by Egor Nuzhnykh, Alexey Dvoykin, Mark Makarychev, Levichev Dmitry.