Skip to content

Commit

Permalink
simplicfy config and stop overloading _getSharedConfig
Browse files Browse the repository at this point in the history
  • Loading branch information
tlhunter committed Jun 12, 2023
1 parent 5cdcf0e commit 1d75d1a
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 19 deletions.
2 changes: 1 addition & 1 deletion packages/dd-trace/src/opentracing/tracer.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ class DatadogTracer {
this._version = config.version
this._env = config.env
this._tags = config.tags
this._logInjection = config.logInjection
this._logInjection = this.getConfig('logInjection')
this._debug = config.debug
this._prioritySampler = new PrioritySampler(config.env, config.sampler)
this._exporter = new Exporter(config, this._prioritySampler)
Expand Down
15 changes: 2 additions & 13 deletions packages/dd-trace/src/plugin_manager.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ module.exports = class PluginManager {

if (!Plugin) return
if (!this._pluginsByName[name]) {
this._pluginsByName[name] = new Plugin(this._tracer)
this._pluginsByName[name] = new Plugin(this._tracer, this._tracerConfig)
}
if (!this._tracerConfig) return // TODO: don't wait for tracer to be initialized

Expand Down Expand Up @@ -120,34 +120,23 @@ module.exports = class PluginManager {
return pluginConfig.enabled !== false
}

// TODO: figure out a better way to handle this
_getSharedConfig (name) {
const {
logInjection,
serviceMapping,
queryStringObfuscation,
site,
url,
dbmPropagationMode
url
} = this._tracerConfig

const sharedConfig = {}

if (logInjection !== undefined) {
sharedConfig.logInjection = logInjection
}

if (queryStringObfuscation !== undefined) {
sharedConfig.queryStringObfuscation = queryStringObfuscation
}

sharedConfig.dbmPropagationMode = dbmPropagationMode

if (serviceMapping && serviceMapping[name]) {
sharedConfig.service = serviceMapping[name]
}

sharedConfig.site = site
sharedConfig.url = url

return sharedConfig
Expand Down
10 changes: 7 additions & 3 deletions packages/dd-trace/src/plugins/database.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,13 +38,17 @@ class DatabasePlugin extends StoragePlugin {
}

injectDbmQuery (query, serviceName, isPreparedStatement = false) {
if (this.config.dbmPropagationMode === 'disabled') {
const dbmPropagationMode = this.getConfig('dbmPropagationMode')

if (dbmPropagationMode === 'disabled') {
return query
}

const servicePropagation = this.createDBMPropagationCommentService(serviceName)
if (isPreparedStatement || this.config.dbmPropagationMode === 'service') {

if (isPreparedStatement || dbmPropagationMode === 'service') {
return `/*${servicePropagation}*/ ${query}`
} else if (this.config.dbmPropagationMode === 'full') {
} else if (dbmPropagationMode === 'full') {
this.activeSpan.setTag('_dd.dbm_trace_injected', 'true')
const traceparent = this.activeSpan._spanContext.toTraceparent()
return `/*${servicePropagation},traceparent='${traceparent}'*/ ${query}`
Expand Down
2 changes: 1 addition & 1 deletion packages/dd-trace/src/plugins/log_plugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ module.exports = class LogPlugin extends Plugin {
configure (config) {
return super.configure({
...config,
enabled: config.enabled && config.logInjection
enabled: config.enabled && this.getConfig('logInjection')
})
}
}
15 changes: 14 additions & 1 deletion packages/dd-trace/src/plugins/plugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,23 @@ class Subscription {
}

module.exports = class Plugin {
constructor (tracer) {
constructor (tracer, tracerConfig) {
this._subscriptions = []
this._enabled = false
this._tracer = tracer
this.config = {} // plugin-specific configuration, unset in constructor
this._tracerConfig = tracerConfig // global tracer configuration
}

// helper method to retrieve a configuration value that is expected to be overridden
getConfig (name) {
if (name in this.config) {
return this.config[name]
}

if (name in this._tracerConfig) {
return this._tracerConfig[name]
}
}

get tracer () {
Expand Down

0 comments on commit 1d75d1a

Please sign in to comment.