Skip to content

Commit

Permalink
make tracer config available to plugins
Browse files Browse the repository at this point in the history
  • Loading branch information
tlhunter committed Jun 13, 2023
1 parent 7b645b9 commit e013f23
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 9 deletions.
8 changes: 3 additions & 5 deletions packages/dd-trace/src/plugin_manager.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,14 +68,15 @@ 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

const pluginConfig = this._configsByName[name] || {
enabled: this._tracerConfig.plugins !== false
}

// extracts predetermined configuration from tracer and combines it with plugin-specific config
this._pluginsByName[name].configure({
...this._getSharedConfig(name),
...pluginConfig
Expand Down Expand Up @@ -127,8 +128,7 @@ module.exports = class PluginManager {
serviceMapping,
queryStringObfuscation,
site,
url,
dbmPropagationMode
url
} = this._tracerConfig

const sharedConfig = {}
Expand All @@ -141,8 +141,6 @@ module.exports = class PluginManager {
sharedConfig.queryStringObfuscation = queryStringObfuscation
}

sharedConfig.dbmPropagationMode = dbmPropagationMode

if (serviceMapping && serviceMapping[name]) {
sharedConfig.service = serviceMapping[name]
}
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 mode = this.config.dbmPropagationMode || this._tracerConfig.dbmPropagationMode

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

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

if (isPreparedStatement || mode === 'service') {
return `/*${servicePropagation}*/ ${query}`
} else if (this.config.dbmPropagationMode === 'full') {
} else if (mode === 'full') {
this.activeSpan.setTag('_dd.dbm_trace_injected', 'true')
const traceparent = this.activeSpan._spanContext.toTraceparent()
return `/*${servicePropagation},traceparent='${traceparent}'*/ ${query}`
Expand Down
4 changes: 3 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,12 @@ 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 until .configure() is called
this._tracerConfig = tracerConfig // global tracer configuration
}

get tracer () {
Expand Down

0 comments on commit e013f23

Please sign in to comment.