Skip to content

Commit a386a30

Browse files
committed
Merge base changes.
2 parents 1ebaa6e + 4b1f244 commit a386a30

File tree

20 files changed

+4455
-86
lines changed

20 files changed

+4455
-86
lines changed

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,13 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
2323
([#3266](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/3266))
2424
- `opentelemetry-instrumentation-botocore` Add support for GenAI choice events
2525
([#3275](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/3275))
26+
- `opentelemetry-instrumentation-botocore` Add support for GenAI tool events
27+
([#3302](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/3302))
2628
- `opentelemetry-instrumentation` make it simpler to initialize auto-instrumentation programmatically
2729
([#3273](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/3273))
30+
- Add `opentelemetry-instrumentation-vertexai>=2.0b0` to `opentelemetry-bootstrap`
31+
([#3307](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/3307))
32+
2833

2934
### Fixed
3035

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

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,10 @@ All notable changes to this project will be documented in this file.
55
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
66
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
77

8-
## 0.0.2
9-
10-
Add support for aync and streaming.
11-
([#3298](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/3298))
12-
138
## Unreleased
149

10+
- Add support for async and streaming.
11+
([#3298](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/3298))
12+
1513
Create an initial version of Open Telemetry instrumentation for github.com/googleapis/python-genai.
1614
([#3256](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/3256))

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

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,16 @@
44

55
Here are some TODO items required to achieve stability for this package:
66

7-
1. Add more span-level attributes for request configuration
8-
2. Add more span-level attributes for response information
9-
3. Verify and correct formatting of events:
10-
- Including the 'role' field for message events
11-
- Including tool invocation information
12-
4. Emit events for safety ratings when they block responses
13-
5. Additional cleanup/improvement tasks such as:
14-
- Adoption of 'wrapt' instead of 'functools.wraps'
15-
- Bolstering test coverage
16-
6. Migrate tests to use VCR.py
7+
- Add more span-level attributes for request configuration
8+
- Add more span-level attributes for response information
9+
- Verify and correct formatting of events:
10+
- Including the 'role' field for message events
11+
- Including tool invocation information
12+
- Emit events for safety ratings when they block responses
13+
- Additional cleanup/improvement tasks such as:
14+
- Adoption of 'wrapt' instead of 'functools.wraps'
15+
- Bolstering test coverage
16+
- Migrate tests to use VCR.py
1717

1818
## Future
1919

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

Lines changed: 31 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -220,7 +220,9 @@ def __init__(
220220
self._response_index = 0
221221
self._candidate_index = 0
222222

223-
def start_span_as_current_span(self, model_name, function_name):
223+
def start_span_as_current_span(
224+
self, model_name, function_name, end_on_exit=True
225+
):
224226
return self._otel_wrapper.start_as_current_span(
225227
f"{_GENERATE_CONTENT_OP_NAME} {model_name}",
226228
start_time=self._start_time,
@@ -230,6 +232,7 @@ def start_span_as_current_span(self, model_name, function_name):
230232
gen_ai_attributes.GEN_AI_REQUEST_MODEL: self._genai_request_model,
231233
gen_ai_attributes.GEN_AI_OPERATION_NAME: _GENERATE_CONTENT_OP_NAME,
232234
},
235+
end_on_exit=end_on_exit,
233236
)
234237

235238
def process_request(
@@ -600,7 +603,7 @@ def instrumented_generate_content(
600603
self,
601604
model=model,
602605
contents=contents,
603-
config=config,
606+
config=_wrapped_config(otel_wrapper, config),
604607
**kwargs,
605608
)
606609
helper.process_response(response)
@@ -640,7 +643,7 @@ def instrumented_generate_content_stream(
640643
self,
641644
model=model,
642645
contents=contents,
643-
config=config,
646+
config=_wrapped_config(otel_wrapper, config),
644647
**kwargs,
645648
):
646649
helper.process_response(response)
@@ -680,7 +683,7 @@ async def instrumented_generate_content(
680683
self,
681684
model=model,
682685
contents=contents,
683-
config=config,
686+
config=_wrapped_config(otel_wrapper, config),
684687
**kwargs,
685688
)
686689
helper.process_response(response)
@@ -712,22 +715,32 @@ async def instrumented_generate_content_stream(
712715
helper = _GenerateContentInstrumentationHelper(
713716
self, otel_wrapper, model
714717
)
718+
with helper.start_span_as_current_span(
719+
model,
720+
"google.genai.AsyncModels.generate_content_stream",
721+
end_on_exit=False,
722+
) as span:
723+
helper.process_request(contents, config)
724+
try:
725+
response_async_generator = await wrapped_func(
726+
self,
727+
model=model,
728+
contents=contents,
729+
config=_wrapped_config(otel_wrapper, config),
730+
**kwargs,
731+
)
732+
except Exception as error:
733+
helper.process_error(error)
734+
helper.finalize_processing()
735+
with trace.use_span(span, end_on_exit=True):
736+
raise
715737

716-
async def _internal_generator():
717-
with helper.start_span_as_current_span(
718-
model, "google.genai.AsyncModels.generate_content_stream"
719-
):
720-
helper.process_request(contents, config)
738+
async def _response_async_generator_wrapper():
739+
with trace.use_span(span, end_on_exit=True):
721740
try:
722-
async for response in await wrapped_func(
723-
self,
724-
model=model,
725-
contents=contents,
726-
config=config,
727-
**kwargs,
728-
): # pyright: ignore
741+
async for response in response_async_generator:
729742
helper.process_response(response)
730-
yield response # pyright: ignore
743+
yield response
731744
except Exception as error:
732745
helper.process_error(error)
733746
raise
@@ -736,7 +749,7 @@ async def _internal_generator():
736749

737750
class _GeneratorProvider:
738751
def __aiter__(self):
739-
return _internal_generator()
752+
return _response_async_generator_wrapper()
740753

741754
return _GeneratorProvider()
742755

instrumentation/opentelemetry-instrumentation-aiohttp-client/src/opentelemetry/instrumentation/aiohttp_client/__init__.py

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -22,24 +22,29 @@
2222
2323
.. code:: python
2424
25+
import asyncio
2526
import aiohttp
2627
from opentelemetry.instrumentation.aiohttp_client import create_trace_config
2728
import yarl
2829
2930
def strip_query_params(url: yarl.URL) -> str:
3031
return str(url.with_query(None))
3132
32-
async with aiohttp.ClientSession(trace_configs=[create_trace_config(
33+
async def get(url):
34+
async with aiohttp.ClientSession(trace_configs=[create_trace_config(
3335
# Remove all query params from the URL attribute on the span.
3436
url_filter=strip_query_params,
35-
)]) as session:
36-
async with session.get(url) as response:
37-
await response.text()
37+
)]) as session:
38+
async with session.get(url) as response:
39+
await response.text()
40+
41+
asyncio.run(get("https://example.com"))
3842
3943
Instrumenting all client sessions:
4044
4145
.. code:: python
4246
47+
import asyncio
4348
import aiohttp
4449
from opentelemetry.instrumentation.aiohttp_client import (
4550
AioHttpClientInstrumentor
@@ -49,9 +54,12 @@ def strip_query_params(url: yarl.URL) -> str:
4954
AioHttpClientInstrumentor().instrument()
5055
5156
# Create a session and make an HTTP get request
52-
async with aiohttp.ClientSession() as session:
53-
async with session.get(url) as response:
54-
await response.text()
57+
async def get(url):
58+
async with aiohttp.ClientSession() as session:
59+
async with session.get(url) as response:
60+
await response.text()
61+
62+
asyncio.run(get("https://example.com"))
5563
5664
Configuration
5765
-------------

instrumentation/opentelemetry-instrumentation-botocore/src/opentelemetry/instrumentation/botocore/extensions/bedrock.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -248,7 +248,8 @@ def before_service_call(
248248
messages = self._get_request_messages()
249249
for message in messages:
250250
event_logger = instrumentor_context.event_logger
251-
event_logger.emit(message_to_event(message, capture_content))
251+
for event in message_to_event(message, capture_content):
252+
event_logger.emit(event)
252253

253254
if not span.is_recording():
254255
return

0 commit comments

Comments
 (0)