Skip to main content

taylor-instrument service

A service based on Pip.Services toolkit that collect logs and metrics by Elasticsearch and Prometheus.

Quick links:

Use

Install the Python package as

pip install taylor-instrument

Configure environment variables:

  • INSTRUMENTATION_PORT - port number for instrument service (default: 8082)
  • CORRELATION_ID - correlation id of the service
  • ELASTICSEARCH_ENABLED - enable ElasticSearch logger
  • ELASTICSEARCH_INFO - loge level (default: info)
  • ELASTICSEARCH_SOURCE - source (context) name
  • ELASTICSEARCH_PROTOCOL - connection protocol: http or https (default: http)
  • ELASTICSEARCH_SERVICE_HOST - host name or IP address (default: localhost)
  • ELASTICSEARCH_SERVICE_PORT - port number (default: 9200)
  • PROMETHEUS_ENABLED - enable prometheus logs and metrics
  • PROMETHEUS_PROTOCOL - connection protocol: http or https (default: http)
  • PROMETHEUS_SERVICE_HOST - host name or IP address (default: localhost)
  • PROMETHEUS_SERVICE_PORT - port number (default: 9090)
  • PUSHGATEWAY_PROTOCOL - connection protocol: http or https (default: http)
  • PUSHGATEWAY_METRICS_SERVICE_HOST - host name or IP address (default: localhost)
  • PUSHGATEWAY_METRICS_SERVICE_PORT - port number (default: 9091)
  • COUNTERS_INTERVAL - interval in milliseconds to save current counters measurements (default: 5 mins)

For more environment configs see above links.

Then use loggers and metrics in your services:

from pip_services3_commons.errors import ApplicationException
from pip_services3_components.log import LogLevel

from taylor_instrument import instrument, logger, counters
# Configure instrument
from taylor_instrument.metrics import metrics

instrument.set_correlation_id_from_file('./component.json')
instrument.logger.set_level(LogLevel.Debug)


def info_service():
    counters.increment_one('my_service.info.calls')
    timing = counters.begin_timing('my_service.info.exec_time')

    logger.warn(message='warning', correlation_id='my custom correlation id')
    logger.debug('debug')
    logger.trace('Trace')

    try:
        raise FileNotFoundError('My exception1')
    except Exception as e:
        logger.error(ApplicationException().with_cause(e), 'my error message')

    logger.info('my custom correlation id', None, 'Info')

    try:
        raise IOError('My exception2')
    except Exception as e:
        logger.fatal(ApplicationException().with_cause(e), 'Fatal exception')


    timing.end_timing()


@metrics('my-custom-optional-name')
def info_service_2():
    logger.info('Using decorator metrics %s', 'Info')


info_service()
info_service_2()

The loggers have next signatures:

    def log(self, level: LogLevel, error: ApplicationException, message: str, *args,
            correlation_id: Optional[str] = None, **kwargs):
        ...

    def fatal(self, error: ApplicationException, message: str, *args, correlation_id: Optional[str] = None, **kwargs):
        ...

    def error(self, error: ApplicationException, message: str, *args, correlation_id: Optional[str] = None, **kwargs):
        ...

    def warn(self, message: str, *args, correlation_id: Optional[str] = None, **kwargs):
        ...

    def info(self, message: str, *args, correlation_id: Optional[str] = None, **kwargs):
        ...

    def debug(self, message: str, *args, correlation_id: Optional[str] = None, **kwargs):
        ...

    def trace(self, message: str, *args, correlation_id: Optional[str] = None, **kwargs):
        ...

See CustomCompositeLogger

Release files for taylor-instrument 0.0.16

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for taylor-instrument 0.0.16
File Size Uploaded
taylor-instrument-0.0.16.tar.gz 7.2 kB Details

Release files / taylor-instrument-0.0.16.tar.gz

Download URL taylor-instrument-0.0.16.tar.gz
Size 7.2 kB
Tags Source
SHA-256 checksum
How to use checksums
24a7fe521c0882fb08d46790210a295ca6fd231cabe3bda13d67cd0bff0ce287
BLAKE2b-256 checksum
How to use checksums
4ca49fb50c971ffe7d1accadf57c94ebd4a4a8a5273657b58d577271253c6ca8
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.2.0 pkginfo/1.6.1 requests/2.25.1 setuptools/41.2.0 requests-toolbelt/0.9.1 tqdm/4.50.2 CPython/3.8.2

Release history Release notifications | RSS feed

This release

0.0.16 This release

1 release file

0.0.15

1 release file

0.0.14

1 release file

0.0.12

1 release file

0.0.11

1 release file

0.0.10

1 release file

0.0.9

1 release file

0.0.8

1 release file

0.0.7

1 release file

0.0.6

1 release file

0.0.5

1 release file

0.0.4

1 release file

0.0.3

1 release file

0.0.2

1 release file

0.0.1

1 release file

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page