Skip to content
Merged
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
6 changes: 3 additions & 3 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -1011,15 +1011,15 @@ jobs:
run: pnpm run test --shard=${{ matrix.shard }}/6

job_deno_integration_tests:
name: Deno Integration Tests (${{ matrix.shard }}/4)
name: Deno Integration Tests (${{ matrix.shard }}/6)
needs: [job_get_metadata, job_build]
if: needs.job_build.outputs.changed_deno_integration == 'true' || github.event_name != 'pull_request'
runs-on: ubuntu-24.04-arm
timeout-minutes: 15
strategy:
fail-fast: false
matrix:
shard: [1, 2, 3, 4]
shard: [1, 2, 3, 4, 5, 6]
steps:
- name: Check out current commit (${{ needs.job_get_metadata.outputs.commit_label }})
uses: actions/checkout@v7
Expand Down Expand Up @@ -1048,7 +1048,7 @@ jobs:
- name: Run shared Node integration tests
working-directory: dev-packages/deno-integration-tests
# Tedious runs in the dedicated SQL Server job because its database container requires x86.
run: pnpm run test:node-suites --shard=${{ matrix.shard }}/4 --exclude '**/tracing/tedious/**'
run: pnpm run test:node-suites --shard=${{ matrix.shard }}/6 --exclude '**/tracing/tedious/**'

# GitHub Actions allows at most 256 jobs in one matrix, so the E2E tests are split into two jobs that share `env`
# and `steps`.
Expand Down
4 changes: 2 additions & 2 deletions dev-packages/bun-integration-tests/node-suites/excludes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ export const NO_AUTO_INSTRUMENTATION = [
'suites/tracing/is-localhost/test.ts',
'suites/tracing/google-genai-v2/test.ts',
'suites/tracing/google-genai-v3/test.ts',
'suites/tracing/google-genai/test.ts',
'suites/tracing/google-genai/**',
'suites/tracing/groq/test.ts',
'suites/tracing/hapi/test.ts',
'suites/tracing/ioredis-dc/test.ts',
Expand Down Expand Up @@ -125,7 +125,7 @@ export const NO_AUTO_INSTRUMENTATION = [
'suites/tracing/openai/v7/test.ts',
'suites/tracing/orchestrion-lazy-registration/test.ts',
'suites/tracing/pi-ai/test.ts',
'suites/tracing/pi-durable/test.ts',
'suites/tracing/pi-durable/**',
'suites/tracing/postgres/test.ts',
'suites/tracing/postgresjs/test.ts',
'suites/tracing/prisma-orm-v5/test.ts',
Expand Down
6 changes: 3 additions & 3 deletions dev-packages/bun-integration-tests/vite.config.mts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import {
const NODE_SUITES_ROOT = fileURLToPath(new URL('../node-integration-tests', import.meta.url));

// All Node suites also run on Bun. The scenarios stay in `node-integration-tests`.
const NODE_SUITES = ['suites/**/test.ts'];
const NODE_SUITES = ['suites/**/test.ts', 'suites/**/*.test.ts'];

// Before Bun 1.4.6, `bun run` cannot load the modules that the instrumentation transforms.
const [bunMajor = 0, bunMinor = 0, bunPatch = 0] = execFileSync('bun', ['--version'], { encoding: 'utf8' })
Expand All @@ -26,8 +26,8 @@ const [bunMajor = 0, bunMinor = 0, bunPatch = 0] = execFileSync('bun', ['--versi
const BUN_BEFORE_1_4 = bunMajor < 1 || (bunMajor === 1 && bunMinor < 4);
const BUN_RUN_INSTRUMENTS = bunMajor > 1 || (bunMajor === 1 && (bunMinor > 4 || (bunMinor === 4 && bunPatch >= 6)));

const AUTO_INSTRUMENTATION_SUITES = NO_AUTO_INSTRUMENTATION.map(glob =>
glob.endsWith('/**') ? `${glob}/test.ts` : glob,
const AUTO_INSTRUMENTATION_SUITES = NO_AUTO_INSTRUMENTATION.flatMap(glob =>
glob.endsWith('/**') ? [`${glob}/test.ts`, `${glob}/*.test.ts`] : glob,
);

const nodeSuitesTest = {
Expand Down
2 changes: 1 addition & 1 deletion dev-packages/deno-integration-tests/vite.config.mts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ export default defineConfig({
...baseConfig.test,
root: fileURLToPath(new URL('../node-integration-tests', import.meta.url)),
isolate: false,
include: ['suites/**/test.ts'],
include: ['suites/**/test.ts', 'suites/**/*.test.ts'],
exclude: NODE_SUITES_EXCLUDE,
env: {
RUNTIME: 'deno',
Expand Down
10 changes: 6 additions & 4 deletions dev-packages/node-integration-tests/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ suites/
|---- test.ts [assertions]
|---- scenario.ts [Sentry initialization and test subject]
|---- customTest/
|---- test.ts [assertions]
|---- tracing.test.ts [tracing assertions]
|---- errors.test.ts [error assertions]
|---- scenario_1.ts [optional extra test scenario]
|---- scenario_2.ts [optional extra test scenario]
|---- server_with_mongo.ts [optional custom server]
Expand All @@ -22,12 +23,13 @@ folders containing test scenarios and assertions.
`scenario.ts` contains the initialization logic and the test subject. By default, `{TEST_DIR}/scenario.ts` is used, but
`runServer` also accepts an optional `scenarioPath` argument for non-standard usage.

`test.ts` is required for each test case, and contains the server runner logic, request interceptors for Sentry
requests, and assertions. Test server, interceptors and assertions are all run on the same Vitest thread.
`test.ts` and descriptive `*.test.ts` files contain the server runner logic, request interceptors for Sentry requests,
and assertions. A suite can use several named test files so Vitest can schedule them independently while sharing
scenario files. Each test's server, interceptors and assertions run on the same Vitest thread.

### Utilities

`utils/` contains helpers and Sentry-specific assertions that can be used in (`test.ts`).
`utils/` contains helpers and Sentry-specific assertions for the test files.

Nock interceptors are internally used to capture envelope requests by `getEnvelopeRequest` and
`getMultipleEnvelopeRequest` helpers. After capturing required requests, the interceptors are removed. Nock can manually
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
import { afterAll, describe, expect } from 'vitest';
import {
GEN_AI_EMBEDDINGS_INPUT,
GEN_AI_OPERATION_NAME,
GEN_AI_PROVIDER_NAME,
GEN_AI_REQUEST_MODEL,
SENTRY_OP,
SENTRY_ORIGIN,
} from '@sentry/conventions/attributes';
import { cleanupChildProcesses, createEsmAndCjsTests } from '../../../utils/runner';

const EXPECTED_ORIGIN = 'auto.ai.google_genai';

describe('Google GenAI integration', () => {
afterAll(() => {
cleanupChildProcesses();
});

createEsmAndCjsTests(__dirname, 'scenario-embeddings.mjs', 'instrument.mjs', (createRunner, test) => {
test('creates google genai embeddings spans with genAI recording disabled', async () => {
await createRunner()
.expect({
span: container => {
expect(container.items.find(span => span.is_segment && span.name === 'main')).toBeDefined();
const spans = container.items.filter(
span => span.attributes[SENTRY_ORIGIN]?.value === 'auto.ai.google_genai',
);
expect(spans).toHaveLength(3);
expect(spans.map(span => span.name).sort()).toEqual([
'embeddings error-model',
'embeddings text-embedding-004',
'embeddings text-embedding-004',
]);

const successfulSpans = spans.filter(
span => span.name === 'embeddings text-embedding-004' && span.status === 'ok',
);
expect(successfulSpans).toHaveLength(2);
for (const span of successfulSpans) {
expect(span.attributes[SENTRY_OP].value).toBe('gen_ai.embeddings');
expect(span.attributes[GEN_AI_OPERATION_NAME].value).toBe('embeddings');
expect(span.attributes[SENTRY_ORIGIN].value).toBe(EXPECTED_ORIGIN);
expect(span.attributes[GEN_AI_PROVIDER_NAME].value).toBe('google_genai');
expect(span.attributes[GEN_AI_REQUEST_MODEL].value).toBe('text-embedding-004');
expect(span.attributes[GEN_AI_EMBEDDINGS_INPUT]).toBeUndefined();
}

const errorSpan = spans.find(span => span.name === 'embeddings error-model');
expect(errorSpan!.status).toBe('error');
expect(errorSpan!.attributes[SENTRY_OP].value).toBe('gen_ai.embeddings');
expect(errorSpan!.attributes[GEN_AI_OPERATION_NAME].value).toBe('embeddings');
},
})
.start()
.completed();
});
});

createEsmAndCjsTests(__dirname, 'scenario-embeddings.mjs', 'instrument-with-pii.mjs', (createRunner, test) => {
test('creates google genai embeddings spans with genAI recording enabled', async () => {
await createRunner()
.expect({
span: container => {
expect(container.items.find(span => span.is_segment && span.name === 'main')).toBeDefined();
const spans = container.items.filter(
span => span.attributes[SENTRY_ORIGIN]?.value === 'auto.ai.google_genai',
);
expect(spans).toHaveLength(3);
expect(spans.map(span => span.name).sort()).toEqual([
'embeddings error-model',
'embeddings text-embedding-004',
'embeddings text-embedding-004',
]);

const stringInputSpan = spans.find(
span => span.attributes[GEN_AI_EMBEDDINGS_INPUT]?.value === 'What is the capital of France?',
);
expect(stringInputSpan!.name).toBe('embeddings text-embedding-004');
expect(stringInputSpan!.status).toBe('ok');
expect(stringInputSpan!.attributes[GEN_AI_OPERATION_NAME].value).toBe('embeddings');
expect(stringInputSpan!.attributes[GEN_AI_PROVIDER_NAME].value).toBe('google_genai');

const errorSpan = spans.find(span => span.attributes[GEN_AI_EMBEDDINGS_INPUT]?.value === 'This will fail');
expect(errorSpan!.name).toBe('embeddings error-model');
expect(errorSpan!.status).toBe('error');
expect(errorSpan!.attributes[GEN_AI_OPERATION_NAME].value).toBe('embeddings');

const arrayInputSpan = spans.find(
span =>
span.attributes[GEN_AI_EMBEDDINGS_INPUT]?.value ===
'[{"role":"user","parts":[{"text":"First input text"}]},{"role":"user","parts":[{"text":"Second input text"}]}]',
);
expect(arrayInputSpan!.name).toBe('embeddings text-embedding-004');
expect(arrayInputSpan!.status).toBe('ok');
expect(arrayInputSpan!.attributes[GEN_AI_OPERATION_NAME].value).toBe('embeddings');
},
})
.start()
.completed();
});
});
});
Loading
Loading