Skip to content

Commit

Permalink
Tedious - service naming (#3061)
Browse files Browse the repository at this point in the history
* add v0 naming to tedious (mssql)
* add v1 naming to tedious (mssql)
* switch to a mostly working test sqlserver

  The standard mssql server image does not work on ARM [1].

  Instead, we use `azure-sql-edge` [2], which provides a sufficient subset
  of mssql server API to test most of our integration. 

  Unfortunately, this image does not support stored procedures [3], so
  tests related to these will still fail locally.

  [1] microsoft/mssql-docker#668
  [2] https://hub.docker.com/_/microsoft-azure-sql-edge
  [3] https://learn.microsoft.com/en-us/azure/azure-sql-edge/features#unsupported-features
  • Loading branch information
jbertran authored and tlhunter committed Jun 23, 2023
1 parent 377114b commit 52f4fd7
Show file tree
Hide file tree
Showing 6 changed files with 49 additions and 25 deletions.
5 changes: 4 additions & 1 deletion docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,10 @@ services:
ports:
- "127.0.0.1:5432:5432"
mssql:
image: mcr.microsoft.com/mssql/server:2017-latest-ubuntu
# A working MSSQL server is not available on ARM.
# This image provides _most_ of sqlserver functionalities, but
# does not support stored procedures (corresponding tests will fail)
image: mcr.microsoft.com/mssql/azure-sql-edge
environment:
- "ACCEPT_EULA=Y"
- "SA_PASSWORD=DD_HUNTER2"
Expand Down
4 changes: 2 additions & 2 deletions packages/datadog-plugin-tedious/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ class TediousPlugin extends DatabasePlugin {
static get system () { return 'mssql' }

start ({ queryOrProcedure, connectionConfig }) {
this.startSpan('tedious.request', {
service: this.config.service,
this.startSpan(this.operationName(), {
service: this.serviceName(this.config, this.system),
resource: queryOrProcedure,
type: 'sql',
kind: 'client',
Expand Down
45 changes: 29 additions & 16 deletions packages/datadog-plugin-tedious/test/index.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
const agent = require('../../dd-trace/test/plugins/agent')
const semver = require('semver')
const { ERROR_MESSAGE, ERROR_TYPE, ERROR_STACK } = require('../../dd-trace/src/constants')
const namingSchema = require('./naming')

const MSSQL_USERNAME = 'sa'
const MSSQL_PASSWORD = 'DD_HUNTER2'
Expand Down Expand Up @@ -71,6 +72,18 @@ describe('Plugin', () => {
}
})

withNamingSchema(
done => {
const query = 'SELECT 1 + 1 AS solution'
const request = new tds.Request(query, (err) => {
if (err) return done(err)
})
connection.execSql(request)
},
() => namingSchema.client.opName,
() => namingSchema.client.serviceName
)

describe('with tedious disabled', () => {
beforeEach(() => {
tracer.use('tedious', false)
Expand Down Expand Up @@ -123,8 +136,8 @@ describe('Plugin', () => {

const promise = agent
.use(traces => {
expect(traces[0][0]).to.have.property('name', 'tedious.request')
expect(traces[0][0]).to.have.property('service', 'test-mssql')
expect(traces[0][0]).to.have.property('name', namingSchema.client.opName)
expect(traces[0][0]).to.have.property('service', namingSchema.client.serviceName)
expect(traces[0][0]).to.have.property('resource', query)
expect(traces[0][0]).to.have.property('type', 'sql')
expect(traces[0][0].meta).to.have.property('component', 'tedious')
Expand All @@ -148,8 +161,8 @@ describe('Plugin', () => {

const promise = agent
.use(traces => {
expect(traces[0][0]).to.have.property('name', 'tedious.request')
expect(traces[0][0]).to.have.property('service', 'test-mssql')
expect(traces[0][0]).to.have.property('name', namingSchema.client.opName)
expect(traces[0][0]).to.have.property('service', namingSchema.client.serviceName)
expect(traces[0][0]).to.have.property('resource', query)
})

Expand All @@ -167,8 +180,8 @@ describe('Plugin', () => {

const promise = agent
.use(traces => {
expect(traces[0][0]).to.have.property('name', 'tedious.request')
expect(traces[0][0]).to.have.property('service', 'test-mssql')
expect(traces[0][0]).to.have.property('name', namingSchema.client.opName)
expect(traces[0][0]).to.have.property('service', namingSchema.client.serviceName)
expect(traces[0][0]).to.have.property('resource', query)
})

Expand All @@ -184,8 +197,8 @@ describe('Plugin', () => {

agent
.use(traces => {
expect(traces[0][0]).to.have.property('name', 'tedious.request')
expect(traces[0][0]).to.have.property('service', 'test-mssql')
expect(traces[0][0]).to.have.property('name', namingSchema.client.opName)
expect(traces[0][0]).to.have.property('service', namingSchema.client.serviceName)
expect(traces[0][0]).to.have.property('resource', query)
})
.then(done)
Expand All @@ -202,8 +215,8 @@ describe('Plugin', () => {

const promise = agent
.use(traces => {
expect(traces[0][0]).to.have.property('name', 'tedious.request')
expect(traces[0][0]).to.have.property('service', 'test-mssql')
expect(traces[0][0]).to.have.property('name', namingSchema.client.opName)
expect(traces[0][0]).to.have.property('service', namingSchema.client.serviceName)
expect(traces[0][0]).to.have.property('resource', query)
})

Expand All @@ -223,8 +236,8 @@ describe('Plugin', () => {

const promise = agent
.use(traces => {
expect(traces[0][0]).to.have.property('name', 'tedious.request')
expect(traces[0][0]).to.have.property('service', 'test-mssql')
expect(traces[0][0]).to.have.property('name', namingSchema.client.opName)
expect(traces[0][0]).to.have.property('service', namingSchema.client.serviceName)
expect(traces[0][0]).to.have.property('resource', query)
})

Expand All @@ -244,8 +257,8 @@ describe('Plugin', () => {

const promise = agent
.use(traces => {
expect(traces[0][0]).to.have.property('name', 'tedious.request')
expect(traces[0][0]).to.have.property('service', 'test-mssql')
expect(traces[0][0]).to.have.property('name', namingSchema.client.opName)
expect(traces[0][0]).to.have.property('service', namingSchema.client.serviceName)
expect(traces[0][0]).to.have.property('resource', procedure)
})

Expand Down Expand Up @@ -335,7 +348,7 @@ describe('Plugin', () => {

agent
.use(traces => {
expect(traces[0][0]).to.have.property('name', 'tedious.request')
expect(traces[0][0]).to.have.property('name', namingSchema.client.opName)
expect(traces[0][0]).to.have.property('resource', bulkLoad.getBulkInsertSql())
})
.then(done)
Expand All @@ -351,7 +364,7 @@ describe('Plugin', () => {

const promise = agent
.use(traces => {
expect(traces[0][0]).to.have.property('name', 'tedious.request')
expect(traces[0][0]).to.have.property('name', namingSchema.client.opName)
expect(traces[0][0]).to.have.property('resource', bulkLoad.getBulkInsertSql())
})

Expand Down
8 changes: 4 additions & 4 deletions packages/datadog-plugin-tedious/test/naming.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
const { namingResolver } = require('../../dd-trace/test/plugins/helpers')
const { resolveNaming } = require('../../dd-trace/test/plugins/helpers')

module.exports = namingResolver({
outbound: {
module.exports = resolveNaming({
client: {
v0: {
opName: 'tedious.request',
serviceName: 'test-mssql'
},
v1: {
opName: 'sqlserver.query',
opName: 'mssql.query',
serviceName: 'test'
}
}
Expand Down
6 changes: 5 additions & 1 deletion packages/dd-trace/src/service-naming/schemas/v0/storage.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,11 @@ const storage = {
opName: () => 'memcached.command',
serviceName: (service, config, system) => config.service || fromSystem(service, system)
},
redis: redisConfig
redis: redisConfig,
tedious: {
opName: () => 'tedious.request',
serviceName: (service, config, system) => config.service || fromSystem(service, system)
}
}
}

Expand Down
6 changes: 5 additions & 1 deletion packages/dd-trace/src/service-naming/schemas/v1/storage.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,11 @@ const storage = {
opName: () => 'memcached.command',
serviceName: configWithFallback
},
redis: redisNaming
redis: redisNaming,
tedious: {
opName: () => 'mssql.query',
serviceName: configWithFallback
}
}
}

Expand Down

0 comments on commit 52f4fd7

Please sign in to comment.