Package: taylor-instrument
taylor-instrument serviceA service based onPip.Services toolkitthat collect logs and metrics by Elasticsearch and Prometheus.Quick links:pip-services3-commonspip-services3-componentspip-services3-rpcpip-services3-prometheuspip-services3-elasticsearchDocumentationUseInstall the Python package aspipinstalltaylor-instrumentConfigure environment variables:INSTRUMENTATION_PORT - port number for instrument service (default: 8082)CORRELATION_ID - correlation id of the serviceELASTICSEARCH_ENABLED - enable ElasticSearch loggerELASTICSEARCH_INFO - loge level (default: info)ELASTICSEARCH_SOURCE - source (context) nameELASTICSEARCH_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 metricsPROMETHEUS_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:frompip_services3_commons.errorsimportApplicationExceptionfrompip_services3_components.logimportLogLevelfromtaylor_instrumentimportinstrument,logger,counters# Configure instrumentfromtaylor_instrument.metricsimportmetricsinstrument.set_correlation_id_from_file('./component.json')instrument.logger.set_level(LogLevel.Debug)definfo_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:raiseFileNotFoundError('My exception1')exceptExceptionase:logger.error(ApplicationException().with_cause(e),'my error message')logger.info('my custom correlation id',None,'Info')try:raiseIOError('My exception2')exceptExceptionase:logger.fatal(ApplicationException().with_cause(e),'Fatal exception')timing.end_timing()@metrics('my-custom-optional-name')definfo_service_2():logger.info('Using decorator metrics%s','Info')info_service()info_service_2()The loggers have next signatures:deflog(self,level:LogLevel,error:ApplicationException,message:str,*args,correlation_id:Optional[str]=None,**kwargs):...deffatal(self,error:ApplicationException,message:str,*args,correlation_id:Optional[str]=None,**kwargs):...deferror(self,error:ApplicationException,message:str,*args,correlation_id:Optional[str]=None,**kwargs):...defwarn(self,message:str,*args,correlation_id:Optional[str]=None,**kwargs):...definfo(self,message:str,*args,correlation_id:Optional[str]=None,**kwargs):...defdebug(self,message:str,*args,correlation_id:Optional[str]=None,**kwargs):...deftrace(self,message:str,*args,correlation_id:Optional[str]=None,**kwargs):...SeeCustomCompositeLogger