diff --git a/iib/common/tracing.py b/iib/common/tracing.py index b4531cd0..be5631a6 100644 --- a/iib/common/tracing.py +++ b/iib/common/tracing.py @@ -81,31 +81,30 @@ 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.info('Instrumenting span for %s', span_name) + tracer = trace.get_tracer(__name__) + 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')))