Skip to content

Commit 33a4eb9

Browse files
author
Jordi Bertran de Balanda
committed
add tests on v1 for mysql databases
1 parent 17c2a36 commit 33a4eb9

File tree

6 files changed

+70
-10
lines changed

6 files changed

+70
-10
lines changed

packages/datadog-plugin-mariadb/test/index.spec.js

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ const agent = require('../../dd-trace/test/plugins/agent')
55
const proxyquire = require('proxyquire').noPreserveCache()
66
const { ERROR_MESSAGE, ERROR_TYPE, ERROR_STACK } = require('../../dd-trace/src/constants')
77

8+
const namingSchema = require('./naming')
9+
810
// https://github.com/mariadb-corporation/mariadb-connector-nodejs/commit/0a90b71ab20ab4e8b6a86a77ba291bba8ba6a34e
911
const range = semver.gte(process.version, '15.0.0') ? '>=2.5.1' : '>=2'
1012

@@ -86,7 +88,8 @@ describe('Plugin', () => {
8688
it('should do automatic instrumentation', done => {
8789
agent
8890
.use(traces => {
89-
expect(traces[0][0]).to.have.property('service', 'test-mariadb')
91+
expect(traces[0][0]).to.have.property('name', namingSchema.outbound.opName)
92+
expect(traces[0][0]).to.have.property('service', namingSchema.outbound.serviceName)
9093
expect(traces[0][0]).to.have.property('resource', 'SELECT 1 + 1 AS solution')
9194
expect(traces[0][0]).to.have.property('type', 'sql')
9295
expect(traces[0][0].meta).to.have.property('span.kind', 'client')
@@ -108,7 +111,8 @@ describe('Plugin', () => {
108111
it('should support prepared statement shorthand', done => {
109112
agent
110113
.use(traces => {
111-
expect(traces[0][0]).to.have.property('service', 'test-mariadb')
114+
expect(traces[0][0]).to.have.property('name', namingSchema.outbound.opName)
115+
expect(traces[0][0]).to.have.property('service', namingSchema.outbound.serviceName)
112116
expect(traces[0][0]).to.have.property('resource', 'SELECT ? + ? AS solution')
113117
expect(traces[0][0]).to.have.property('type', 'sql')
114118
expect(traces[0][0].meta).to.have.property('span.kind', 'client')
@@ -129,7 +133,8 @@ describe('Plugin', () => {
129133
it('should support prepared statements', done => {
130134
agent
131135
.use(traces => {
132-
expect(traces[0][0]).to.have.property('service', 'test-mariadb')
136+
expect(traces[0][0]).to.have.property('name', namingSchema.outbound.opName)
137+
expect(traces[0][0]).to.have.property('service', namingSchema.outbound.serviceName)
133138
expect(traces[0][0]).to.have.property('resource', 'SELECT ? + ? AS solution')
134139
expect(traces[0][0]).to.have.property('type', 'sql')
135140
expect(traces[0][0].meta).to.have.property('span.kind', 'client')
@@ -293,7 +298,8 @@ describe('Plugin', () => {
293298
it('should do automatic instrumentation', done => {
294299
agent
295300
.use(traces => {
296-
expect(traces[0][0]).to.have.property('service', 'test-mariadb')
301+
expect(traces[0][0]).to.have.property('name', namingSchema.outbound.opName)
302+
expect(traces[0][0]).to.have.property('service', namingSchema.outbound.serviceName)
297303
expect(traces[0][0]).to.have.property('resource', 'SELECT 1 + 1 AS solution')
298304
expect(traces[0][0]).to.have.property('type', 'sql')
299305
expect(traces[0][0].meta).to.have.property('span.kind', 'client')
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
const { resolveNaming } = require('../../dd-trace/test/plugins/helpers')
2+
3+
module.exports = resolveNaming({
4+
outbound: {
5+
v0: {
6+
opName: 'mariadb.query',
7+
serviceName: 'test-mariadb'
8+
},
9+
v1: {
10+
opName: 'mariadb.query',
11+
serviceName: 'test'
12+
}
13+
}
14+
})

packages/datadog-plugin-mysql/test/index.spec.js

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ const agent = require('../../dd-trace/test/plugins/agent')
44
const proxyquire = require('proxyquire').noPreserveCache()
55
const { ERROR_MESSAGE, ERROR_TYPE, ERROR_STACK } = require('../../dd-trace/src/constants')
66

7+
const namingSchema = require('./naming')
8+
79
describe('Plugin', () => {
810
let mysql
911
let tracer
@@ -67,7 +69,8 @@ describe('Plugin', () => {
6769

6870
it('should do automatic instrumentation', done => {
6971
agent.use(traces => {
70-
expect(traces[0][0]).to.have.property('service', 'test-mysql')
72+
expect(traces[0][0]).to.have.property('name', namingSchema.outbound.opName)
73+
expect(traces[0][0]).to.have.property('service', namingSchema.outbound.serviceName)
7174
expect(traces[0][0]).to.have.property('resource', 'SELECT 1 + 1 AS solution')
7275
expect(traces[0][0]).to.have.property('type', 'sql')
7376
expect(traces[0][0].meta).to.have.property('span.kind', 'client')
@@ -134,6 +137,7 @@ describe('Plugin', () => {
134137

135138
it('should be configured with the correct values', done => {
136139
agent.use(traces => {
140+
expect(traces[0][0]).to.have.property('name', namingSchema.outbound.opName)
137141
expect(traces[0][0]).to.have.property('service', 'custom')
138142
done()
139143
})
@@ -167,6 +171,7 @@ describe('Plugin', () => {
167171

168172
it('should be configured with the correct values', done => {
169173
agent.use(traces => {
174+
expect(traces[0][0]).to.have.property('name', namingSchema.outbound.opName)
170175
expect(traces[0][0]).to.have.property('service', 'custom')
171176
sinon.assert.calledWith(serviceSpy, sinon.match({
172177
host: 'localhost',
@@ -203,7 +208,8 @@ describe('Plugin', () => {
203208

204209
it('should do automatic instrumentation', done => {
205210
agent.use(traces => {
206-
expect(traces[0][0]).to.have.property('service', 'test-mysql')
211+
expect(traces[0][0]).to.have.property('name', namingSchema.outbound.opName)
212+
expect(traces[0][0]).to.have.property('service', namingSchema.outbound.serviceName)
207213
expect(traces[0][0]).to.have.property('resource', 'SELECT 1 + 1 AS solution')
208214
expect(traces[0][0]).to.have.property('type', 'sql')
209215
expect(traces[0][0].meta).to.have.property('span.kind', 'client')
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
const { resolveNaming } = require('../../dd-trace/test/plugins/helpers')
2+
3+
module.exports = resolveNaming({
4+
outbound: {
5+
v0: {
6+
opName: 'mysql.query',
7+
serviceName: 'test-mysql'
8+
},
9+
v1: {
10+
opName: 'mysql.query',
11+
serviceName: 'test'
12+
}
13+
}
14+
})

packages/datadog-plugin-mysql2/test/index.spec.js

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ const agent = require('../../dd-trace/test/plugins/agent')
44
const proxyquire = require('proxyquire').noPreserveCache()
55
const { ERROR_MESSAGE, ERROR_TYPE, ERROR_STACK } = require('../../dd-trace/src/constants')
66

7+
const namingSchema = require('./naming')
8+
79
describe('Plugin', () => {
810
let mysql2
911
let tracer
@@ -74,7 +76,8 @@ describe('Plugin', () => {
7476
it('should do automatic instrumentation', done => {
7577
agent
7678
.use(traces => {
77-
expect(traces[0][0]).to.have.property('service', 'test-mysql')
79+
expect(traces[0][0]).to.have.property('name', namingSchema.outbound.opName)
80+
expect(traces[0][0]).to.have.property('service', namingSchema.outbound.serviceName)
7881
expect(traces[0][0]).to.have.property('resource', 'SELECT 1 + 1 AS solution')
7982
expect(traces[0][0]).to.have.property('type', 'sql')
8083
expect(traces[0][0].meta).to.have.property('span.kind', 'client')
@@ -94,7 +97,8 @@ describe('Plugin', () => {
9497
it('should support prepared statement shorthand', done => {
9598
agent
9699
.use(traces => {
97-
expect(traces[0][0]).to.have.property('service', 'test-mysql')
100+
expect(traces[0][0]).to.have.property('name', namingSchema.outbound.opName)
101+
expect(traces[0][0]).to.have.property('service', namingSchema.outbound.serviceName)
98102
expect(traces[0][0]).to.have.property('resource', 'SELECT ? + ? AS solution')
99103
expect(traces[0][0]).to.have.property('type', 'sql')
100104
expect(traces[0][0].meta).to.have.property('span.kind', 'client')
@@ -116,7 +120,8 @@ describe('Plugin', () => {
116120
it('should support prepared statements', done => {
117121
agent
118122
.use(traces => {
119-
expect(traces[0][0]).to.have.property('service', 'test-mysql')
123+
expect(traces[0][0]).to.have.property('name', namingSchema.outbound.opName)
124+
expect(traces[0][0]).to.have.property('service', namingSchema.outbound.serviceName)
120125
expect(traces[0][0]).to.have.property('resource', 'SELECT ? + ? AS solution')
121126
expect(traces[0][0]).to.have.property('type', 'sql')
122127
expect(traces[0][0].meta).to.have.property('span.kind', 'client')
@@ -262,7 +267,8 @@ describe('Plugin', () => {
262267
it('should do automatic instrumentation', done => {
263268
agent
264269
.use(traces => {
265-
expect(traces[0][0]).to.have.property('service', 'test-mysql')
270+
expect(traces[0][0]).to.have.property('name', namingSchema.outbound.opName)
271+
expect(traces[0][0]).to.have.property('service', namingSchema.outbound.serviceName)
266272
expect(traces[0][0]).to.have.property('resource', 'SELECT 1 + 1 AS solution')
267273
expect(traces[0][0]).to.have.property('type', 'sql')
268274
expect(traces[0][0].meta).to.have.property('span.kind', 'client')
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
const { resolveNaming } = require('../../dd-trace/test/plugins/helpers')
2+
3+
module.exports = resolveNaming({
4+
outbound: {
5+
v0: {
6+
opName: 'mysql.query',
7+
serviceName: 'test-mysql'
8+
},
9+
v1: {
10+
opName: 'mysql.query',
11+
serviceName: 'test'
12+
}
13+
}
14+
})

0 commit comments

Comments
 (0)