Skip to content

Commit 4280eb9

Browse files
committed
refactor: replace json.dumps with gen_ai_json_dumps for message serialization
1 parent 4044274 commit 4280eb9

File tree

1 file changed

+5
-3
lines changed
  • util/opentelemetry-util-genai/src/opentelemetry/util/genai

1 file changed

+5
-3
lines changed

util/opentelemetry-util-genai/src/opentelemetry/util/genai/span_utils.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
# See the License for the specific language governing permissions and
1313
# limitations under the License.
1414

15-
import json
1615
from dataclasses import asdict
1716
from typing import Any, Dict, List
1817

@@ -34,6 +33,7 @@
3433
)
3534
from opentelemetry.util.genai.utils import (
3635
ContentCapturingMode,
36+
gen_ai_json_dumps,
3737
get_content_capturing_mode,
3838
is_experimental_mode,
3939
)
@@ -95,12 +95,14 @@ def _maybe_set_span_messages(
9595
if input_messages:
9696
span.set_attribute(
9797
GenAI.GEN_AI_INPUT_MESSAGES,
98-
json.dumps([asdict(message) for message in input_messages]),
98+
gen_ai_json_dumps([asdict(message) for message in input_messages]),
9999
)
100100
if output_messages:
101101
span.set_attribute(
102102
GenAI.GEN_AI_OUTPUT_MESSAGES,
103-
json.dumps([asdict(message) for message in output_messages]),
103+
gen_ai_json_dumps(
104+
[asdict(message) for message in output_messages]
105+
),
104106
)
105107

106108

0 commit comments

Comments
 (0)