Skip to content
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

[wip] 663 integrations disabled env var #1

Closed
wants to merge 6 commits into from
Closed
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
39 changes: 20 additions & 19 deletions docs/API.md
Original file line number Diff line number Diff line change
Expand Up @@ -310,25 +310,26 @@ tracer.use('pg', {

Options can be configured as a parameter to the [init()](./interfaces/tracer.html#init) method or as environment variables.

| Config | Environment Variable | Default | Description |
| -------------- | ------------------------------ | ----------- | ----------- |
| enabled | `DD_TRACE_ENABLED` | `true` | Whether to enable the tracer. |
| debug | `DD_TRACE_DEBUG` | `false` | Enable debug logging in the tracer. |
| service | `DD_SERVICE_NAME` | - | The service name to be used for this program. |
| url | `DD_TRACE_AGENT_URL` | - | The url of the trace agent that the tracer will submit to. Takes priority over hostname and port, if set. |
| hostname | `DD_TRACE_AGENT_HOSTNAME` | `localhost` | The address of the agent that the tracer will submit to. |
| port | `DD_TRACE_AGENT_PORT` | `8126` | The port of the trace agent that the tracer will submit to. |
| dogstatsd.port | `DD_DOGSTATSD_PORT` | `8125` | The port of the Dogstatsd agent that metrics will be submitted to. |
| env | `DD_ENV` | - | Set an application’s environment e.g. `prod`, `pre-prod`, `stage`. |
| logInjection | `DD_LOGS_INJECTION` | `false` | Enable automatic injection of trace IDs in logs for supported logging libraries. |
| tags | - | `{}` | Set global tags that should be applied to all spans. |
| sampleRate | - | `1` | Percentage of spans to sample as a float between 0 and 1. |
| flushInterval | - | `2000` | Interval in milliseconds at which the tracer will submit traces to the agent. |
| runtimeMetrics | `DD_RUNTIME_METRICS_ENABLED` | `false` | Whether to enable capturing runtime metrics. Port 8125 (or configured with `dogstatsd.port`) must be opened on the agent for UDP. |
| reportHostname | `DD_TRACE_REPORT_HOSTNAME` | `false` | Whether to report the system's hostname for each trace. When disabled, the hostname of the agent will be used instead. |
| experimental | - | `{}` | Experimental features can be enabled all at once using boolean `true` or individually using key/value pairs. Please contact us to learn more about the available experimental features. |
| plugins | - | `true` | Whether or not to enable automatic instrumentation of external libraries using the built-in plugins. |
| clientToken | `DD_CLIENT_TOKEN` | - | Client token for browser tracing. Can be generated in the UI at `Integrations -> APIs`. |
| Config | Environment Variable | Default | Description |
| -------------------- | ------------------------------ | ----------- | ----------- |
| enabled | `DD_TRACE_ENABLED` | `true` | Whether to enable the tracer. |
| debug | `DD_TRACE_DEBUG` | `false` | Enable debug logging in the tracer. |
| service | `DD_SERVICE_NAME` | - | The service name to be used for this program. |
| url | `DD_TRACE_AGENT_URL` | - | The url of the trace agent that the tracer will submit to. Takes priority over hostname and port, if set. |
| hostname | `DD_TRACE_AGENT_HOSTNAME` | `localhost` | The address of the agent that the tracer will submit to. |
| port | `DD_TRACE_AGENT_PORT` | `8126` | The port of the trace agent that the tracer will submit to. |
| dogstatsd.port | `DD_DOGSTATSD_PORT` | `8125` | The port of the Dogstatsd agent that metrics will be submitted to. |
| env | `DD_ENV` | - | Set an application’s environment e.g. `prod`, `pre-prod`, `stage`. |
| logInjection | `DD_LOGS_INJECTION` | `false` | Enable automatic injection of trace IDs in logs for supported logging libraries. |
| tags | - | `{}` | Set global tags that should be applied to all spans. |
| sampleRate | - | `1` | Percentage of spans to sample as a float between 0 and 1. |
| flushInterval | - | `2000` | Interval in milliseconds at which the tracer will submit traces to the agent. |
| runtimeMetrics | `DD_RUNTIME_METRICS_ENABLED` | `false` | Whether to enable capturing runtime metrics. Port 8125 (or configured with `dogstatsd.port`) must be opened on the agent for UDP. |
| reportHostname | `DD_TRACE_REPORT_HOSTNAME` | `false` | Whether to report the system's hostname for each trace. When disabled, the hostname of the agent will be used instead. |
| experimental | - | `{}` | Experimental features can be enabled all at once using boolean `true` or individually using key/value pairs. Please contact us to learn more about the available experimental features. |
| plugins | - | `true` | Whether or not to enable automatic instrumentation of external libraries using the built-in plugins. |
| clientToken | `DD_CLIENT_TOKEN` | - | Client token for browser tracing. Can be generated in the UI at `Integrations -> APIs`. |
| integrationsDisabled | `DD_INTEGRATIONS_DISABLED` | `[]` | Set an array of integration names to automatically disable when the tracer is initializated, e.g. `['express','http','dns']`. |

<h3 id="custom-logging">Custom Logging</h3>

Expand Down
6 changes: 6 additions & 0 deletions index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -290,6 +290,12 @@ export declare interface TracerOptions {
*/
reportHostname?: boolean

/**
* An array of integrations to automatically disable when the tracer is initialized e.g. [`express`,`hapi`,`dns`]
* @default []
*/
integrationsDisabled?: string[]

/**
* Client token for browser tracing. Can be generated in the UI at `Integrations -> APIs`.
*/
Expand Down
1 change: 1 addition & 0 deletions packages/dd-trace/src/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ class Config {
}
this.reportHostname = String(reportHostname) === 'true'
this.scope = platform.env('DD_CONTEXT_PROPAGATION') === 'false' ? scopes.NOOP : scope
this.integrationsDisabled = coalesce(options.integrationsDisabled, platform.env('DD_INTEGRATIONS_DISABLED'), [])
this.clientToken = clientToken
}
}
Expand Down
6 changes: 5 additions & 1 deletion packages/dd-trace/src/instrumenter.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,11 @@ class Instrumenter {
Object.keys(plugins)
.filter(name => !this._plugins.has(plugins[name]))
.forEach(name => {
this._set(plugins[name], { name, config: {} })
if (!config.integrationsDisabled || config.integrationsDisabled.indexOf(name) === -1) {
this._set(plugins[name], { name, config: {} })
} else {
log.debug(`configuration disabled via configuration option, named "${name}".`)
}
})
}

Expand Down
4 changes: 4 additions & 0 deletions packages/dd-trace/test/config.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ describe('Config', () => {
expect(config).to.have.property('reportHostname', false)
expect(config).to.have.property('scope', undefined)
expect(config).to.have.property('clientToken', undefined)
expect(config).to.have.deep.property('integrationsDisabled', [])
expect(config).to.have.nested.property('experimental.b3', false)
})

Expand Down Expand Up @@ -92,6 +93,7 @@ describe('Config', () => {
const tags = {
'foo': 'bar'
}
const mockDisabledIntegrations = ['express']
const config = new Config('test', {
enabled: false,
debug: true,
Expand All @@ -113,6 +115,7 @@ describe('Config', () => {
plugins: false,
scope: 'noop',
clientToken: '789',
integrationsDisabled: mockDisabledIntegrations,
experimental: {
b3: true
}
Expand All @@ -136,6 +139,7 @@ describe('Config', () => {
expect(config).to.have.property('plugins', false)
expect(config).to.have.property('scope', 'noop')
expect(config).to.have.property('clientToken', '789')
expect(config).to.have.property('integrationsDisabled', mockDisabledIntegrations)
expect(config).to.have.deep.property('tags', {
'foo': 'bar'
})
Expand Down
23 changes: 23 additions & 0 deletions packages/dd-trace/test/instrumenter.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -352,4 +352,27 @@ describe('Instrumenter', () => {
})
})
})

describe('with plugins disabled via configuration option', () => {
describe('enable', () => {
it('should not patch plugins disabled from configuration option', () => {
const configDisabled = { foo: 'bar', integrationsDisabled: ['express-mock'] }
instrumenter.enable(configDisabled)

require('express-mock')

expect(integrations.express.patch).to.not.have.been.called
})

it('should patch plugins not disabled from configuration option', () => {
const configDefault = {}
const configNotDisabled = { foo: 'bar', integrationsDisabled: [] }
instrumenter.enable(configNotDisabled)

const express = require('express-mock')

expect(integrations.express.patch).to.have.been.calledWith(express, 'tracer', configDefault)
})
})
})
})