Skip to content

Commit 5ac2108

Browse files
committed
Make it easy to turn off instrumentation for streaming and async to allow for rapid iteration.
1 parent b6068e2 commit 5ac2108

File tree

1 file changed

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

1 file changed

+15
-0
lines changed

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

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,12 @@
2424
_logger = logging.getLogger(__name__)
2525

2626

27+
# Enable these after these cases are fully vetted and tested
28+
_INSTRUMENT_STREAMING = False
29+
_INSTRUMENT_ASYNC = False
30+
31+
32+
2733
class _MethodsSnapshot:
2834

2935
def __init__(self):
@@ -317,6 +323,9 @@ def _create_instrumented_generate_content_stream(
317323
snapshot: _MethodsSnapshot,
318324
otel_wrapper: OTelWrapper):
319325
wrapped_func = snapshot.generate_content_stream
326+
if not _INSTRUMENT_STREAMING:
327+
# TODO: remove once this case has been fully tested
328+
return wrapped_func
320329
@functools.wraps(wrapped_func)
321330
def instrumented_generate_content_stream(
322331
self: Models,
@@ -343,6 +352,9 @@ def _create_instrumented_async_generate_content(
343352
snapshot: _MethodsSnapshot,
344353
otel_wrapper: OTelWrapper):
345354
wrapped_func = snapshot.async_generate_content
355+
if not _INSTRUMENT_ASYNC:
356+
# TODO: remove once this case has been fully tested
357+
return wrapped_func
346358
@functools.wraps(wrapped_func)
347359
async def instrumented_generate_content(
348360
self: AsyncModels,
@@ -369,6 +381,9 @@ def _create_instrumented_async_generate_content_stream(
369381
snapshot: _MethodsSnapshot,
370382
otel_wrapper: OTelWrapper):
371383
wrapped_func = snapshot.async_generate_content_stream
384+
if not _INSTRUMENT_ASYNC or not _INSTRUMENT_STREAMING:
385+
# TODO: remove once this case has been fully tested
386+
return wrapped_func
372387
@functools.wraps(wrapped_func)
373388
async def instrumented_generate_content_stream(
374389
self: AsyncModels,

0 commit comments

Comments
 (0)