Skip to content

Commit 6ae0525

Browse files
committed
Add **kwargs to patched methods to prevent future breakage due to the addition of future keyword arguments.
1 parent c834e97 commit 6ae0525

File tree

1 file changed

+12
-8
lines changed
  • instrumentation-genai/opentelemetry-instrumentation-google-genai/src/opentelemetry/instrumentation/google_genai

1 file changed

+12
-8
lines changed

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

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -332,12 +332,13 @@ def instrumented_generate_content(
332332
*,
333333
model: str,
334334
contents: Union[ContentListUnion, ContentListUnionDict],
335-
config: Optional[GenerateContentConfigOrDict] = None) -> GenerateContentResponse:
335+
config: Optional[GenerateContentConfigOrDict] = None,
336+
**kwargs: Any) -> GenerateContentResponse:
336337
helper = _GenerateContentInstrumentationHelper(self, otel_wrapper, model)
337338
with helper.start_span_as_current_span(model, "google.genai.Models.generate_content"):
338339
helper.process_request(contents, config)
339340
try:
340-
response = wrapped_func(self, model=model, contents=contents, config=config)
341+
response = wrapped_func(self, model=model, contents=contents, config=config, **kwargs)
341342
helper.process_response(response)
342343
return response
343344
except Exception as error:
@@ -361,12 +362,13 @@ def instrumented_generate_content_stream(
361362
*,
362363
model: str,
363364
contents: Union[ContentListUnion, ContentListUnionDict],
364-
config: Optional[GenerateContentConfigOrDict] = None) -> Iterator[GenerateContentResponse]:
365+
config: Optional[GenerateContentConfigOrDict] = None,
366+
**kwargs: Any) -> Iterator[GenerateContentResponse]:
365367
helper = _GenerateContentInstrumentationHelper(self, otel_wrapper, model)
366368
with helper.start_span_as_current_span(model, "google.genai.Models.generate_content_stream"):
367369
helper.process_request(contents, config)
368370
try:
369-
for response in wrapped_func(self, model=model, contents=contents, config=config):
371+
for response in wrapped_func(self, model=model, contents=contents, config=config, **kwargs):
370372
helper.process_response(response)
371373
yield response
372374
except Exception as error:
@@ -390,12 +392,13 @@ async def instrumented_generate_content(
390392
*,
391393
model: str,
392394
contents: Union[ContentListUnion, ContentListUnionDict],
393-
config: Optional[GenerateContentConfigOrDict] = None) -> GenerateContentResponse:
395+
config: Optional[GenerateContentConfigOrDict] = None,
396+
**kwargs: Any) -> GenerateContentResponse:
394397
helper = _GenerateContentInstrumentationHelper(self, otel_wrapper, model)
395398
with helper.start_span_as_current_span(model, "google.genai.AsyncModels.generate_content"):
396399
helper.process_request(contents, config)
397400
try:
398-
response = await wrapped_func(self, model=model, contents=contents, config=config)
401+
response = await wrapped_func(self, model=model, contents=contents, config=config, **kwargs)
399402
helper.process_response(response)
400403
return response
401404
except Exception as error:
@@ -420,12 +423,13 @@ async def instrumented_generate_content_stream(
420423
*,
421424
model: str,
422425
contents: Union[ContentListUnion, ContentListUnionDict],
423-
config: Optional[GenerateContentConfigOrDict] = None) -> Awaitable[AsyncIterator[GenerateContentResponse]]: # pyright: ignore
426+
config: Optional[GenerateContentConfigOrDict] = None,
427+
**kwargs: Any) -> Awaitable[AsyncIterator[GenerateContentResponse]]: # pyright: ignore
424428
helper = _GenerateContentInstrumentationHelper(self, otel_wrapper, model)
425429
with helper.start_span_as_current_span(model, "google.genai.AsyncModels.generate_content_stream"):
426430
helper.process_request(contents, config)
427431
try:
428-
async for response in await wrapped_func(self, model=model, contents=contents, config=config): # pyright: ignore
432+
async for response in await wrapped_func(self, model=model, contents=contents, config=config, **kwargs): # pyright: ignore
429433
helper.process_response(response)
430434
yield response # pyright: ignore
431435
except Exception as error:

0 commit comments

Comments
 (0)