-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
feat(core,node): Add instrumentation for GoogleGenAI
#17625
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
Conversation
size-limit report 📦
|
node-overhead report 🧳Note: This is a synthetic benchmark with a minimal express app and does not necessarily reflect the real-world performance impact in an application.
|
52f49f5
to
6ef5ce0
Compare
packages/node/src/integrations/tracing/google-genai/instrumentation.ts
Outdated
Show resolved
Hide resolved
af4e147
to
2a58c6a
Compare
dev-packages/node-integration-tests/suites/tracing/google-genai/scenario.mjs
Outdated
Show resolved
Hide resolved
packages/node/src/integrations/tracing/google-genai/instrumentation.ts
Outdated
Show resolved
Hide resolved
packages/node/src/integrations/tracing/google-genai/instrumentation.ts
Outdated
Show resolved
Hide resolved
224c1a3
to
60eb2d1
Compare
60eb2d1
to
275a9a7
Compare
tracesSampleRate: 1.0, | ||
sendDefaultPii: true, | ||
transport: loggingTransport, | ||
integrations: [Sentry.googleGenAIIntegration()], |
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.
integrations: [Sentry.googleGenAIIntegration()], |
this is added by default, right? So no need to add this here :)
tracesSampleRate: 1.0, | ||
sendDefaultPii: false, | ||
transport: loggingTransport, | ||
integrations: [Sentry.googleGenAIIntegration()], |
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.
integrations: [Sentry.googleGenAIIntegration()], |
/** | ||
* Google GenAI Integration interface for type safety | ||
*/ | ||
export interface GoogleGenAIIntegration { |
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.
do we actually need this, when we do not lookup the integration on the client anymore? :)
* @param wrappedConstructor The wrapped constructor function to replace the original with | ||
* @returns void | ||
*/ | ||
export function replaceExports( |
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.
👍 nice util!
exports => this._patch(exports), | ||
exports => exports, | ||
[ | ||
new InstrumentationNodeModuleFile( |
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.
let's add a comment here why this is necessary, for future reference!
const config = this.getConfig(); | ||
|
||
if (typeof Original !== 'function') { | ||
return; |
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.
return; | |
return exports; |
Do we not need to return the exports here if we do not patch it? 🤔 or is this handled if this is undefined and we do nothing then? just double checking 😅
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.
Nah i think you're correct
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.
left some small comments but overall this looks very good now 🚀
GoogleGenerativeAI
GoogleGenAI
…17664) ✅ This PR depends on #17625 and it should be reviewed only after that one is merged. This PR adds: 1. Streaming support for Google GenAI sdk instrumenting the following methods: 1. Models API Streaming - `models.generateContentStream()` - Stream content generation with real-time chunks 3. Chat API Streaming (chats.create) - `chat.sendMessageStream()` - Stream chat responses with conversation context 2. New tool calls attributes - GEN_AI_REQUEST_AVAILABLE_TOOLS_ATTRIBUTE - Captures available tools from requests - GEN_AI_RESPONSE_TOOL_CALLS_ATTRIBUTE - Captures function calls from responses --------- Co-authored-by: Andrei <[email protected]>
This PR implements instrumentation for the Google Gen AI SDK, adding automatic tracing for both direct model calls (models.generateContent) and conversational chat sessions (chats.create + sendMessage). The implementation follows Sentry's AI Agents Manual Instrumentation conventions and includes integration tests.
Usage: