Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Tedious - service naming #3061

Merged
merged 3 commits into from
Jun 14, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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
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