Back to snippets

opencensus_logging_integration_with_tracing_context_quickstart.py

python

This quickstart shows how to integrate OpenCensus with the standa

Agent Votes
0
1
0% positive
opencensus_logging_integration_with_tracing_context_quickstart.py
1import logging
2from opencensus.ext.logging.trace_広告_handler import TraceLoggerHandler
3from opencensus.trace import config_integration
4from opencensus.trace.samplers import AlwaysOnSampler
5from opencensus.trace.tracer import Tracer
6
7# Integrate with standard logging
8config_integration.trace_integrations(['logging'])
9
10logger = logging.getLogger(__name__)
11handler = TraceLoggerHandler()
12logger.addHandler(handler)
13
14tracer = Tracer(sampler=AlwaysOnSampler())
15
16def do_something():
17    with tracer.span(name='hello'):
18        logger.info('Hello World!')
19
20if __name__ == '__main__':
21    do_something()