Skip to content

Commit 123f556

Browse files
authored
Fix a few bugs in opentelemetry-instrumentation-google-genai instrumentation package (#3905)
* Fix a few bugs in gen AI instrumentation * Make a lot of changes * Remove print statements * fix lint issues * remove added folder * Address comments * Move code into helper * Revert change to pyright include
1 parent bd3c1f2 commit 123f556

File tree

9 files changed

+295
-202
lines changed

9 files changed

+295
-202
lines changed

instrumentation-genai/opentelemetry-instrumentation-google-genai/CHANGELOG.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
77

88
## Unreleased
99

10-
- Minor change to check LRU cache in Completion Hook before acquiring semaphore/thread ([#3907](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/3907)).
10+
- Ensure log event is written and completion hook is called even when model call results in exception. Put new
11+
log event (` gen_ai.client.inference.operation.details`) behind the flag `OTEL_SEMCONV_STABILITY_OPT_IN=gen_ai_latest_experimental`.
12+
Ensure same sem conv attributes are on the log and span. Fix an issue where the instrumentation would crash when a pydantic.BaseModel class was passed as the response schema ([#3905](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/3905)).
1113

1214
## Version 0.4b0 (2025-10-16)
1315

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

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,7 @@ def _flatten_compound_value_using_json(
151151
)
152152

153153

154-
def _flatten_compound_value(
154+
def _flatten_compound_value( # pylint: disable=too-many-return-statements
155155
key: str,
156156
value: Any,
157157
exclude_keys: Set[str],
@@ -189,13 +189,16 @@ def _flatten_compound_value(
189189
flatten_functions=flatten_functions,
190190
)
191191
if hasattr(value, "model_dump"):
192-
return _flatten_dict(
193-
value.model_dump(),
194-
key_prefix=key,
195-
exclude_keys=exclude_keys,
196-
rename_keys=rename_keys,
197-
flatten_functions=flatten_functions,
198-
)
192+
try:
193+
return _flatten_dict(
194+
value.model_dump(),
195+
key_prefix=key,
196+
exclude_keys=exclude_keys,
197+
rename_keys=rename_keys,
198+
flatten_functions=flatten_functions,
199+
)
200+
except TypeError:
201+
return {key: str(value)}
199202
return _flatten_compound_value_using_json(
200203
key,
201204
value,

0 commit comments

Comments
 (0)