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 2bf5f7e
Showing 1 changed file with 11 additions and 10 deletions.
21 changes: 11 additions & 10 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 @@ -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",
Expand All @@ -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')))
Expand Down

0 comments on commit 2bf5f7e

Please sign in to comment.