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

Fix OTEL issues when dealing with unsupported objects #698

Merged
merged 2 commits into from
Jul 2, 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
8 changes: 7 additions & 1 deletion iib/common/tracing.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ def func():
pass

"""
import json
import os
import functools
import getpass
Expand All @@ -20,6 +21,7 @@ def func():
from typing import Any, Dict


from flask import Response
from opentelemetry import trace
from opentelemetry.trace import SpanKind, Status, StatusCode
from opentelemetry.sdk.resources import Resource, SERVICE_NAME
Expand Down Expand Up @@ -128,9 +130,13 @@ def wrapper(*args, **kwargs):
result = func(*args, **kwargs)
if isinstance(result, dict):
span_result = normalize_data_for_span(result)
elif isinstance(result, tuple) and isinstance(result[0], Response):
response = json.dumps(result[0].json)
code = result[1]
span_result = {'response': response, 'http_code': code}
else:
# If the returned result is not of type dict, create one
span_result = {'result': result or 'success'}
span_result = {'result': str(result) or 'success'}
except Exception as exc:
span.set_status(Status(StatusCode.ERROR))
span.record_exception(exc)
Expand Down