Skip to content

Commit

Permalink
fix: allow non-objects for plugins to disable automatic tracing (#720)
Browse files Browse the repository at this point in the history
PR-URL: #720
  • Loading branch information
kjin authored Apr 10, 2018
1 parent eafaa45 commit 068260c
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 4 deletions.
4 changes: 3 additions & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,9 @@ function initConfig(projectConfig: Forceable<Config>):
// 4. Default Config (as specified in './config')
const config = extend(
true, {[FORCE_NEW]: projectConfig[FORCE_NEW]}, defaultConfig,
envSetConfig, projectConfig, envConfig);
envSetConfig, projectConfig, envConfig, {plugins: {}});
// The empty plugins object guarantees that plugins is a plain object,
// even if it's explicitly specified in the config to be a non-object.

// Enforce the upper limit for the label value size.
if (config.maximumLabelValueSize >
Expand Down
12 changes: 9 additions & 3 deletions test/plugins/test-trace-http2.ts
Original file line number Diff line number Diff line change
Expand Up @@ -244,9 +244,15 @@ describe('test-trace-http2', () => {
assert.equal(
span.labels[TraceLabels.ERROR_DETAILS_NAME],
'Error [ERR_HTTP2_STREAM_ERROR]');
assert.equal(
span.labels[TraceLabels.ERROR_DETAILS_MESSAGE],
'Stream closed with error code 2');
if (semver.satisfies(process.version, '>=9.11')) {
assert.equal(
span.labels[TraceLabels.ERROR_DETAILS_MESSAGE],
'Stream closed with error code NGHTTP2_INTERNAL_ERROR');
} else {
assert.equal(
span.labels[TraceLabels.ERROR_DETAILS_MESSAGE],
'Stream closed with error code 2');
}
session.destroy();
server.close();
done();
Expand Down
5 changes: 5 additions & 0 deletions test/test-config-plugins.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,11 @@ describe('Configuration: Plugins', () => {
e => assert.ok(plugins![e].includes(`plugin-${e}.js`)));
});

it('should handle non-object', () => {
trace.start({plugins: false as {}});
assert.deepStrictEqual(plugins, {});
});

it('should overwrite builtin plugins correctly', () => {
trace.start({plugins: {express: 'foo'}});
assert.ok(plugins);
Expand Down

0 comments on commit 068260c

Please sign in to comment.