-
Notifications
You must be signed in to change notification settings - Fork 789
Update google genai instrumentation to work with latest semantic convention, allow for uploading content. #3772
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
|
...trumentation-google-genai/src/opentelemetry/instrumentation/google_genai/generate_content.py
Outdated
Show resolved
Hide resolved
...trumentation-google-genai/src/opentelemetry/instrumentation/google_genai/generate_content.py
Outdated
Show resolved
Hide resolved
...trumentation-google-genai/src/opentelemetry/instrumentation/google_genai/generate_content.py
Outdated
Show resolved
Hide resolved
...trumentation-google-genai/src/opentelemetry/instrumentation/google_genai/generate_content.py
Outdated
Show resolved
Hide resolved
...trumentation-google-genai/src/opentelemetry/instrumentation/google_genai/generate_content.py
Outdated
Show resolved
Hide resolved
...trumentation-google-genai/src/opentelemetry/instrumentation/google_genai/generate_content.py
Outdated
Show resolved
Hide resolved
e76d888
to
d0d6f1a
Compare
Co-authored-by: Aaron Abbott <aaronabbott@google.com>
d0d6f1a
to
ee911f5
Compare
5d0572a
to
8583327
Compare
...-instrumentation-google-genai/src/opentelemetry/instrumentation/google_genai/instrumentor.py
Outdated
Show resolved
Hide resolved
...lemetry-instrumentation-google-genai/src/opentelemetry/instrumentation/google_genai/flags.py
Show resolved
Hide resolved
...metry-instrumentation-google-genai/src/opentelemetry/instrumentation/google_genai/message.py
Outdated
Show resolved
Hide resolved
...metry-instrumentation-google-genai/src/opentelemetry/instrumentation/google_genai/message.py
Show resolved
Hide resolved
interactions: | ||
- request: | ||
body: |- | ||
{ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Mind adding a test for the completion hook somewhere ? https://github.com/open-telemetry/opentelemetry-python-contrib/blob/main/instrumentation-genai/opentelemetry-instrumentation-vertexai/tests/test_function_calling_experimental.py#L262 -- this is how I did it for vertex AI
instrumentation-genai/opentelemetry-instrumentation-google-genai/tests/requirements.oldest.txt
Show resolved
Hide resolved
…y-python-contrib into genai-instrumentation-semconv
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you, LGTM! Will merge once Dylan has finished reviewing/approved too.
|
||
if as_str: | ||
return { | ||
k: json.dumps(v, cls=_GenAiJsonEncoder) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can you use this function instead? it will remove extra whitespace too
opentelemetry-python-contrib/util/opentelemetry-util-genai/src/opentelemetry/util/genai/utils.py
Line 76 in a4adc93
gen_ai_json_dumps = partial( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done, but won't this require util-genai package version bump? I see this func is not in the currently released version (0.1b0)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ya I can do a release today before merging
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe for now don't pin a version and use it.
Lines 29 to 31 in 9f393c7
# TODO https://github.com/open-telemetry/opentelemetry-python-contrib/issues/3786: restrict | |
# version after the first release | |
"opentelemetry-util-genai", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done, I linked it to the same issue, will add a comment there that it's also the case for google-genai instrumentation.
...trumentation-google-genai/src/opentelemetry/instrumentation/google_genai/generate_content.py
Outdated
Show resolved
Hide resolved
...entation-genai/opentelemetry-instrumentation-google-genai/tests/generate_content/test_e2e.py
Show resolved
Hide resolved
uri: https://test-location-aiplatform.googleapis.com/v1beta1/projects/test-project/locations/test-location/publishers/google/models/gemini-2.5-flash:streamGenerateContent?alt=sse | ||
response: | ||
body: | ||
string: "data: {\"candidates\": [{\"content\": {\"role\": \"model\",\"parts\"\ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Any idea why this one is formatted like this vs the other RPC recordings?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Dylan updated these, so I don't know :/ @DylanRussell?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure.. will take a look
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ok, so it's only like this for the streaming tests. It's like this in the current streaming cassettes at head too.
It's because the response is sent using Server-Sent Events (SSE) format, which is a stream of separate data messages. json.loads
fails here:
Lines 207 to 208 in 9f393c7
json_data = json.loads(string_value) | |
return _LiteralBlockScalar(json.dumps(json_data, indent=2)) |
uri: https://test-location-aiplatform.googleapis.com/v1beta1/projects/test-project/locations/test-location/publishers/google/models/gemini-2.5-flash:streamGenerateContent?alt=sse | ||
response: | ||
body: | ||
string: "data: {\"candidates\": [{\"content\": {\"role\": \"model\",\"parts\"\ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same question, why is the YAML not nice like the other recordings?
util/opentelemetry-util-genai/src/opentelemetry/util/genai/types.py
Outdated
Show resolved
Hide resolved
...ation-genai/opentelemetry-instrumentation-google-genai/tests/utils/test_tool_call_wrapper.py
Show resolved
Hide resolved
...metry-instrumentation-google-genai/src/opentelemetry/instrumentation/google_genai/message.py
Show resolved
Hide resolved
|
||
if as_str: | ||
return { | ||
k: json.dumps(v, cls=_GenAiJsonEncoder) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe for now don't pin a version and use it.
Lines 29 to 31 in 9f393c7
# TODO https://github.com/open-telemetry/opentelemetry-python-contrib/issues/3786: restrict | |
# version after the first release | |
"opentelemetry-util-genai", |
uri: https://test-location-aiplatform.googleapis.com/v1beta1/projects/test-project/locations/test-location/publishers/google/models/gemini-2.5-flash:streamGenerateContent?alt=sse | ||
response: | ||
body: | ||
string: "data: {\"candidates\": [{\"content\": {\"role\": \"model\",\"parts\"\ |
There was a problem hiding this comment.
Not sure.. will take a look
Description
Accomodation of semantic conventions changes made in open-telemetry/semantic-conventions#2179.
Also, when logging the completion details, the upload hook is called, so if user has configured
OTEL_INSTRUMENTATION_GENAI_UPLOAD_BASE_PATH
andOTEL_INSTRUMENTATION_GENAI_UPLOAD_HOOK
env vars, completion details will also be logged as refs (if appropriate capture content env var is set).Type of change
How Has This Been Tested?
Unit tests, manual tests.
Does This PR Require a Core Repo Change?
No?
Checklist:
See contributing.md for styleguide, changelog guidelines, and more.