Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixing logging in tracing.py #628

Merged
merged 1 commit into from
Feb 15, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 8 additions & 9 deletions iib/common/tracing.py
Original file line number Diff line number Diff line change
Expand Up @@ -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')))
Expand Down
Loading