Skip to content
Closed
Show file tree
Hide file tree
Changes from all 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
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,27 @@ describe('Google GenAI integration (v2)', () => {

createEsmAndCjsTests(
__dirname,
'../google-genai/scenario.mjs',
['../google-genai/scenario.mjs', '../google-genai/scenario-embeddings.mjs'],
'instrument.mjs',
(createRunner, test) => {
test('auto-instruments chat and generateContent on @google/genai v2', async () => {
const runner = createRunner().ignore('event');
const spansPromise = runner.collectStreamedSpansUntilSegment('main');
let scenarios: ReturnType<typeof runScenarios> | undefined;
async function runScenarios() {
const runner = createRunner();

const collectors = ['../google-genai/scenario.mjs', '../google-genai/scenario-embeddings.mjs'].map(name =>
runner.collectStreamedSpansUntilSegment(
span => span.name === 'main' && span.attributes['test.scenario']?.value === name,
),
);
await runner.start().completed();
return { spans: await Promise.all(collectors) };
}
const getScenarios = () => (scenarios ??= runScenarios());

test('auto-instruments chat and generateContent on @google/genai v2', async () => {
const spansPromise = getScenarios().then(result => result.spans[0]!);

await getScenarios();

const spans = (await spansPromise).filter(
span => span.attributes[SENTRY_ORIGIN]?.value === 'auto.ai.google_genai',
Expand Down Expand Up @@ -78,22 +91,13 @@ describe('Google GenAI integration (v2)', () => {
expect(errorSpan!.attributes[GEN_AI_OPERATION_NAME].value).toBe('generate_content');
expect(errorSpan!.attributes[GEN_AI_REQUEST_MODEL].value).toBe('error-model');
});
},
{ additionalDependencies: { '@google/genai': '^2' } },
);

createEsmAndCjsTests(
__dirname,
'../google-genai/scenario-embeddings.mjs',
'instrument.mjs',
(createRunner, test) => {
// `embedContent` is the member that changed shape in v2; asserting its span proves the
// `className`/`methodName` selector still matches the constructor-assigned arrow.
test('auto-instruments embedContent on @google/genai v2', async () => {
const runner = createRunner().ignore('event');
const spansPromise = runner.collectStreamedSpansUntilSegment('main');
const spansPromise = getScenarios().then(result => result.spans[1]!);

await runner.start().completed();
await getScenarios();

const spans = (await spansPromise).filter(
span => span.attributes[SENTRY_ORIGIN]?.value === 'auto.ai.google_genai',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ function startMockGoogleGenAIServer() {
return startMockServer(app);
}

async function run() {
export async function run() {
const server = await startMockGoogleGenAIServer();

await Sentry.startSpan({ op: 'function', name: 'main' }, async () => {
Expand Down Expand Up @@ -70,5 +70,3 @@ async function run() {

server.close();
}

run();
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ const BLOCKED_CHUNKS = [
{ candidates: [{ content: { parts: [{ text: 'This should not be processed' }], role: 'model' }, index: 0 }] },
];

async function run() {
export async function run() {
const server = await startMockGoogleGenAIServer();

await Sentry.startSpan({ op: 'function', name: 'main' }, async () => {
Expand Down Expand Up @@ -142,5 +142,3 @@ async function run() {

server.close();
}

run();
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ function startMockGoogleGenAIServer() {
return startMockServer(app);
}

async function run() {
export async function run() {
const server = await startMockGoogleGenAIServer();

await Sentry.startSpan({ op: 'function', name: 'main' }, async () => {
Expand Down Expand Up @@ -44,9 +44,5 @@ async function run() {
});
});

await Sentry.flush(2000);

server.close();
}

run();
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ function startMockGoogleGenAIServer() {
return startMockServer(app);
}

async function run() {
export async function run() {
const server = await startMockGoogleGenAIServer();

await Sentry.startSpan({ op: 'function', name: 'main' }, async () => {
Expand Down Expand Up @@ -145,5 +145,3 @@ async function run() {

server.close();
}

run();
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ function startMockGoogleGenAIServer() {
return startMockServer(app);
}

async function run() {
export async function run() {
const server = await startMockGoogleGenAIServer();

await Sentry.startSpan({ op: 'function', name: 'main' }, async () => {
Expand Down Expand Up @@ -87,5 +87,3 @@ async function run() {

server.close();
}

run();
Loading
Loading