Package: jaeger-logger-reporter
Jaeger Logger ReporterThis packages enables a way to log your span in a simple way. It provides aLoggerReporterwith some configurations. But enables a way to create custom logger reporters.It extends thejaeger-clientpackages, change the configuration in a way it's possible use customer logger reporters.InstallationRunning the following command:$ pip install jaeger-logger-reporterUsageIt's very similar to thejaeger-client, the only difference will be the configuration.importtimeimportloggingimportsysfromjaeger_logger_reporterimportLoggerTraceConfig,LoggerTracerReporterif__name__=="__main__":config=LoggerTraceConfig(config={'sampler':{'type':'const','param':1,},'local_agent':{'reporting_host':'localhost','reporting_port':'5775',},'logging':True,'max_tag_value_length':sys.maxsize},service_name='test',validate=True,)# setup my logger (optional)tracer_logger=logging.getLogger('my.logger')tracer_logger.setLevel(logging.DEBUG)handler=logging.StreamHandler()formatter=logging.Formatter('[%(levelname)s][%(date)s]%(name)s%(span)s%(event)s%(message)s')handler.setFormatter(formatter)handler.setLevel(logging.DEBUG)tracer_logger.addHandler(handler)# define the logger to use, by default LoggerTracerReporter but can be changed.tracer=config.initialize_tracer(logger_reporter=LoggerTracerReporter(logger=tracer_logger))withtracer.start_span('TestSpan')asspan:span.log_kv({'event':'test message','life':42})withtracer.start_span('ChildSpan',child_of=span)aschild_span:child_span.log_kv({'event':'down below'})# yield to IOLoop to flush the spans - https://github.com/jaegertracing/jaeger-client-python/issues/50time.sleep(2)tracer.close()# flush any buffered spansIt will produce a logger output similar to:2020-10-13T22:37:02.538850
[INFO][2020-10-13T22:37:02.538850] my.logger [TestSpan] STARTED
INFO:my.logger:
2020-10-13T22:37:02.538918
[INFO][2020-10-13T22:37:02.538918] my.logger [TestSpan][ChildSpan] STARTED
INFO:my.logger:
2020-10-13T22:37:02.538924
[DEBUG][2020-10-13T22:37:02.538924] my.logger [TestSpan][ChildSpan] LOG down below
DEBUG:my.logger:down below
2020-10-13T22:37:02.538940
[INFO][2020-10-13T22:37:02.538940] my.logger [TestSpan][ChildSpan] FINISHED  2.2172927856445312e-05s
INFO:my.logger: 2.2172927856445312e-05s
2020-10-13T22:37:02.538887
[DEBUG][2020-10-13T22:37:02.538887] my.logger [TestSpan] LOG test message 42
DEBUG:my.logger:test message 42
2020-10-13T22:37:02.538985
[INFO][2020-10-13T22:37:02.538985] my.logger [TestSpan] FINISHED  0.00013494491577148438s
INFO:my.logger: 0.00013494491577148438sLoggerTracerReporterLoggerTracerReporterhave some configurations.Span identifierBy default the span it's identifier byoperation_nameeg:[get_user]But can be changed:defspan_identifier(span):returnf'**{span}**'...tracer=config.initialize_tracer(logger=LoggerTracerReporter(span_identifier=span_identifier))And the output will be something like:**79408c731416c394:55150307c2aa6ca8:0:1 test.TestSpan**Note: if the span has a parent the parent identifier will be display before the span identifier:[parent_id][span_id]Logger formatterThe logger follows this formatter:'%(levelname)s][%(date)s]%(name)s%(span)s%(event)s%(message)s'Where:levelnameis the log level of message;dateis the time of event;nameis the logger name;spanis the span identifier;eventis the span eventmessageis the message of the logThe logger can be overrider onLoggerTracerReporterinstaciation.Span life cycleDefined tagsThere are some Tags keys defined. Can be used to improve the log quality:LOG_HTTP_METHODLOG_HTTP_URLLOG_HTTP_STATUS_CODELOG_SPAN_ERRORLOG_SPAN_HTML_DATALOG_SPAN_HTML_RESPONSELOG_SPAN_SERIALIZER_RESPONSEEventsThere's some different events types:STARTEDIdentify the start of the event. It will show:dateof the begin of the spanLOG_HTTP_METHODandLOG_HTTP_URLif exist, as amessageTAGRepresent a value of a span tag(log_level = DEBUG)LOGRepresent a value of alog_kv(log_level = DEBUG)`FINISHEDIdentify the end of the event. It will show:dateof the end of the spanLOG_HTTP_STATUS_CODEif exist, and the duration fo the span as amessage