Skip to content

add experimental flag on plugins to disable them by default #5985

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 3 commits into
base: master
Choose a base branch
from
Draft
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
1 change: 1 addition & 0 deletions packages/datadog-plugin-prisma/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ const PrismaClientPlugin = require('./client')
const PrismaEnginePlugin = require('./engine')

class PrismaPlugin extends CompositePlugin {
static experimental = true
static get id () { return 'prisma' }
static get plugins () {
return {
Expand Down
12 changes: 8 additions & 4 deletions packages/dd-trace/src/plugin_manager.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
'use strict'

const { channel } = require('dc-polyfill')
const { isFalse, normalizePluginEnvName } = require('./util')
const { isFalse, isTrue, normalizePluginEnvName } = require('./util')
const plugins = require('./plugins')
const log = require('./log')
const { getEnvironmentVariable } = require('../../dd-trace/src/config-helper')
Expand Down Expand Up @@ -32,8 +32,7 @@ loadChannel.subscribe(({ name }) => {
function maybeEnable (Plugin) {
if (!Plugin || typeof Plugin !== 'function') return
if (!pluginClasses[Plugin.id]) {
const envName = `DD_TRACE_${Plugin.id.toUpperCase()}_ENABLED`
const enabled = getEnvironmentVariable(normalizePluginEnvName(envName))
const enabled = getEnvEnabled(Plugin)

// TODO: remove the need to load the plugin class in order to disable the plugin
if (isFalse(enabled) || disabledPlugins.has(Plugin.id)) {
Expand All @@ -46,6 +45,11 @@ function maybeEnable (Plugin) {
}
}

function getEnvEnabled (Plugin) {
const envName = `DD_TRACE_${Plugin.id.toUpperCase()}_ENABLED`
return getEnvironmentVariable(normalizePluginEnvName(envName))
}

// TODO this must always be a singleton.
module.exports = class PluginManager {
constructor (tracer) {
Expand Down Expand Up @@ -74,7 +78,7 @@ module.exports = class PluginManager {
this._pluginsByName[name] = new Plugin(this._tracer, this._tracerConfig)
}
const pluginConfig = this._configsByName[name] || {
enabled: this._tracerConfig.plugins !== false
enabled: this._tracerConfig.plugins !== false && (!Plugin.experimental || isTrue(getEnvEnabled(Plugin)))
}

// extracts predetermined configuration from tracer and combines it with plugin-specific config
Expand Down
33 changes: 32 additions & 1 deletion packages/dd-trace/test/plugin_manager.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ describe('Plugin Manager', () => {
let Four
let Five
let Six
let Eight
let pm

beforeEach(() => {
Expand Down Expand Up @@ -53,7 +54,11 @@ describe('Plugin Manager', () => {
return 'six'
}
},
seven: {}
seven: {},
eight: class Eight extends FakePlugin {
static experimental = true
static id = 'eight'
}
}

Two = plugins.two
Expand All @@ -67,6 +72,9 @@ describe('Plugin Manager', () => {
Six = plugins.six
Six.prototype.configure = sinon.spy()

Eight = plugins.eight
Eight.prototype.configure = sinon.spy()

process.env.DD_TRACE_DISABLED_PLUGINS = 'five,six,seven'

PluginManager = proxyquire.noPreserveCache()('../src/plugin_manager', {
Expand All @@ -83,6 +91,7 @@ describe('Plugin Manager', () => {

afterEach(() => {
delete process.env.DD_TRACE_DISABLED_PLUGINS
delete process.env.DD_TRACE_EIGHT_ENABLED
pm.destroy()
})

Expand Down Expand Up @@ -273,6 +282,28 @@ describe('Plugin Manager', () => {
})
})

describe('with an experimental plugin', () => {
it('should disable the plugin by default', () => {
pm.configure()
loadChannel.publish({ name: 'eight' })
expect(Eight.prototype.configure).to.have.been.calledWithMatch({ enabled: false })
})

it('should enable the plugin when configured programmatically', () => {
pm.configure()
pm.configurePlugin('eight')
loadChannel.publish({ name: 'eight' })
expect(Eight.prototype.configure).to.have.been.calledWithMatch({ enabled: true })
})

it('should enable the plugin when configured with an environment variable', () => {
process.env.DD_TRACE_EIGHT_ENABLED = 'true'
pm.configure()
loadChannel.publish({ name: 'eight' })
expect(Eight.prototype.configure).to.have.been.calledWithMatch({ enabled: true })
})
})

it('instantiates plugin classes', () => {
pm.configure()
loadChannel.publish({ name: 'two' })
Expand Down