OpenCensus日志集成
opencensus-ext-logging的Python项目详细描述
日志集成使用trace id、span id和sampling标志丰富日志记录。 以下属性将添加到LogRecord:
- traceId
- spanId
- traceSampled
注意,这只对集成后创建的记录器生效。
安装
pip install opencensus-ext-logging
用法
importloggingfromopencensus.traceimportconfig_integrationfromopencensus.trace.samplersimportAlwaysOnSamplerfromopencensus.trace.tracerimportTracerconfig_integration.trace_integrations(['logging'])logging.basicConfig(format='%(asctime)s traceId=%(traceId)s spanId=%(spanId)s%(message)s')tracer=Tracer(sampler=AlwaysOnSampler())logger=logging.getLogger(__name__)logger.warning('Before the span')withtracer.span(name='hello'):logger.warning('In the span')logger.warning('After the span')