Skip to content

Commit

Permalink
add tests on v1 for mysql databases
Browse files Browse the repository at this point in the history
  • Loading branch information
Jordi Bertran de Balanda committed May 23, 2023
1 parent 3f95900 commit 3744c6a
Show file tree
Hide file tree
Showing 6 changed files with 70 additions and 10 deletions.
14 changes: 10 additions & 4 deletions packages/datadog-plugin-mariadb/test/index.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ const agent = require('../../dd-trace/test/plugins/agent')
const proxyquire = require('proxyquire').noPreserveCache()
const { ERROR_MESSAGE, ERROR_TYPE, ERROR_STACK } = require('../../dd-trace/src/constants')

const namingSchema = require('./naming')

// https://github.com/mariadb-corporation/mariadb-connector-nodejs/commit/0a90b71ab20ab4e8b6a86a77ba291bba8ba6a34e
const range = semver.gte(process.version, '15.0.0') ? '>=2.5.1' : '>=2'

Expand Down Expand Up @@ -86,7 +88,8 @@ describe('Plugin', () => {
it('should do automatic instrumentation', done => {
agent
.use(traces => {
expect(traces[0][0]).to.have.property('service', 'test-mariadb')
expect(traces[0][0]).to.have.property('name', namingSchema.outbound.opName)
expect(traces[0][0]).to.have.property('service', namingSchema.outbound.serviceName)
expect(traces[0][0]).to.have.property('resource', 'SELECT 1 + 1 AS solution')
expect(traces[0][0]).to.have.property('type', 'sql')
expect(traces[0][0].meta).to.have.property('span.kind', 'client')
Expand All @@ -108,7 +111,8 @@ describe('Plugin', () => {
it('should support prepared statement shorthand', done => {
agent
.use(traces => {
expect(traces[0][0]).to.have.property('service', 'test-mariadb')
expect(traces[0][0]).to.have.property('name', namingSchema.outbound.opName)
expect(traces[0][0]).to.have.property('service', namingSchema.outbound.serviceName)
expect(traces[0][0]).to.have.property('resource', 'SELECT ? + ? AS solution')
expect(traces[0][0]).to.have.property('type', 'sql')
expect(traces[0][0].meta).to.have.property('span.kind', 'client')
Expand All @@ -129,7 +133,8 @@ describe('Plugin', () => {
it('should support prepared statements', done => {
agent
.use(traces => {
expect(traces[0][0]).to.have.property('service', 'test-mariadb')
expect(traces[0][0]).to.have.property('name', namingSchema.outbound.opName)
expect(traces[0][0]).to.have.property('service', namingSchema.outbound.serviceName)
expect(traces[0][0]).to.have.property('resource', 'SELECT ? + ? AS solution')
expect(traces[0][0]).to.have.property('type', 'sql')
expect(traces[0][0].meta).to.have.property('span.kind', 'client')
Expand Down Expand Up @@ -293,7 +298,8 @@ describe('Plugin', () => {
it('should do automatic instrumentation', done => {
agent
.use(traces => {
expect(traces[0][0]).to.have.property('service', 'test-mariadb')
expect(traces[0][0]).to.have.property('name', namingSchema.outbound.opName)
expect(traces[0][0]).to.have.property('service', namingSchema.outbound.serviceName)
expect(traces[0][0]).to.have.property('resource', 'SELECT 1 + 1 AS solution')
expect(traces[0][0]).to.have.property('type', 'sql')
expect(traces[0][0].meta).to.have.property('span.kind', 'client')
Expand Down
14 changes: 14 additions & 0 deletions packages/datadog-plugin-mariadb/test/naming.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
const { resolveNaming } = require('../../dd-trace/test/plugins/helpers')

module.exports = resolveNaming({
outbound: {
v0: {
opName: 'mariadb.query',
serviceName: 'test-mariadb'
},
v1: {
opName: 'mariadb.query',
serviceName: 'test'
}
}
})
10 changes: 8 additions & 2 deletions packages/datadog-plugin-mysql/test/index.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ const agent = require('../../dd-trace/test/plugins/agent')
const proxyquire = require('proxyquire').noPreserveCache()
const { ERROR_MESSAGE, ERROR_TYPE, ERROR_STACK } = require('../../dd-trace/src/constants')

const namingSchema = require('./naming')

describe('Plugin', () => {
let mysql
let tracer
Expand Down Expand Up @@ -67,7 +69,8 @@ describe('Plugin', () => {

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

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

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

it('should do automatic instrumentation', done => {
agent.use(traces => {
expect(traces[0][0]).to.have.property('service', 'test-mysql')
expect(traces[0][0]).to.have.property('name', namingSchema.outbound.opName)
expect(traces[0][0]).to.have.property('service', namingSchema.outbound.serviceName)
expect(traces[0][0]).to.have.property('resource', 'SELECT 1 + 1 AS solution')
expect(traces[0][0]).to.have.property('type', 'sql')
expect(traces[0][0].meta).to.have.property('span.kind', 'client')
Expand Down
14 changes: 14 additions & 0 deletions packages/datadog-plugin-mysql/test/naming.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
const { resolveNaming } = require('../../dd-trace/test/plugins/helpers')

module.exports = resolveNaming({
outbound: {
v0: {
opName: 'mysql.query',
serviceName: 'test-mysql'
},
v1: {
opName: 'mysql.query',
serviceName: 'test'
}
}
})
14 changes: 10 additions & 4 deletions packages/datadog-plugin-mysql2/test/index.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ const agent = require('../../dd-trace/test/plugins/agent')
const proxyquire = require('proxyquire').noPreserveCache()
const { ERROR_MESSAGE, ERROR_TYPE, ERROR_STACK } = require('../../dd-trace/src/constants')

const namingSchema = require('./naming')

describe('Plugin', () => {
let mysql2
let tracer
Expand Down Expand Up @@ -74,7 +76,8 @@ describe('Plugin', () => {
it('should do automatic instrumentation', done => {
agent
.use(traces => {
expect(traces[0][0]).to.have.property('service', 'test-mysql')
expect(traces[0][0]).to.have.property('name', namingSchema.outbound.opName)
expect(traces[0][0]).to.have.property('service', namingSchema.outbound.serviceName)
expect(traces[0][0]).to.have.property('resource', 'SELECT 1 + 1 AS solution')
expect(traces[0][0]).to.have.property('type', 'sql')
expect(traces[0][0].meta).to.have.property('span.kind', 'client')
Expand All @@ -94,7 +97,8 @@ describe('Plugin', () => {
it('should support prepared statement shorthand', done => {
agent
.use(traces => {
expect(traces[0][0]).to.have.property('service', 'test-mysql')
expect(traces[0][0]).to.have.property('name', namingSchema.outbound.opName)
expect(traces[0][0]).to.have.property('service', namingSchema.outbound.serviceName)
expect(traces[0][0]).to.have.property('resource', 'SELECT ? + ? AS solution')
expect(traces[0][0]).to.have.property('type', 'sql')
expect(traces[0][0].meta).to.have.property('span.kind', 'client')
Expand All @@ -116,7 +120,8 @@ describe('Plugin', () => {
it('should support prepared statements', done => {
agent
.use(traces => {
expect(traces[0][0]).to.have.property('service', 'test-mysql')
expect(traces[0][0]).to.have.property('name', namingSchema.outbound.opName)
expect(traces[0][0]).to.have.property('service', namingSchema.outbound.serviceName)
expect(traces[0][0]).to.have.property('resource', 'SELECT ? + ? AS solution')
expect(traces[0][0]).to.have.property('type', 'sql')
expect(traces[0][0].meta).to.have.property('span.kind', 'client')
Expand Down Expand Up @@ -262,7 +267,8 @@ describe('Plugin', () => {
it('should do automatic instrumentation', done => {
agent
.use(traces => {
expect(traces[0][0]).to.have.property('service', 'test-mysql')
expect(traces[0][0]).to.have.property('name', namingSchema.outbound.opName)
expect(traces[0][0]).to.have.property('service', namingSchema.outbound.serviceName)
expect(traces[0][0]).to.have.property('resource', 'SELECT 1 + 1 AS solution')
expect(traces[0][0]).to.have.property('type', 'sql')
expect(traces[0][0].meta).to.have.property('span.kind', 'client')
Expand Down
14 changes: 14 additions & 0 deletions packages/datadog-plugin-mysql2/test/naming.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
const { resolveNaming } = require('../../dd-trace/test/plugins/helpers')

module.exports = resolveNaming({
outbound: {
v0: {
opName: 'mysql.query',
serviceName: 'test-mysql'
},
v1: {
opName: 'mysql.query',
serviceName: 'test'
}
}
})

0 comments on commit 3744c6a

Please sign in to comment.