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
34 changes: 25 additions & 9 deletions packages/dd-trace/src/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -321,19 +321,38 @@ class Config {
false
)
const DD_TRACE_SPAN_ATTRIBUTE_SCHEMA = validateNamingVersion(
process.env.DD_TRACE_SPAN_ATTRIBUTE_SCHEMA
coalesce(
options.spanAttributeSchema,
process.env.DD_TRACE_SPAN_ATTRIBUTE_SCHEMA
)
)
const DD_TRACE_PEER_SERVICE_MAPPING = coalesce(
options.peerServiceMapping,
process.env.DD_TRACE_PEER_SERVICE_MAPPING ? fromEntries(
process.env.DD_TRACE_PEER_SERVICE_MAPPING.split(',').map(x => x.trim().split(':'))
) : {}
)
const DD_TRACE_PEER_SERVICE_DEFAULTS_ENABLED = process.env.DD_TRACE_PEER_SERVICE_DEFAULTS_ENABLED

const peerServiceSet = (
options.hasOwnProperty('spanComputePeerService') ||
process.env.hasOwnProperty('DD_TRACE_PEER_SERVICE_DEFAULTS_ENABLED')
)
const peerServiceValue = coalesce(
options.spanComputePeerService,
process.env.DD_TRACE_PEER_SERVICE_DEFAULTS_ENABLED
)

const DD_TRACE_PEER_SERVICE_DEFAULTS_ENABLED = (
DD_TRACE_SPAN_ATTRIBUTE_SCHEMA === 'v0'
// In v0, peer service is computed only if it is explicitly set to true
? peerServiceSet && isTrue(peerServiceValue)
// In >v0, peer service is false only if it is explicitly set to false
: (peerServiceSet ? !isFalse(peerServiceValue) : true)
)

const DD_TRACE_REMOVE_INTEGRATION_SERVICE_NAMES_ENABLED = coalesce(
isTrue(process.env.DD_TRACE_REMOVE_INTEGRATION_SERVICE_NAMES_ENABLED),
false
options.spanRemoveIntegrationFromService,
isTrue(process.env.DD_TRACE_REMOVE_INTEGRATION_SERVICE_NAMES_ENABLED)
)
const DD_TRACE_X_DATADOG_TAGS_MAX_LENGTH = coalesce(
process.env.DD_TRACE_X_DATADOG_TAGS_MAX_LENGTH,
Expand Down Expand Up @@ -565,11 +584,8 @@ ken|consumer_?(?:id|key|secret)|sign(?:ed|ature)?|auth(?:entication|orization)?)
exporters: DD_PROFILING_EXPORTERS
}
this.spanAttributeSchema = DD_TRACE_SPAN_ATTRIBUTE_SCHEMA
this.spanComputePeerService = (this.spanAttributeSchema === 'v0'
? isTrue(DD_TRACE_PEER_SERVICE_DEFAULTS_ENABLED)
: true
)
this.traceRemoveIntegrationServiceNamesEnabled = DD_TRACE_REMOVE_INTEGRATION_SERVICE_NAMES_ENABLED
this.spanComputePeerService = DD_TRACE_PEER_SERVICE_DEFAULTS_ENABLED
this.spanRemoveIntegrationFromService = DD_TRACE_REMOVE_INTEGRATION_SERVICE_NAMES_ENABLED
this.peerServiceMapping = DD_TRACE_PEER_SERVICE_MAPPING
this.lookup = options.lookup
this.startupLogs = isTrue(DD_TRACE_STARTUP_LOGS)
Expand Down
4 changes: 2 additions & 2 deletions packages/dd-trace/src/service-naming/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ const { schemaDefinitions } = require('./schemas')
class SchemaManager {
constructor () {
this.schemas = schemaDefinitions
this.config = { spanAttributeSchema: 'v0', traceRemoveIntegrationServiceNamesEnabled: false }
this.config = { spanAttributeSchema: 'v0', spanRemoveIntegrationFromService: false }
}

get schema () {
Expand All @@ -15,7 +15,7 @@ class SchemaManager {
}

get shouldUseConsistentServiceNaming () {
return this.config.traceRemoveIntegrationServiceNamesEnabled && this.version === 'v0'
return this.config.spanRemoveIntegrationFromService && this.version === 'v0'
}

opName (type, kind, plugin, ...opNameArgs) {
Expand Down
65 changes: 63 additions & 2 deletions packages/dd-trace/test/config.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ describe('Config', () => {
expect(config).to.have.property('traceId128BitLoggingEnabled', false)
expect(config).to.have.property('spanAttributeSchema', 'v0')
expect(config).to.have.property('spanComputePeerService', false)
expect(config).to.have.property('traceRemoveIntegrationServiceNamesEnabled', false)
expect(config).to.have.property('spanRemoveIntegrationFromService', false)
expect(config).to.have.deep.property('serviceMapping', {})
expect(config).to.have.nested.deep.property('tracePropagationStyle.inject', ['tracecontext', 'datadog'])
expect(config).to.have.nested.deep.property('tracePropagationStyle.extract', ['tracecontext', 'datadog'])
Expand Down Expand Up @@ -195,6 +195,8 @@ describe('Config', () => {
process.env.DD_TRACE_EXPERIMENTAL_GET_RUM_DATA_ENABLED = 'true'
process.env.DD_TRACE_EXPERIMENTAL_INTERNAL_ERRORS_ENABLED = 'true'
process.env.DD_TRACE_SPAN_ATTRIBUTE_SCHEMA = 'v1'
process.env.DD_TRACE_PEER_SERVICE_DEFAULTS_ENABLED = 'true'
process.env.DD_TRACE_REMOVE_INTEGRATION_SERVICE_NAMES_ENABLED = 'true'
process.env.DD_TRACE_REMOVE_INTEGRATION_SERVICE_NAMES_ENABLED = true
process.env.DD_APPSEC_ENABLED = 'true'
process.env.DD_APPSEC_RULES = RULES_JSON_PATH
Expand Down Expand Up @@ -237,6 +239,8 @@ describe('Config', () => {
expect(config).to.have.property('traceId128BitGenerationEnabled', true)
expect(config).to.have.property('traceId128BitLoggingEnabled', true)
expect(config).to.have.property('spanAttributeSchema', 'v1')
expect(config).to.have.property('spanRemoveIntegrationFromService', true)
expect(config).to.have.property('spanComputePeerService', true)
expect(config.tags).to.include({ foo: 'bar', baz: 'qux' })
expect(config.tags).to.include({ service: 'service', 'version': '1.0.0', 'env': 'test' })
expect(config).to.have.deep.nested.property('sampler', {
Expand Down Expand Up @@ -372,6 +376,12 @@ describe('Config', () => {
{ service: 'mysql', sampleRate: 1.0 },
{ sampleRate: 0.1 }
],
spanAttributeSchema: 'v1',
spanComputePeerService: true,
spanRemoveIntegrationFromService: true,
peerServiceMapping: {
d: 'dd'
},
serviceMapping: {
a: 'aa',
b: 'bb'
Expand Down Expand Up @@ -437,6 +447,9 @@ describe('Config', () => {
expect(config).to.have.property('logLevel', logLevel)
expect(config).to.have.property('traceId128BitGenerationEnabled', true)
expect(config).to.have.property('traceId128BitLoggingEnabled', true)
expect(config).to.have.property('spanRemoveIntegrationFromService', true)
expect(config).to.have.property('spanComputePeerService', true)
expect(config).to.have.deep.property('peerServiceMapping', { d: 'dd' })
expect(config).to.have.property('tags')
expect(config.tags).to.have.property('foo', 'bar')
expect(config.tags).to.have.property('runtime-id')
Expand Down Expand Up @@ -536,13 +549,52 @@ describe('Config', () => {
it('should warn if defaulting to v0 span attribute schema', () => {
process.env.DD_TRACE_SPAN_ATTRIBUTE_SCHEMA = 'foo'

// eslint-disable-next-line no-new
const config = new Config()

expect(log.warn).to.have.been.calledWith('Unexpected input for config.spanAttributeSchema, picked default v0')
expect(config).to.have.property('spanAttributeSchema', 'v0')
})

context('peer service tagging', () => {
it('should activate peer service only if explicitly true in v0', () => {
process.env.DD_TRACE_SPAN_ATTRIBUTE_SCHEMA = 'v0'
process.env.DD_TRACE_PEER_SERVICE_DEFAULTS_ENABLED = 'true'
let config = new Config()
expect(config).to.have.property('spanComputePeerService', true)

process.env.DD_TRACE_PEER_SERVICE_DEFAULTS_ENABLED = 'foo'
config = new Config()
expect(config).to.have.property('spanComputePeerService', false)

process.env.DD_TRACE_PEER_SERVICE_DEFAULTS_ENABLED = 'false'
config = new Config()
expect(config).to.have.property('spanComputePeerService', false)

delete process.env.DD_TRACE_PEER_SERVICE_DEFAULTS_ENABLED
config = new Config()
expect(config).to.have.property('spanComputePeerService', false)
})

it('should activate peer service in v1 unless explicitly false', () => {
process.env.DD_TRACE_SPAN_ATTRIBUTE_SCHEMA = 'v1'
process.env.DD_TRACE_PEER_SERVICE_DEFAULTS_ENABLED = 'false'
let config = new Config()
expect(config).to.have.property('spanComputePeerService', false)

process.env.DD_TRACE_PEER_SERVICE_DEFAULTS_ENABLED = 'foo'
config = new Config()
expect(config).to.have.property('spanComputePeerService', true)

process.env.DD_TRACE_PEER_SERVICE_DEFAULTS_ENABLED = 'true'
config = new Config()
expect(config).to.have.property('spanComputePeerService', true)

delete process.env.DD_TRACE_PEER_SERVICE_DEFAULTS_ENABLED
config = new Config()
expect(config).to.have.property('spanComputePeerService', true)
})
})

it('should give priority to the common agent environment variable', () => {
process.env.DD_TRACE_AGENT_HOSTNAME = 'trace-agent'
process.env.DD_AGENT_HOST = 'agent'
Expand Down Expand Up @@ -572,6 +624,9 @@ describe('Config', () => {
process.env.DD_ENV = 'test'
process.env.DD_API_KEY = '123'
process.env.DD_APP_KEY = '456'
process.env.DD_TRACE_SPAN_ATTRIBUTE_SCHEMA = 'v0'
process.env.DD_TRACE_PEER_SERVICE_DEFAULTS_ENABLED = 'false'
process.env.DD_TRACE_REMOVE_INTEGRATION_SERVICE_NAMES_ENABLED = 'false'
process.env.DD_TRACE_CLIENT_IP_ENABLED = 'false'
process.env.DD_TRACE_CLIENT_IP_HEADER = 'foo-bar-header'
process.env.DD_TRACE_GLOBAL_TAGS = 'foo:bar,baz:qux'
Expand Down Expand Up @@ -620,6 +675,9 @@ describe('Config', () => {
serviceMapping: {
b: 'bb'
},
spanAttributeSchema: 'v1',
spanComputePeerService: true,
spanRemoveIntegrationFromService: true,
peerServiceMapping: {
d: 'dd'
},
Expand Down Expand Up @@ -677,6 +735,9 @@ describe('Config', () => {
expect(config.tags).to.include({ foo: 'foo', baz: 'qux' })
expect(config.tags).to.include({ service: 'test', version: '1.0.0', env: 'development' })
expect(config).to.have.deep.property('serviceMapping', { b: 'bb' })
expect(config).to.have.property('spanAttributeSchema', 'v1')
expect(config).to.have.property('spanRemoveIntegrationFromService', true)
expect(config).to.have.property('spanComputePeerService', true)
expect(config).to.have.deep.property('peerServiceMapping', { d: 'dd' })
expect(config).to.have.nested.deep.property('tracePropagationStyle.inject', [])
expect(config).to.have.nested.deep.property('tracePropagationStyle.extract', [])
Expand Down
2 changes: 1 addition & 1 deletion packages/dd-trace/test/setup/mocha.js
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ function withNamingSchema (spanProducerFn, expectedOpName, expectedServiceName,
Nomenclature.configure({
spanAttributeSchema: 'v0',
service: fullConfig.service,
traceRemoveIntegrationServiceNamesEnabled: true
spanRemoveIntegrationFromService: true
})
})
after(() => {
Expand Down