Skip to content

Commit d0f5444

Browse files
committed
Fix lint issues.
1 parent ff73608 commit d0f5444

File tree

1 file changed

+32
-15
lines changed
  • instrumentation-genai/opentelemetry-instrumentation-google-genai/src/opentelemetry/instrumentation/google_genai

1 file changed

+32
-15
lines changed

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

Lines changed: 32 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414

1515

1616
import json
17-
from typing import Any, Callable, Dict, Optional, Sequence, Set, Union
17+
from typing import Any, Callable, Dict, Optional, Sequence, Set, Union, Tuple
1818

1919
Primitive = Union[bool, str, int, float]
2020
BoolList = list[bool]
@@ -63,32 +63,49 @@ def _get_flatten_func(
6363
return None
6464

6565

66-
def _flatten_compound_value(
66+
def _flatten_with_flatten_func(
6767
key: str,
6868
value: Any,
6969
exclude_keys: Set[str],
7070
rename_keys: Dict[str, str],
7171
flatten_functions: Dict[str, Callable],
72-
key_names: Set[str],
73-
_from_json=False,
74-
) -> FlattenedDict:
72+
key_names: Set[str]) -> Tuple[bool, Any]:
7573
flatten_func = _get_flatten_func(flatten_functions, key_names)
76-
if flatten_func is not None:
77-
func_output = flatten_func(
74+
if flatten_func is None:
75+
return False, value
76+
func_output = flatten_func(
7877
key,
7978
value,
8079
exclude_keys=exclude_keys,
8180
rename_keys=rename_keys,
8281
flatten_functions=flatten_functions,
8382
)
84-
if func_output is None:
85-
return {}
86-
elif _is_primitive(func_output) or _is_homogenous_primitive_list(
87-
func_output
88-
):
89-
return {key: func_output}
90-
else:
91-
value = func_output
83+
if func_output is None:
84+
return True, {}
85+
if _is_primitive(func_output) or _is_homogenous_primitive_list(
86+
func_output):
87+
return True, {key: func_output}
88+
return False, func_output
89+
90+
91+
def _flatten_compound_value(
92+
key: str,
93+
value: Any,
94+
exclude_keys: Set[str],
95+
rename_keys: Dict[str, str],
96+
flatten_functions: Dict[str, Callable],
97+
key_names: Set[str],
98+
_from_json=False,
99+
) -> FlattenedDict:
100+
fully_flattened_with_flatten_func, value = _flatten_with_flatten_func(
101+
key=key,
102+
value=value,
103+
exclude_keys=exclude_keys,
104+
rename_keys=rename_keys,
105+
flatten_functions=flatten_functions,
106+
key_names=key_names)
107+
if fully_flattened_with_flatten_func:
108+
return value
92109
if isinstance(value, dict):
93110
return _flatten_dict(
94111
value,

0 commit comments

Comments
 (0)