Skip to content

Commit

Permalink
Properly parse IIB Responses in OTEL
Browse files Browse the repository at this point in the history
This commit detects a typical IIB API response, which consists of a
tuple with a Flask.Response object and the HTTP code.

Example:

```
def add_bundles() -> Tuple[flask.Response, int]:
    ...
    return flask.jsonify(request.to_json()), 200
```

With this we no longer see the following messages in IIB-API logs:

```
Invalid type Response in attribute 'result' value sequence.
Expected one of ['bool', 'str', 'bytes', 'int', 'float'] or None
```

Refers to CLOUDDST-23028
  • Loading branch information
JAVGan committed Jul 2, 2024
1 parent 36d19fe commit a1cefc2
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions 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,6 +130,10 @@ 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'}
Expand Down

0 comments on commit a1cefc2

Please sign in to comment.