Skip to content

feat: @google/genai Gemini AI LLM instrumentation #3119

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

Open
wants to merge 34 commits into
base: main
Choose a base branch
from

Conversation

amychisholm03
Copy link
Contributor

@amychisholm03 amychisholm03 commented May 27, 2025

This PR closes #2890. This instruments the @google/genai library which provides an SDK for Google's Gemini AI.

For reviewers, refer to:

Copy link

codecov bot commented May 27, 2025

Codecov Report

Attention: Patch coverage is 98.24176% with 8 lines in your changes missing coverage. Please review.

Project coverage is 80.27%. Comparing base (686c747) to head (eaa4c4c).
Report is 1 commits behind head on main.

Files with missing lines Patch % Lines
lib/instrumentation/@google/genai.js 98.96% 3 Missing ⚠️
lib/llm-events/google-genai/embedding.js 88.00% 3 Missing ⚠️
lib/llm-events/error-message.js 88.23% 2 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #3119      +/-   ##
==========================================
- Coverage   80.27%   80.27%   -0.01%     
==========================================
  Files         322      328       +6     
  Lines       49103    49558     +455     
==========================================
+ Hits        39419    39781     +362     
- Misses       9684     9777      +93     
Flag Coverage Δ
integration-tests-esm-20.x 49.64% <29.16%> (?)
integration-tests-esm-22.x 49.70% <29.16%> (-0.01%) ⬇️
versioned-tests-18.x 80.17% <98.24%> (?)
versioned-tests-20.x 80.18% <98.24%> (?)
versioned-tests-22.x 80.19% <98.24%> (-0.01%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@amychisholm03 amychisholm03 marked this pull request as ready for review May 28, 2025 17:13
Copy link
Contributor

@jsumners-nr jsumners-nr left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It'll take some time to go through the actual code. But I wanted to get this style feedback over sooner rather than later.

@amychisholm03 amychisholm03 changed the title feat: @google/gen-ai Gemini AI LLM instrumentation feat: @google/genai Gemini AI LLM instrumentation May 28, 2025
@amychisholm03 amychisholm03 requested a review from mrickard June 2, 2025 14:43
Co-authored-by: Maurice Rickard <[email protected]>
@amychisholm03 amychisholm03 requested a review from jsumners-nr June 3, 2025 18:14
this['error.message'] = cause?.message
this['error.code'] = response?.code ?? cause?.error?.code
this['error.code'] = response?.code ?? cause?.error?.code ?? parsedError?.code
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

...though if we define parsedError from cause.message, we'll need to change this reference to parsedError.code

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it's better to set parsedError to undefined that way we don't attempt to set http.statusCode or error.code if that value doesn't actually exist.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And it's true that we're capturing cause.message in error.message.

I'd recommend we add one test of a malformed cause.message string in test/versioned/google-genai/mock-responses.js, just to make sure that this error handling does what we think it does.

Copy link
Contributor Author

@amychisholm03 amychisholm03 Jun 3, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yup I added that test in test/unit/llm-events/google-genai/error.test.js per James' suggestion

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: Needs PR Review
Development

Successfully merging this pull request may close these issues.

Gemini LLM support - node.js
3 participants