Skip to content

Commit c0e5504

Browse files
AbhiPrasadmydea
andauthored
feat(tracing): Add db.system span data to DB spans (#7952)
Co-authored-by: Francesco Novy <[email protected]>
1 parent 0161cdd commit c0e5504

File tree

16 files changed

+74
-9
lines changed

16 files changed

+74
-9
lines changed

packages/node-integration-tests/suites/tracing-new/auto-instrument/mongodb/test.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ conditionalTest({ min: 12 })('MongoDB Test', () => {
3434
dbName: 'admin',
3535
namespace: 'admin.movies',
3636
doc: '{"title":"Rick and Morty"}',
37+
'db.system': 'mongodb',
3738
},
3839
description: 'insertOne',
3940
op: 'db',
@@ -44,6 +45,7 @@ conditionalTest({ min: 12 })('MongoDB Test', () => {
4445
dbName: 'admin',
4546
namespace: 'admin.movies',
4647
query: '{"title":"Back to the Future"}',
48+
'db.system': 'mongodb',
4749
},
4850
description: 'findOne',
4951
op: 'db',
@@ -55,6 +57,7 @@ conditionalTest({ min: 12 })('MongoDB Test', () => {
5557
namespace: 'admin.movies',
5658
filter: '{"title":"Back to the Future"}',
5759
update: '{"$set":{"title":"South Park"}}',
60+
'db.system': 'mongodb',
5861
},
5962
description: 'updateOne',
6063
op: 'db',
@@ -65,6 +68,7 @@ conditionalTest({ min: 12 })('MongoDB Test', () => {
6568
dbName: 'admin',
6669
namespace: 'admin.movies',
6770
query: '{"title":"South Park"}',
71+
'db.system': 'mongodb',
6872
},
6973
description: 'findOne',
7074
op: 'db',
@@ -75,6 +79,7 @@ conditionalTest({ min: 12 })('MongoDB Test', () => {
7579
dbName: 'admin',
7680
namespace: 'admin.movies',
7781
query: '{"title":"South Park"}',
82+
'db.system': 'mongodb',
7883
},
7984
description: 'find',
8085
op: 'db',

packages/node-integration-tests/suites/tracing-new/auto-instrument/mysql/test.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,17 @@ test('should auto-instrument `mysql` package.', async () => {
1212
{
1313
description: 'SELECT 1 + 1 AS solution',
1414
op: 'db',
15+
data: {
16+
'db.system': 'mysql',
17+
},
1518
},
1619

1720
{
1821
description: 'SELECT NOW()',
1922
op: 'db',
23+
data: {
24+
'db.system': 'mysql',
25+
},
2026
},
2127
],
2228
});

packages/node-integration-tests/suites/tracing-new/auto-instrument/pg/test.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,14 +40,23 @@ test('should auto-instrument `pg` package.', async () => {
4040
{
4141
description: 'SELECT * FROM foo where bar ilike "baz%"',
4242
op: 'db',
43+
data: {
44+
'db.system': 'postgresql',
45+
},
4346
},
4447
{
4548
description: 'SELECT * FROM bazz',
4649
op: 'db',
50+
data: {
51+
'db.system': 'postgresql',
52+
},
4753
},
4854
{
4955
description: 'SELECT NOW()',
5056
op: 'db',
57+
data: {
58+
'db.system': 'postgresql',
59+
},
5160
},
5261
],
5362
});

packages/node-integration-tests/suites/tracing-new/prisma-orm/test.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,9 @@ conditionalTest({ min: 12 })('Prisma ORM Integration', () => {
88
assertSentryTransaction(envelope[2], {
99
transaction: 'Test Transaction',
1010
spans: [
11-
{ description: 'User create', op: 'db.sql.prisma' },
12-
{ description: 'User findMany', op: 'db.sql.prisma' },
13-
{ description: 'User deleteMany', op: 'db.sql.prisma' },
11+
{ description: 'User create', op: 'db.sql.prisma', data: { 'db.system': 'prisma' } },
12+
{ description: 'User findMany', op: 'db.sql.prisma', data: { 'db.system': 'prisma' } },
13+
{ description: 'User deleteMany', op: 'db.sql.prisma', data: { 'db.system': 'prisma' } },
1414
],
1515
});
1616
});

packages/node-integration-tests/suites/tracing/auto-instrument/mongodb/test.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ conditionalTest({ min: 12 })('MongoDB Test', () => {
3434
dbName: 'admin',
3535
namespace: 'admin.movies',
3636
doc: '{"title":"Rick and Morty"}',
37+
'db.system': 'mongodb',
3738
},
3839
description: 'insertOne',
3940
op: 'db',
@@ -44,6 +45,7 @@ conditionalTest({ min: 12 })('MongoDB Test', () => {
4445
dbName: 'admin',
4546
namespace: 'admin.movies',
4647
query: '{"title":"Back to the Future"}',
48+
'db.system': 'mongodb',
4749
},
4850
description: 'findOne',
4951
op: 'db',
@@ -55,6 +57,7 @@ conditionalTest({ min: 12 })('MongoDB Test', () => {
5557
namespace: 'admin.movies',
5658
filter: '{"title":"Back to the Future"}',
5759
update: '{"$set":{"title":"South Park"}}',
60+
'db.system': 'mongodb',
5861
},
5962
description: 'updateOne',
6063
op: 'db',
@@ -65,6 +68,7 @@ conditionalTest({ min: 12 })('MongoDB Test', () => {
6568
dbName: 'admin',
6669
namespace: 'admin.movies',
6770
query: '{"title":"South Park"}',
71+
'db.system': 'mongodb',
6872
},
6973
description: 'findOne',
7074
op: 'db',
@@ -75,6 +79,7 @@ conditionalTest({ min: 12 })('MongoDB Test', () => {
7579
dbName: 'admin',
7680
namespace: 'admin.movies',
7781
query: '{"title":"South Park"}',
82+
'db.system': 'mongodb',
7883
},
7984
description: 'find',
8085
op: 'db',

packages/node-integration-tests/suites/tracing/auto-instrument/mysql/test.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,17 @@ test('should auto-instrument `mysql` package.', async () => {
1212
{
1313
description: 'SELECT 1 + 1 AS solution',
1414
op: 'db',
15+
data: {
16+
'db.system': 'mysql',
17+
},
1518
},
1619

1720
{
1821
description: 'SELECT NOW()',
1922
op: 'db',
23+
data: {
24+
'db.system': 'mysql',
25+
},
2026
},
2127
],
2228
});

packages/node-integration-tests/suites/tracing/auto-instrument/pg/test.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,14 +40,23 @@ test('should auto-instrument `pg` package.', async () => {
4040
{
4141
description: 'SELECT * FROM foo where bar ilike "baz%"',
4242
op: 'db',
43+
data: {
44+
'db.system': 'postgresql',
45+
},
4346
},
4447
{
4548
description: 'SELECT * FROM bazz',
4649
op: 'db',
50+
data: {
51+
'db.system': 'postgresql',
52+
},
4753
},
4854
{
4955
description: 'SELECT NOW()',
5056
op: 'db',
57+
data: {
58+
'db.system': 'postgresql',
59+
},
5160
},
5261
],
5362
});

packages/node-integration-tests/suites/tracing/prisma-orm/test.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,9 @@ conditionalTest({ min: 12 })('Prisma ORM Integration', () => {
88
assertSentryTransaction(envelope[2], {
99
transaction: 'Test Transaction',
1010
spans: [
11-
{ description: 'User create', op: 'db.sql.prisma' },
12-
{ description: 'User findMany', op: 'db.sql.prisma' },
13-
{ description: 'User deleteMany', op: 'db.sql.prisma' },
11+
{ description: 'User create', op: 'db.sql.prisma', data: { 'db.system': 'prisma' } },
12+
{ description: 'User findMany', op: 'db.sql.prisma', data: { 'db.system': 'prisma' } },
13+
{ description: 'User deleteMany', op: 'db.sql.prisma', data: { 'db.system': 'prisma' } },
1414
],
1515
});
1616
});

packages/tracing-internal/src/extensions.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ function _autoloadDatabaseIntegrations(): void {
2222
const integration = dynamicRequire(module, './node/integrations/mongo') as {
2323
Mongo: IntegrationClass<Integration>;
2424
};
25-
return new integration.Mongo({ mongoose: true });
25+
return new integration.Mongo();
2626
},
2727
mysql() {
2828
const integration = dynamicRequire(module, './node/integrations/mysql') as {

packages/tracing-internal/src/node/integrations/mongo.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -231,6 +231,7 @@ export class Mongo implements LazyLoadedIntegration<MongoModule> {
231231
collectionName: collection.collectionName,
232232
dbName: collection.dbName,
233233
namespace: collection.namespace,
234+
'db.system': 'mongodb',
234235
};
235236
const spanContext: SpanContext = {
236237
op: 'db',

packages/tracing-internal/src/node/integrations/mysql.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,9 @@ export class Mysql implements LazyLoadedIntegration<MysqlConnection> {
5555
const span = parentSpan?.startChild({
5656
description: typeof options === 'string' ? options : (options as { sql: string }).sql,
5757
op: 'db',
58+
data: {
59+
'db.system': 'mysql',
60+
},
5861
});
5962

6063
if (typeof callback === 'function') {

packages/tracing-internal/src/node/integrations/postgres.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,9 @@ export class Postgres implements LazyLoadedIntegration<PGModule> {
7979
const span = parentSpan?.startChild({
8080
description: typeof config === 'string' ? config : (config as { text: string }).text,
8181
op: 'db',
82+
data: {
83+
'db.system': 'postgresql',
84+
},
8285
});
8386

8487
if (typeof callback === 'function') {

packages/tracing-internal/src/node/integrations/prisma.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,10 @@ export class Prisma implements Integration {
9191
this._client.$use((params, next: (params: PrismaMiddlewareParams) => Promise<unknown>) => {
9292
const action = params.action;
9393
const model = params.model;
94-
return trace({ name: model ? `${model} ${action}` : action, op: 'db.sql.prisma' }, () => next(params));
94+
return trace(
95+
{ name: model ? `${model} ${action}` : action, op: 'db.sql.prisma', data: { 'db.system': 'prisma' } },
96+
() => next(params),
97+
);
9598
});
9699
}
97100
}

packages/tracing/test/integrations/node/mongo.test.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@ describe('patchOperation()', () => {
7878
dbName: 'mockedDbName',
7979
doc: JSON.stringify(doc),
8080
namespace: 'mockedNamespace',
81+
'db.system': 'mongodb',
8182
},
8283
op: 'db',
8384
description: 'insertOne',
@@ -96,6 +97,7 @@ describe('patchOperation()', () => {
9697
dbName: 'mockedDbName',
9798
doc: JSON.stringify(doc),
9899
namespace: 'mockedNamespace',
100+
'db.system': 'mongodb',
99101
},
100102
op: 'db',
101103
description: 'insertOne',
@@ -111,6 +113,7 @@ describe('patchOperation()', () => {
111113
collectionName: 'mockedCollectionName',
112114
dbName: 'mockedDbName',
113115
namespace: 'mockedNamespace',
116+
'db.system': 'mongodb',
114117
},
115118
op: 'db',
116119
description: 'initializeOrderedBulkOp',

packages/tracing/test/integrations/node/postgres.test.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,9 @@ describe('setupOnce', () => {
7272
expect(parentSpan.startChild).toBeCalledWith({
7373
description: 'SELECT NOW()',
7474
op: 'db',
75+
data: {
76+
'db.system': 'postgresql',
77+
},
7578
});
7679
expect(childSpan.finish).toBeCalled();
7780
done();
@@ -84,6 +87,9 @@ describe('setupOnce', () => {
8487
expect(parentSpan.startChild).toBeCalledWith({
8588
description: 'SELECT NOW()',
8689
op: 'db',
90+
data: {
91+
'db.system': 'postgresql',
92+
},
8793
});
8894
expect(childSpan.finish).toBeCalled();
8995
done();
@@ -96,6 +102,9 @@ describe('setupOnce', () => {
96102
expect(parentSpan.startChild).toBeCalledWith({
97103
description: 'SELECT NOW()',
98104
op: 'db',
105+
data: {
106+
'db.system': 'postgresql',
107+
},
99108
});
100109
expect(childSpan.finish).toBeCalled();
101110
});

packages/tracing/test/integrations/node/prisma.test.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,10 @@ describe('setupOnce', function () {
5454
it('should add middleware with $use method correctly', done => {
5555
void Client.user.create()?.then(() => {
5656
expect(mockTrace).toHaveBeenCalledTimes(1);
57-
expect(mockTrace).toHaveBeenLastCalledWith({ name: 'user create', op: 'db.sql.prisma' }, expect.any(Function));
57+
expect(mockTrace).toHaveBeenLastCalledWith(
58+
{ name: 'user create', op: 'db.sql.prisma', data: { 'db.system': 'prisma' } },
59+
expect.any(Function),
60+
);
5861
done();
5962
});
6063
});

0 commit comments

Comments
 (0)