From 2bf5f7ed50faa50664bffaa9871cc6fc0a60b558 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan=20Lipovsk=C3=BD?= Date: Thu, 1 Feb 2024 16:16:03 +0100 Subject: [PATCH] Fixing logging in tracing.py [CLOUDDST-21024] --- iib/common/tracing.py | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/iib/common/tracing.py b/iib/common/tracing.py index b4531cd05..eb9fcde9c 100644 --- a/iib/common/tracing.py +++ b/iib/common/tracing.py @@ -35,6 +35,7 @@ def func(): log = logging.getLogger(__name__) +log.setLevel(logging.DEBUG) propagator = TraceContextTextMapPropagator() @@ -64,7 +65,7 @@ def __new__(cls): return None if TracingWrapper.__instance is None: - log.info('Creating TracingWrapper instance') + log.debug('Creating TracingWrapper instance') cls.__instance = super().__new__(cls) otlp_exporter = OTLPSpanExporter( endpoint=f"{os.getenv('OTEL_EXPORTER_OTLP_ENDPOINT')}/v1/traces", @@ -81,31 +82,31 @@ def __new__(cls): def instrument_tracing( - func=None, span_name: str = '', attributes: Dict = {}, ): """ Instrument tracing for a function. - :param func: The function to be decorated. :param span_name: The name of the span to be created. :param attributes: The attributes to be added to the span. :return: The decorated function or class. """ - log.info('Instrumenting span for %s', span_name) - tracer = trace.get_tracer(__name__) - context = None - if trace.get_current_span(): - context = trace.get_current_span().get_span_context() - else: - context = propagator.extract(carrier={}) def decorator_instrument_tracing(func): @functools.wraps(func) def wrapper(*args, **kwargs): if not os.getenv('IIB_OTEL_TRACING', '').lower() == 'true': return func(*args, **kwargs) + + log.debug('Instrumenting span for %s', span_name) + tracer = trace.get_tracer(__name__) + log.debug('Tracer: %s', tracer) + if trace.get_current_span(): + context = trace.get_current_span().get_span_context() + else: + context = propagator.extract(carrier={}) + log.debug('Context inside %s: %s', span_name, context) if kwargs.get('traceparent'): log.debug('traceparent is %s' % str(kwargs.get('traceparent')))