opencensus-python
opencensus-python copied to clipboard
How to log custom operation id in application insights using open census with Python
import logging
from opencensus.ext.azure.log_exporter import AzureLogHandler from opencensus.ext.azure.trace_exporter import AzureExporter from opencensus.trace import config_integration from opencensus.trace.samplers import ProbabilitySampler from opencensus.trace.tracer import Tracer
config_integration.trace_integrations(['logging'])
logger = logging.getLogger(name)
handler = AzureLogHandler(connection_string='InstrumentationKey=<your-instrumentation_key-here>') handler.setFormatter(logging.Formatter('%(traceId)s %(spanId)s %(message)s')) logger.addHandler(handler)
tracer = Tracer( exporter=AzureExporter(connection_string='InstrumentationKey=<your-instrumentation_key-here>'), sampler=ProbabilitySampler(1.0) )
logger.warning('Before the span') with tracer.span(name='test'): logger.warning('In the span') logger.warning('After the span')
Steps to reproduce. I am not getting as how should i change the operation id, trace Id, span Id here
What is the expected behavior? I should be able to log error with custom operationid
What is the actual behavior? Opertion Id not getting logged
@Chetas1
I am unclear at what the issue is you are describing. Are you trying to log operation_id? There is no operation_id in the code snippet you posted.
@Chetas1 Do you still have an issue with this? If not, this issue will be closed.