Skip to content

Commit

Permalink
feat: 2 level merge of user supplied and default plugin configs
Browse files Browse the repository at this point in the history
Signed-off-by: Naseem <[email protected]>
  • Loading branch information
Naseem committed Apr 28, 2020
1 parent 32dc2c8 commit 19bd6c3
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 4 deletions.
24 changes: 21 additions & 3 deletions packages/opentelemetry-node/src/NodeTracerProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import {
SDKRegistrationConfig,
} from '@opentelemetry/tracing';
import { DEFAULT_INSTRUMENTATION_PLUGINS, NodeTracerConfig } from './config';
import { PluginLoader } from './instrumentation/PluginLoader';
import { PluginLoader, Plugins } from './instrumentation/PluginLoader';

/**
* Register this TracerProvider for use with the OpenTelemetry API.
Expand All @@ -40,10 +40,28 @@ export class NodeTracerProvider extends BasicTracerProvider {

this._pluginLoader = new PluginLoader(this, this.logger);

// Shallow-merge default plugins with user supplied config
/**
* For user supplied config of plugin(s) that are loaded by default,
* merge the user supplied and default configs of said plugin(s)
*/
let mergedUserSuppliedPlugins: Plugins = {};

for (const plugin in config.plugins) {
if (DEFAULT_INSTRUMENTATION_PLUGINS.hasOwnProperty(plugin)) {
mergedUserSuppliedPlugins[plugin] = {
...DEFAULT_INSTRUMENTATION_PLUGINS[plugin],
...config.plugins[plugin],
};
} else {
// TODO: enable non-default but user-configured plugins unless
// explicitly disabled
mergedUserSuppliedPlugins[plugin] = config.plugins[plugin];
}
}

this._pluginLoader.load({
...DEFAULT_INSTRUMENTATION_PLUGINS,
...config.plugins,
...mergedUserSuppliedPlugins,
});
}

Expand Down
5 changes: 4 additions & 1 deletion packages/opentelemetry-node/test/NodeTracerProvider.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ describe('NodeTracerProvider', () => {
assert.ok(provider instanceof NodeTracerProvider);
});

it('should load user configured and default plugins that have been shallowly merged', () => {
it('should load a merge of user configured and default plugins', () => {
provider = new NodeTracerProvider({
logger: new NoopLogger(),
plugins: {
Expand All @@ -95,6 +95,9 @@ describe('NodeTracerProvider', () => {
ignoreMethods: [],
ignoreUrls: [],
},
http: {
path: '@opentelemetry/plugin-http-module',
},
},
});
const pluginLoader = provider['_pluginLoader'];
Expand Down

0 comments on commit 19bd6c3

Please sign in to comment.