Skip to content

Commit 26aef68

Browse files
committed
split up knex into two docker files
1 parent 9b3cd20 commit 26aef68

File tree

9 files changed

+156
-147
lines changed

9 files changed

+156
-147
lines changed
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
version: '3.9'
2+
3+
services:
4+
db_mysql2:
5+
image: mysql:8
6+
restart: always
7+
container_name: integration-tests-knex-mysql2
8+
ports:
9+
- '3307:3306'
10+
environment:
11+
MYSQL_ROOT_PASSWORD: docker
12+
MYSQL_DATABASE: tests
File renamed without changes.
File renamed without changes.
Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
import { describe, expect } from 'vitest';
2+
import { createEsmAndCjsTests } from '../../../../utils/runner';
3+
4+
describe('knex auto instrumentation', () => {
5+
// Update this if another knex version is installed
6+
const KNEX_VERSION = '2.5.1';
7+
8+
describe('with `mysql2` client', () => {
9+
createEsmAndCjsTests(__dirname, 'scenario.mjs', 'instrument.mjs', (createRunner, test) => {
10+
test('should auto-instrument `knex` package', { timeout: 60_000 }, async () => {
11+
const EXPECTED_TRANSACTION = {
12+
transaction: 'Test Transaction',
13+
spans: expect.arrayContaining([
14+
expect.objectContaining({
15+
data: expect.objectContaining({
16+
'knex.version': KNEX_VERSION,
17+
'db.system': 'mysql2',
18+
'db.name': 'tests',
19+
'db.user': 'root',
20+
'sentry.origin': 'auto.db.otel.knex',
21+
'sentry.op': 'db',
22+
'net.peer.name': 'localhost',
23+
'net.peer.port': 3307,
24+
}),
25+
status: 'ok',
26+
description:
27+
'create table `User` (`id` int unsigned not null auto_increment primary key, `createdAt` timestamp(3) not null default CURRENT_TIMESTAMP(3), `email` text not null, `name` text not null)',
28+
origin: 'auto.db.otel.knex',
29+
}),
30+
expect.objectContaining({
31+
data: expect.objectContaining({
32+
'knex.version': KNEX_VERSION,
33+
'db.system': 'mysql2',
34+
'db.name': 'tests',
35+
'db.user': 'root',
36+
'sentry.origin': 'auto.db.otel.knex',
37+
'sentry.op': 'db',
38+
'net.peer.name': 'localhost',
39+
'net.peer.port': 3307,
40+
}),
41+
status: 'ok',
42+
description: 'insert into `User` (`email`, `name`) values (?, ?)',
43+
origin: 'auto.db.otel.knex',
44+
}),
45+
46+
expect.objectContaining({
47+
data: expect.objectContaining({
48+
'knex.version': KNEX_VERSION,
49+
'db.operation': 'select',
50+
'db.sql.table': 'User',
51+
'db.system': 'mysql2',
52+
'db.name': 'tests',
53+
'db.statement': 'select * from `User`',
54+
'db.user': 'root',
55+
'sentry.origin': 'auto.db.otel.knex',
56+
'sentry.op': 'db',
57+
}),
58+
status: 'ok',
59+
description: 'select * from `User`',
60+
origin: 'auto.db.otel.knex',
61+
}),
62+
]),
63+
};
64+
65+
await createRunner()
66+
.withDockerCompose({ workingDirectory: [__dirname], readyMatches: ['port: 3306'] })
67+
.expect({ transaction: EXPECTED_TRANSACTION })
68+
.start()
69+
.completed();
70+
});
71+
});
72+
});
73+
});

dev-packages/node-integration-tests/suites/tracing/knex/docker-compose.yml renamed to dev-packages/node-integration-tests/suites/tracing/knex/pg/docker-compose.yml

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,3 @@ services:
1111
POSTGRES_USER: test
1212
POSTGRES_PASSWORD: test
1313
POSTGRES_DB: tests
14-
15-
db_mysql2:
16-
image: mysql:8
17-
restart: always
18-
container_name: integration-tests-knex-mysql2
19-
ports:
20-
- '3307:3306'
21-
environment:
22-
MYSQL_ROOT_PASSWORD: docker
23-
MYSQL_DATABASE: tests
File renamed without changes.
File renamed without changes.
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
import { describe, expect } from 'vitest';
2+
import { createEsmAndCjsTests } from '../../../../utils/runner';
3+
4+
describe('knex auto instrumentation', () => {
5+
// Update this if another knex version is installed
6+
const KNEX_VERSION = '2.5.1';
7+
8+
describe('with `pg` client', () => {
9+
createEsmAndCjsTests(__dirname, 'scenario.mjs', 'instrument.mjs', (createRunner, test) => {
10+
test('should auto-instrument `knex` package', { timeout: 60_000 }, async () => {
11+
const EXPECTED_TRANSACTION = {
12+
transaction: 'Test Transaction',
13+
spans: expect.arrayContaining([
14+
expect.objectContaining({
15+
data: expect.objectContaining({
16+
'knex.version': KNEX_VERSION,
17+
'db.system': 'postgresql',
18+
'db.name': 'tests',
19+
'sentry.origin': 'auto.db.otel.knex',
20+
'sentry.op': 'db',
21+
'net.peer.name': 'localhost',
22+
'net.peer.port': 5445,
23+
}),
24+
status: 'ok',
25+
description:
26+
'create table "User" ("id" serial primary key, "createdAt" timestamptz(3) not null default CURRENT_TIMESTAMP(3), "email" text not null, "name" text not null)',
27+
origin: 'auto.db.otel.knex',
28+
}),
29+
expect.objectContaining({
30+
data: expect.objectContaining({
31+
'knex.version': KNEX_VERSION,
32+
'db.system': 'postgresql',
33+
'db.name': 'tests',
34+
'sentry.origin': 'auto.db.otel.knex',
35+
'sentry.op': 'db',
36+
'net.peer.name': 'localhost',
37+
'net.peer.port': 5445,
38+
}),
39+
status: 'ok',
40+
// In the knex-otel spans, the placeholders (e.g., `$1`) are replaced by a `?`.
41+
description: 'insert into "User" ("email", "name") values (?, ?)',
42+
origin: 'auto.db.otel.knex',
43+
}),
44+
45+
expect.objectContaining({
46+
data: expect.objectContaining({
47+
'knex.version': KNEX_VERSION,
48+
'db.operation': 'select',
49+
'db.sql.table': 'User',
50+
'db.system': 'postgresql',
51+
'db.name': 'tests',
52+
'db.statement': 'select * from "User"',
53+
'sentry.origin': 'auto.db.otel.knex',
54+
'sentry.op': 'db',
55+
}),
56+
status: 'ok',
57+
description: 'select * from "User"',
58+
origin: 'auto.db.otel.knex',
59+
}),
60+
]),
61+
};
62+
63+
await createRunner()
64+
.withDockerCompose({ workingDirectory: [__dirname], readyMatches: ['port 5432'] })
65+
.expect({ transaction: EXPECTED_TRANSACTION })
66+
.start()
67+
.completed();
68+
});
69+
});
70+
});
71+
});

dev-packages/node-integration-tests/suites/tracing/knex/test.ts

Lines changed: 0 additions & 137 deletions
This file was deleted.

0 commit comments

Comments
 (0)