|
24 | 24 |
|
25 | 25 | logger = logging.getLogger(__name__) |
26 | 26 |
|
27 | | -_instruments = ("google-generativeai >= 0.5.0",) |
| 27 | +_instruments = ("google-generativeai >= 0.5.0", "google-genai >= 0.1.0") |
28 | 28 |
|
29 | 29 | WRAPPED_METHODS = [ |
30 | 30 | { |
|
39 | 39 | "method": "generate_content_async", |
40 | 40 | "span_name": "gemini.generate_content_async", |
41 | 41 | }, |
| 42 | + { |
| 43 | + "package": "google.genai.models", |
| 44 | + "object": "Models", |
| 45 | + "method": "generate_content", |
| 46 | + "span_name": "gemini.generate_content", |
| 47 | + }, |
| 48 | + { |
| 49 | + "package": "google.genai.models", |
| 50 | + "object": "AsyncModels", |
| 51 | + "method": "generate_content", |
| 52 | + "span_name": "gemini.generate_content", |
| 53 | + }, |
42 | 54 | ] |
43 | 55 |
|
44 | 56 |
|
@@ -69,7 +81,18 @@ def _set_input_attributes(span, args, kwargs, llm_model): |
69 | 81 |
|
70 | 82 | if "contents" in kwargs: |
71 | 83 | contents = kwargs["contents"] |
72 | | - if isinstance(contents, list): |
| 84 | + if isinstance(contents, str): |
| 85 | + _set_span_attribute( |
| 86 | + span, |
| 87 | + f"{SpanAttributes.LLM_PROMPTS}.0.content", |
| 88 | + contents, |
| 89 | + ) |
| 90 | + _set_span_attribute( |
| 91 | + span, |
| 92 | + f"{SpanAttributes.LLM_PROMPTS}.0.role", |
| 93 | + "user", |
| 94 | + ) |
| 95 | + elif isinstance(contents, list): |
73 | 96 | for i, content in enumerate(contents): |
74 | 97 | if hasattr(content, "parts"): |
75 | 98 | for part in content.parts: |
@@ -255,6 +278,8 @@ async def _awrap(tracer, to_wrap, wrapped, instance, args, kwargs): |
255 | 278 | ).replace("models/", "") |
256 | 279 | if hasattr(instance, "model") and hasattr(instance.model, "model_name"): |
257 | 280 | llm_model = instance.model.model_name.replace("models/", "") |
| 281 | + if "model" in kwargs: |
| 282 | + llm_model = kwargs["model"].replace("models/", "") |
258 | 283 |
|
259 | 284 | name = to_wrap.get("span_name") |
260 | 285 | span = tracer.start_span( |
@@ -299,6 +324,8 @@ def _wrap(tracer, to_wrap, wrapped, instance, args, kwargs): |
299 | 324 | ).replace("models/", "") |
300 | 325 | if hasattr(instance, "model") and hasattr(instance.model, "model_name"): |
301 | 326 | llm_model = instance.model.model_name.replace("models/", "") |
| 327 | + if "model" in kwargs: |
| 328 | + llm_model = kwargs["model"].replace("models/", "") |
302 | 329 |
|
303 | 330 | name = to_wrap.get("span_name") |
304 | 331 | span = tracer.start_span( |
|
0 commit comments