Skip to content

Commit

Permalink
persist kind in plugins and infer controlPlane from messaging clients
Browse files Browse the repository at this point in the history
  • Loading branch information
Jordi Bertran de Balanda committed Apr 25, 2023
1 parent 78b3994 commit a27b9d1
Show file tree
Hide file tree
Showing 7 changed files with 30 additions and 9 deletions.
5 changes: 2 additions & 3 deletions packages/datadog-plugin-amqplib/src/client.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ const { getResourceName } = require('./util')
class AmqplibClientPlugin extends ClientPlugin {
static get id () { return 'amqplib' }
static get type () { return 'messaging' }
static get ioDirection () { return 'controlPlane' }
static get operation () { return 'command' }

start ({ channel = {}, method, fields }) {
Expand All @@ -17,9 +16,9 @@ class AmqplibClientPlugin extends ClientPlugin {

const stream = (channel.connection && channel.connection.stream) || {}
const span = this.startSpan(this.operationName(), {
service: this.config.service || this.serviceName({ service: this.tracer._service }),
service: this.config.service || this.serviceName(),
resource: getResourceName(method, fields),
kind: 'client',
kind: this.constructor.kind,
meta: {
'out.host': stream._host,
[CLIENT_PORT_KEY]: stream.remotePort,
Expand Down
3 changes: 1 addition & 2 deletions packages/datadog-plugin-google-cloud-pubsub/src/client.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ const ClientPlugin = require('../../dd-trace/src/plugins/client')
class GoogleCloudPubsubClientPlugin extends ClientPlugin {
static get id () { return 'google-cloud-pubsub' }
static get type () { return 'messaging' }
static get ioDirection () { return 'controlPlane' }
static get operation () { return 'request' }

start ({ request, api, projectId }) {
Expand All @@ -14,7 +13,7 @@ class GoogleCloudPubsubClientPlugin extends ClientPlugin {
this.startSpan(this.operationName(), {
service: this.config.service || this.serviceName({ service: this.tracer._service }),
resource: [api, request.name].filter(x => x).join(' '),
kind: 'client',
kind: this.constructor.kind,
meta: {
'pubsub.method': api,
'gcloud.project_id': projectId
Expand Down
14 changes: 14 additions & 0 deletions packages/datadog-plugin-tedious/test/naming.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
const { namingResolver } = require('../../dd-trace/test/plugins/helpers')

module.exports = namingResolver({
outbound: {
v0: {
opName: 'tedious.request',
serviceName: 'test-mssql'
},
v1: {
opName: 'sqlserver.query',
serviceName: 'test'
}
}
})
1 change: 1 addition & 0 deletions packages/dd-trace/src/plugins/client.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ const OutboundPlugin = require('./outbound')

class ClientPlugin extends OutboundPlugin {
static get operation () { return 'request' }
static get kind () { return 'client' }
}

module.exports = ClientPlugin
3 changes: 2 additions & 1 deletion packages/dd-trace/src/plugins/consumer.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,13 @@ const InboundPlugin = require('./inbound')

class ConsumerPlugin extends InboundPlugin {
static get operation () { return 'receive' }
static get kind () { return 'consumer' }
static get type () { return 'messaging' }

startSpan (options) {
const spanDefaults = {
service: this.config.service || this.serviceName(),
kind: 'consumer'
kind: this.constructor.kind
}
Object.keys(spanDefaults).forEach(
key => {
Expand Down
3 changes: 2 additions & 1 deletion packages/dd-trace/src/plugins/producer.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,13 @@ const OutboundPlugin = require('./outbound')

class ProducerPlugin extends OutboundPlugin {
static get operation () { return 'publish' }
static get kind () { return 'producer' }
static get type () { return 'messaging' }

startSpan (options) {
const spanDefaults = {
service: this.config.service || this.serviceName(),
kind: 'producer'
kind: this.constructor.kind
}
Object.keys(spanDefaults).forEach(
key => {
Expand Down
10 changes: 8 additions & 2 deletions packages/dd-trace/src/plugins/tracing.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,18 @@ class TracingPlugin extends Plugin {
}

serviceName (serviceArgs) {
const { type, ioDirection, id } = this.constructor
const { type, ioDirection, id, kind } = this.constructor
if (type === 'messaging' && kind === 'client') {
return Nomenclature.serviceName(type, 'controlPlane', id, serviceArgs)
}
return Nomenclature.serviceName(type, ioDirection, id, serviceArgs)
}

operationName (opNameArgs) {
const { type, ioDirection, id } = this.constructor
const { type, ioDirection, id, kind } = this.constructor
if (type === 'messaging' && kind === 'client') {
return Nomenclature.opName(type, 'controlPlane', id, opNameArgs)
}
return Nomenclature.opName(type, ioDirection, id, opNameArgs)
}

Expand Down

0 comments on commit a27b9d1

Please sign in to comment.