Skip to content
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
83 changes: 83 additions & 0 deletions cassettes/test_tool_events_no_content
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
interactions:
- request:
body: "{\n \"contents\": [\n {\n \"role\": \"user\",\n \"parts\":
[\n {\n \"text\": \"Get weather details in New Delhi and San
Francisco?\"\n }\n ]\n },\n {\n \"role\": \"model\",\n
\ \"parts\": [\n {\n \"functionCall\": {\n \"name\":
\"get_current_weather\",\n \"args\": {\n \"location\":
\"New Delhi\"\n }\n }\n },\n {\n \"functionCall\":
{\n \"name\": \"get_current_weather\",\n \"args\": {\n
\ \"location\": \"San Francisco\"\n }\n }\n
\ }\n ]\n },\n {\n \"role\": \"user\",\n \"parts\":
[\n {\n \"functionResponse\": {\n \"name\": \"get_current_weather\",\n
\ \"response\": {\n \"content\": \"{\\\"temperature\\\":
35, \\\"unit\\\": \\\"C\\\"}\"\n }\n }\n },\n {\n
\ \"functionResponse\": {\n \"name\": \"get_current_weather\",\n
\ \"response\": {\n \"content\": \"{\\\"temperature\\\":
25, \\\"unit\\\": \\\"C\\\"}\"\n }\n }\n }\n ]\n
\ }\n ],\n \"tools\": [\n {\n \"functionDeclarations\": [\n {\n
\ \"name\": \"get_current_weather\",\n \"description\": \"Get
the current weather in a given location\",\n \"parameters\": {\n \"type\":
6,\n \"properties\": {\n \"location\": {\n \"type\":
1,\n \"description\": \"The location for which to get the weather.
It can be a city name, a city name and state, or a zip code. Examples: 'San
Francisco', 'San Francisco, CA', '95616', etc.\"\n }\n },\n
\ \"propertyOrdering\": [\n \"location\"\n ]\n
\ }\n }\n ]\n }\n ]\n}"
headers:
Accept:
- '*/*'
Accept-Encoding:
- gzip, deflate
Connection:
- keep-alive
Content-Length:
- '1731'
Content-Type:
- application/json
User-Agent:
- python-requests/2.32.3
x-goog-api-client:
- model-builder/1.79.0+top_google_constructor_method+vertexai.generative_models.GenerativeModel.generate_content
gl-python/3.11.9 grpc/1.68.1 gax/2.23.0 gapic/1.79.0+top_google_constructor_method+vertexai.generative_models.GenerativeModel.generate_content
x-goog-request-params:
- model=projects/fake-project/locations/us-central1/publishers/google/models/gemini-2.5-pro
method: POST
uri: https://us-central1-aiplatform.googleapis.com/v1/projects/fake-project/locations/us-central1/publishers/google/models/gemini-2.5-pro:generateContent?%24alt=json%3Benum-encoding%3Dint
response:
body:
string: !!binary |
H4sIAAAAAAAC/91TwU7rMBC89ytWPRcHECdOVG3EqwQFkXJCCBlnSRccb7A3BYT679ghQODAgeM7
OTueHc+OndcRwBi9Zz8+hNdYxNJwibE62N2bvAM1hqCrhI0v8LHFIEABagqBXAU+QuSxBN3KGp2Q
0ULswEQsldoqyJ8bNBI5Z9NIgn3QxkRREH5ANwHLFcUG5gdCYA8chTxstKVfVQtEWIs04TDLStyg
5QZ9UBVzZVEZrjPquPKSBarcDrnsCW8T1bALbHGn8XwfjalxP2kQLW1Ig14up5erf/lytZhNV/n8
g1CiaLKJcdUB0IfWbR7JS9OllNbehm4odFZ6V74xao63bbVwd9yrDpT/54z7WbeTvyeXp5f6MzmP
OrBL3bOLfJ6ubHpS3JwuimKxPP4WMdeaOuL3E4acOl5DqUV//g5f+JrLr15lLLel0tRYLXfsa7XZ
U+cxODIpwwL9hgyqY3ToteCMncSYBiel1/ZOSqIDnR/ePhu2o+F6PUpf29EbabJOVcEDAAA=
headers:
Content-Encoding:
- gzip
Content-Type:
- application/json; charset=UTF-8
Date:
- Tue, 30 Sep 2025 15:26:53 GMT
Server:
- scaffolding on HTTPServer2
Transfer-Encoding:
- chunked
Vary:
- Origin
- X-Origin
- Referer
WWW-Authenticate:
- Bearer realm="https://accounts.google.com/"
X-Content-Type-Options:
- nosniff
X-Frame-Options:
- SAMEORIGIN
X-XSS-Protection:
- '0'
status:
code: 401
message: Unauthorized
version: 1
83 changes: 83 additions & 0 deletions cassettes/test_tool_events_no_content.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
interactions:
- request:
body: "{\n \"contents\": [\n {\n \"role\": \"user\",\n \"parts\":
[\n {\n \"text\": \"Get weather details in New Delhi and San
Francisco?\"\n }\n ]\n },\n {\n \"role\": \"model\",\n
\ \"parts\": [\n {\n \"functionCall\": {\n \"name\":
\"get_current_weather\",\n \"args\": {\n \"location\":
\"New Delhi\"\n }\n }\n },\n {\n \"functionCall\":
{\n \"name\": \"get_current_weather\",\n \"args\": {\n
\ \"location\": \"San Francisco\"\n }\n }\n
\ }\n ]\n },\n {\n \"role\": \"user\",\n \"parts\":
[\n {\n \"functionResponse\": {\n \"name\": \"get_current_weather\",\n
\ \"response\": {\n \"content\": \"{\\\"temperature\\\":
35, \\\"unit\\\": \\\"C\\\"}\"\n }\n }\n },\n {\n
\ \"functionResponse\": {\n \"name\": \"get_current_weather\",\n
\ \"response\": {\n \"content\": \"{\\\"temperature\\\":
25, \\\"unit\\\": \\\"C\\\"}\"\n }\n }\n }\n ]\n
\ }\n ],\n \"tools\": [\n {\n \"functionDeclarations\": [\n {\n
\ \"name\": \"get_current_weather\",\n \"description\": \"Get
the current weather in a given location\",\n \"parameters\": {\n \"type\":
6,\n \"properties\": {\n \"location\": {\n \"type\":
1,\n \"description\": \"The location for which to get the weather.
It can be a city name, a city name and state, or a zip code. Examples: 'San
Francisco', 'San Francisco, CA', '95616', etc.\"\n }\n },\n
\ \"propertyOrdering\": [\n \"location\"\n ]\n
\ }\n }\n ]\n }\n ]\n}"
headers:
Accept:
- '*/*'
Accept-Encoding:
- gzip, deflate
Connection:
- keep-alive
Content-Length:
- '1731'
Content-Type:
- application/json
User-Agent:
- python-requests/2.32.3
x-goog-api-client:
- model-builder/1.79.0+top_google_constructor_method+vertexai.generative_models.GenerativeModel.generate_content
gl-python/3.11.9 grpc/1.68.1 gax/2.23.0 gapic/1.79.0+top_google_constructor_method+vertexai.generative_models.GenerativeModel.generate_content
x-goog-request-params:
- model=projects/fake-project/locations/us-central1/publishers/google/models/gemini-2.5-pro
method: POST
uri: https://us-central1-aiplatform.googleapis.com/v1/projects/fake-project/locations/us-central1/publishers/google/models/gemini-2.5-pro:generateContent?%24alt=json%3Benum-encoding%3Dint
response:
body:
string: !!binary |
H4sIAAAAAAAC/91TwU7rMBC89ytWPRcHECdOVG3EqwQFkXJCCBlnSRccb7A3BYT679ghQODAgeM7
OTueHc+OndcRwBi9Zz8+hNdYxNJwibE62N2bvAM1hqCrhI0v8LHFIEABagqBXAU+QuSxBN3KGp2Q
0ULswEQsldoqyJ8bNBI5Z9NIgn3QxkRREH5ANwHLFcUG5gdCYA8chTxstKVfVQtEWIs04TDLStyg
5QZ9UBVzZVEZrjPquPKSBarcDrnsCW8T1bALbHGn8XwfjalxP2kQLW1Ig14up5erf/lytZhNV/n8
g1CiaLKJcdUB0IfWbR7JS9OllNbehm4odFZ6V74xao63bbVwd9yrDpT/54z7WbeTvyeXp5f6MzmP
OrBL3bOLfJ6ubHpS3JwuimKxPP4WMdeaOuL3E4acOl5DqUV//g5f+JrLr15lLLel0tRYLXfsa7XZ
U+cxODIpwwL9hgyqY3ToteCMncSYBiel1/ZOSqIDnR/ePhu2o+F6PUpf29EbabJOVcEDAAA=
headers:
Content-Encoding:
- gzip
Content-Type:
- application/json; charset=UTF-8
Date:
- Tue, 30 Sep 2025 15:27:34 GMT
Server:
- scaffolding on HTTPServer2
Transfer-Encoding:
- chunked
Vary:
- Origin
- X-Origin
- Referer
WWW-Authenticate:
- Bearer realm="https://accounts.google.com/"
X-Content-Type-Options:
- nosniff
X-Frame-Options:
- SAMEORIGIN
X-XSS-Protection:
- '0'
status:
code: 401
message: Unauthorized
version: 1
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## Unreleased

- Start making changes to implement the big semantic convention changes made in https://github.com/open-telemetry/semantic-conventions/pull/2179.
Now only a single event (`gen_ai.client.inference.operation.details`) is used to capture Chat History. These changes will be opt-in,
users will need to set the environment variable OTEL_SEMCONV_STABILITY_OPT_IN to `gen_ai_latest_experimental` to see them ([#3386](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/3386)).
- Update instrumentation to use the latest semantic convention changes made in https://github.com/open-telemetry/semantic-conventions/pull/2179.
Now only a single event and span (`gen_ai.client.inference.operation.details`) are used to capture prompt and response content. These changes are opt-in,
users will need to set the environment variable OTEL_SEMCONV_STABILITY_OPT_IN to `gen_ai_latest_experimental` to see them ([#3799](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/3799)) and ([#3709](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/3709)).
- Implement uninstrument for `opentelemetry-instrumentation-vertexai`
([#3328](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/3328))
- VertexAI support for async calling
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,17 @@ OTEL_SERVICE_NAME=opentelemetry-python-vertexai

# Change to 'false' to hide prompt and completion content
OTEL_INSTRUMENTATION_GENAI_CAPTURE_MESSAGE_CONTENT=true

# Alternatively set this env var to enable the latest semantic conventions:
OTEL_SEMCONV_STABILITY_OPT_IN=gen_ai_latest_experimental

# When using the latest experimental flag this env var controls which telemetry signals will have prompt and response content included in them.
# Choices are NO_CONTENT, SPAN_ONLY, EVENT_ONLY, SPAN_AND_EVENT.
OTEL_INSTRUMENTATION_GENAI_CAPTURE_MESSAGE_CONTENT=SPAN_AND_EVENT

# Optional hook that will upload prompt and response content to some external destination.
# For example fsspec.
OTEL_INSTRUMENTATION_GENAI_COMPLETION_HOOK = "fsspec"

# Required if using a completion hook. The path to upload content to for example gs://my_bucket.
OTEL_INSTRUMENTATION_GENAI_UPLOAD_BASE_PATH = "gs://my_bucket"
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,17 @@ OTEL_PYTHON_LOGGING_AUTO_INSTRUMENTATION_ENABLED=true

# Change to 'false' to hide prompt and completion content
OTEL_INSTRUMENTATION_GENAI_CAPTURE_MESSAGE_CONTENT=true

# Alternatively set this env var to enable the latest semantic conventions:
OTEL_SEMCONV_STABILITY_OPT_IN=gen_ai_latest_experimental

# When using the latest experimental flag this env var controls which telemetry signals will have prompt and response content included in them.
# Choices are NO_CONTENT, SPAN_ONLY, EVENT_ONLY, SPAN_AND_EVENT.
OTEL_INSTRUMENTATION_GENAI_CAPTURE_MESSAGE_CONTENT=SPAN_AND_EVENT

# Optional hook that will upload prompt and response content to some external destination.
# For example fsspec.
OTEL_INSTRUMENTATION_GENAI_COMPLETION_HOOK = "fsspec"

# Required if using a completion hook. The path to upload content to for example gs://my_bucket.
OTEL_INSTRUMENTATION_GENAI_UPLOAD_BASE_PATH = "gs://my_bucket"
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@
from opentelemetry.instrumentation.vertexai.utils import is_content_enabled
from opentelemetry.semconv.schemas import Schemas
from opentelemetry.trace import get_tracer
from opentelemetry.util.genai.completion_hook import load_completion_hook


def _methods_to_wrap(
Expand Down Expand Up @@ -109,6 +110,9 @@ def instrumentation_dependencies(self) -> Collection[str]:

def _instrument(self, **kwargs: Any):
"""Enable VertexAI instrumentation."""
completion_hook = (
kwargs.get("completion_hook") or load_completion_hook()
)
sem_conv_opt_in_mode = _OpenTelemetrySemanticConventionStability._get_opentelemetry_stability_opt_in_mode(
_OpenTelemetryStabilitySignalType.GEN_AI,
)
Expand Down Expand Up @@ -141,6 +145,7 @@ def _instrument(self, **kwargs: Any):
event_logger,
is_content_enabled(sem_conv_opt_in_mode),
sem_conv_opt_in_mode,
completion_hook,
)
elif sem_conv_opt_in_mode == _StabilityMode.GEN_AI_LATEST_EXPERIMENTAL:
# Type checker now knows it's the other literal
Expand All @@ -149,6 +154,7 @@ def _instrument(self, **kwargs: Any):
event_logger,
is_content_enabled(sem_conv_opt_in_mode),
sem_conv_opt_in_mode,
completion_hook,
)
else:
raise RuntimeError(f"{sem_conv_opt_in_mode} mode not supported")
Expand Down
Loading