Skip to content
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
4 changes: 2 additions & 2 deletions packages/datadog-plugin-grpc/src/client.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ class GrpcClientPlugin extends ClientPlugin {
start ({ metadata, path, type }) {
const metadataFilter = this.config.metadataFilter
const method = getMethodMetadata(path, type)
const span = this.startSpan('grpc.client', {
service: this.config.service,
const span = this.startSpan(this.operationName(), {
service: this.config.service || this.serviceName(),
resource: path,
kind: 'client',
type: 'http',
Expand Down
4 changes: 2 additions & 2 deletions packages/datadog-plugin-grpc/src/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@ class GrpcServerPlugin extends ServerPlugin {
const metadataFilter = this.config.metadataFilter
const childOf = extract(this.tracer, metadata)
const method = getMethodMetadata(name, type)
const span = this.startSpan('grpc.server', {
const span = this.startSpan(this.operationName(), {
childOf,
service: this.config.service,
service: this.config.service || this.serviceName(),
resource: name,
kind: 'server',
type: 'web',
Expand Down
9 changes: 9 additions & 0 deletions packages/datadog-plugin-grpc/test/client.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ const { ERROR_MESSAGE, ERROR_TYPE, ERROR_STACK } = require('../../dd-trace/src/c
const nodeMajor = parseInt(process.versions.node.split('.')[0])
const pkgs = nodeMajor > 14 ? ['@grpc/grpc-js'] : ['grpc', '@grpc/grpc-js']

const namingSchema = require('./naming')

describe('Plugin', () => {
let grpc
let port
Expand Down Expand Up @@ -105,6 +107,13 @@ describe('Plugin', () => {
(done) => client.getUnary({ first: 'foobar' }, () => done()),
'test.TestService', 'rpc.service')

withNamingSchema(
(done) => client.getUnary({ first: 'foobar' }, () => done()),
() => namingSchema.client.opName,
() => namingSchema.client.serviceName,
'test'
)

client.getUnary({ first: 'foobar' }, () => {})
return agent
.use(traces => {
Expand Down
24 changes: 24 additions & 0 deletions packages/datadog-plugin-grpc/test/naming.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
const { resolveNaming } = require('../../dd-trace/test/plugins/helpers')

module.exports = resolveNaming({
client: {
v0: {
opName: 'grpc.client',
serviceName: 'test'
},
v1: {
opName: 'grpc.client.request',
serviceName: 'test'
}
},
server: {
v0: {
opName: 'grpc.server',
serviceName: 'test'
},
v1: {
opName: 'grpc.server.request',
serviceName: 'test'
}
}
})
10 changes: 10 additions & 0 deletions packages/datadog-plugin-grpc/test/server.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,14 @@
const agent = require('../../dd-trace/test/plugins/agent')
const getPort = require('get-port')
const Readable = require('stream').Readable

const { ERROR_MESSAGE, ERROR_TYPE, ERROR_STACK } = require('../../dd-trace/src/constants')

const nodeMajor = parseInt(process.versions.node.split('.')[0])
const pkgs = nodeMajor > 14 ? ['@grpc/grpc-js'] : ['grpc', '@grpc/grpc-js']

const namingSchema = require('./naming')

describe('Plugin', () => {
let grpc
let port
Expand Down Expand Up @@ -80,6 +83,13 @@ describe('Plugin', () => {
getUnary: (_, callback) => callback()
})

withNamingSchema(
(done) => client.getUnary({ first: 'foobar' }, () => done()),
() => namingSchema.server.opName,
() => namingSchema.server.serviceName,
'test'
)

client.getUnary({ first: 'foobar' }, () => {})

return agent
Expand Down
8 changes: 4 additions & 4 deletions packages/datadog-plugin-moleculer/test/index.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ describe('Plugin', () => {
broker.call('math.add', { a: 5, b: 3 }).catch(done)
})
withNamingSchema(
(done) => broker.call('math.add', { a: 5, b: 3 }).then(done, done),
(done) => broker.call('math.add', { a: 5, b: 3 }).catch(done),
() => namingSchema.server.opName,
() => namingSchema.server.serviceName,
'test'
Expand All @@ -112,7 +112,7 @@ describe('Plugin', () => {
})

withNamingSchema(
(done) => broker.call('math.add', { a: 5, b: 3 }).then(done, done),
(done) => broker.call('math.add', { a: 5, b: 3 }).catch(done),
() => namingSchema.server.opName,
() => 'custom',
'custom'
Expand Down Expand Up @@ -167,7 +167,7 @@ describe('Plugin', () => {
})

withNamingSchema(
(done) => broker.call('math.add', { a: 5, b: 3 }).then(done, done),
(done) => broker.call('math.add', { a: 5, b: 3 }).catch(done),
() => namingSchema.client.opName,
() => namingSchema.client.serviceName,
'test'
Expand All @@ -194,7 +194,7 @@ describe('Plugin', () => {
})

withNamingSchema(
(done) => broker.call('math.add', { a: 5, b: 3 }).then(done, done),
(done) => broker.call('math.add', { a: 5, b: 3 }).catch(done),
() => namingSchema.client.opName,
() => 'custom',
'custom'
Expand Down
8 changes: 8 additions & 0 deletions packages/dd-trace/src/service-naming/schemas/v0/web.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,20 @@ const { identityService } = require('../util')

const web = {
client: {
grpc: {
opName: () => 'grpc.client',
serviceName: identityService
},
moleculer: {
opName: () => 'moleculer.call',
serviceName: identityService
}
},
server: {
grpc: {
opName: () => 'grpc.server',
serviceName: identityService
},
moleculer: {
opName: () => 'moleculer.action',
serviceName: identityService
Expand Down
8 changes: 8 additions & 0 deletions packages/dd-trace/src/service-naming/schemas/v1/web.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,20 @@ const { identityService } = require('../util')

const web = {
client: {
grpc: {
opName: () => 'grpc.client.request',
serviceName: identityService
},
moleculer: {
opName: () => 'moleculer.client.request',
serviceName: identityService
}
},
server: {
grpc: {
opName: () => 'grpc.server.request',
serviceName: identityService
},
moleculer: {
opName: () => 'moleculer.server.request',
serviceName: identityService
Expand Down
4 changes: 2 additions & 2 deletions packages/dd-trace/test/setup/mocha.js
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ function withNamingSchema (spanProducerFn, expectedOpName, expectedServiceName,
})
.then(done)
.catch(done)
spanProducerFn()
spanProducerFn(done)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks like a bug? When the .then(done) above calls, it'll execute the done() function. However, when spanProducerFn(done) calls, it will also run done(). Running this function twice results in a test failure. Was it added accidentally?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unless it's explicitly used for the purpose of failing tests and should always have a truthy argument?

})
})
})
Expand All @@ -101,7 +101,7 @@ function withNamingSchema (spanProducerFn, expectedOpName, expectedServiceName,
})
.then(done)
.catch(done)
spanProducerFn()
spanProducerFn(done)
})
})
})
Expand Down