Skip to content

Commit

Permalink
feat: merge user supplied and default plugin configs
Browse files Browse the repository at this point in the history
By merging user supplied config, a user can now only configure the diff
from the default auto enablement of installed plugins, rather than
having to explicitly re enable all plugins if at least one of their
configurations require are edited.

Signed-off-by: Naseem <[email protected]>
  • Loading branch information
Naseem committed Apr 28, 2020
1 parent 69f1913 commit 32dc2c8
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 2 deletions.
1 change: 1 addition & 0 deletions packages/opentelemetry-node/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
},
"devDependencies": {
"@opentelemetry/context-base": "^0.7.0",
"@opentelemetry/plugin-http": "^0.7.0",
"@opentelemetry/resources": "^0.7.0",
"@types/mocha": "^7.0.0",
"@types/node": "^12.6.8",
Expand Down
7 changes: 6 additions & 1 deletion packages/opentelemetry-node/src/NodeTracerProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,12 @@ export class NodeTracerProvider extends BasicTracerProvider {
super(config);

this._pluginLoader = new PluginLoader(this, this.logger);
this._pluginLoader.load(config.plugins || DEFAULT_INSTRUMENTATION_PLUGINS);

// Shallow-merge default plugins with user supplied config
this._pluginLoader.load({
...DEFAULT_INSTRUMENTATION_PLUGINS,
...config.plugins,
});
}

stop() {
Expand Down
4 changes: 3 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 plugins', () => {
it('should load user configured and default plugins that have been shallowly merged', () => {
provider = new NodeTracerProvider({
logger: new NoopLogger(),
plugins: {
Expand All @@ -103,6 +103,8 @@ describe('NodeTracerProvider', () => {
assert.strictEqual(pluginLoader['_plugins'].length, 1);
require('supported-module');
assert.strictEqual(pluginLoader['_plugins'].length, 2);
require('http');
assert.strictEqual(pluginLoader['_plugins'].length, 3);
});

it('should construct an instance with default attributes', () => {
Expand Down

0 comments on commit 32dc2c8

Please sign in to comment.