Skip to content

Commit

Permalink
Fixing logging in tracing.py
Browse files Browse the repository at this point in the history
[CLOUDDST-21024]
  • Loading branch information
lipoja committed Feb 7, 2024
1 parent 60d8359 commit 723c5ad
Showing 1 changed file with 9 additions and 9 deletions.
18 changes: 9 additions & 9 deletions iib/common/tracing.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ def func():


log = logging.getLogger(__name__)
log.setLevel(logging.DEBUG)
propagator = TraceContextTextMapPropagator()


Expand Down Expand Up @@ -81,31 +82,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')))
Expand Down

0 comments on commit 723c5ad

Please sign in to comment.