Skip to content

Commit e51ef37

Browse files
committed
refactor: import encoder from utils-genai
1 parent 48ac64b commit e51ef37

File tree

2 files changed

+2
-12
lines changed

2 files changed

+2
-12
lines changed

instrumentation-genai/opentelemetry-instrumentation-google-genai/src/opentelemetry/instrumentation/google_genai/generate_content.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,13 +57,13 @@
5757
MessagePart,
5858
OutputMessage,
5959
)
60+
from opentelemetry.util.genai.utils import _GenAiJsonEncoder
6061

6162
from .allowlist_util import AllowList
6263
from .custom_semconv import GCP_GENAI_OPERATION_CONFIG
6364
from .dict_util import flatten_dict
6465
from .flags import is_content_recording_enabled
6566
from .message import (
66-
Base64JsonEncoder,
6767
to_input_messages,
6868
to_output_messages,
6969
to_system_instructions,
@@ -316,7 +316,7 @@ def _create_completion_details_attributes(
316316

317317
if as_str:
318318
return {
319-
k: json.dumps(v, cls=Base64JsonEncoder)
319+
k: json.dumps(v, cls=_GenAiJsonEncoder)
320320
for k, v in attributes.items()
321321
}
322322

instrumentation-genai/opentelemetry-instrumentation-google-genai/src/opentelemetry/instrumentation/google_genai/message.py

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,8 @@
1414

1515
from __future__ import annotations
1616

17-
import json
1817
import logging
19-
from base64 import b64encode
2018
from enum import Enum
21-
from typing import Any
2219

2320
from google.genai import types as genai_types
2421

@@ -42,13 +39,6 @@ class Role(str, Enum):
4239
TOOL = "tool"
4340

4441

45-
class Base64JsonEncoder(json.JSONEncoder):
46-
def default(self, o: Any) -> Any:
47-
if isinstance(o, bytes):
48-
return b64encode(o).decode()
49-
return super().default(o)
50-
51-
5242
_logger = logging.getLogger(__name__)
5343

5444

0 commit comments

Comments
 (0)