Skip to content

Commit

Permalink
add option to disable splitting aws-sdk service names by aws service (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
rochdev committed Sep 3, 2020
1 parent 5951c65 commit 3b84978
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 7 deletions.
1 change: 1 addition & 0 deletions docs/test.ts
Expand Up @@ -135,6 +135,7 @@ const elasticsearchOptions = {

const awsSdkOptions = {
service: 'test',
splitByAwsService: false,
hooks: {
request: (span, response) => {},
}
Expand Down
6 changes: 6 additions & 0 deletions index.d.ts
Expand Up @@ -667,6 +667,12 @@ declare namespace plugins {
* [aws-sdk](https://github.com/aws/aws-sdk-js) module.
*/
interface aws_sdk extends Instrumentation {
/**
* Whether to add a suffix to the service name so that each AWS service has its own service name.
* @default true
*/
splitByAwsService?: boolean;

/**
* Hooks to run before spans are finished.
*/
Expand Down
22 changes: 15 additions & 7 deletions packages/datadog-plugin-aws-sdk/src/index.js
Expand Up @@ -11,13 +11,12 @@ function createWrapRequest (tracer, config) {
return function requestWithTrace (cb) {
if (!this.service) return send.apply(this, arguments)

const serviceName = this.service.serviceIdentifier
const serviceIdentifier = this.service.serviceIdentifier
const serviceName = getServiceName(serviceIdentifier, tracer, config)
const childOf = tracer.scope().active()
const tags = {
[Tags.SPAN_KIND]: 'client',
'service.name': config.service
? `${config.service}-aws-${serviceName}`
: `${tracer._service}-aws-${serviceName}`,
'service.name': serviceName,
'aws.operation': this.operation,
'aws.region': this.service.config && this.service.config.region,
'aws.service': this.service.api && this.service.api.className,
Expand All @@ -32,20 +31,20 @@ function createWrapRequest (tracer, config) {
this.on('complete', response => {
if (!span) return

awsHelpers.addResponseTags(span, response, serviceName, config, tracer)
awsHelpers.addResponseTags(span, response, serviceIdentifier, config, tracer)
awsHelpers.finish(span, response.error)
})

analyticsSampler.sample(span, config.analytics)

awsHelpers.requestInject(span, this, serviceName, tracer)
awsHelpers.requestInject(span, this, serviceIdentifier, tracer)

const request = this

return tracer.scope().activate(span, () => {
let boundCb
if (typeof cb === 'function') {
boundCb = awsHelpers.wrapCb(cb, serviceName, tags, request, tracer, childOf)
boundCb = awsHelpers.wrapCb(cb, serviceIdentifier, tags, request, tracer, childOf)
} else {
boundCb = cb
}
Expand All @@ -71,6 +70,7 @@ function normalizeConfig (config) {
const hooks = getHooks(config)

return Object.assign({}, config, {
splitByAwsService: config.splitByAwsService !== false,
hooks
})
}
Expand All @@ -82,6 +82,14 @@ function getHooks (config) {
return { request }
}

function getServiceName (serviceIdentifier, tracer, config) {
const service = config.service || tracer._service

return config.splitByAwsService
? `${service}-aws-${serviceIdentifier}`
: service
}

// <2.1.35 has breaking changes for instrumentation
// https://github.com/aws/aws-sdk-js/pull/629
module.exports = [
Expand Down

0 comments on commit 3b84978

Please sign in to comment.