Skip to content
This repository has been archived by the owner on Oct 3, 2023. It is now read-only.

Commit

Permalink
Uses object as base for local config definition [nodejs] (#159)
Browse files Browse the repository at this point in the history
Fixes #158
  • Loading branch information
isaikevych committed Oct 23, 2018
1 parent 8fb4146 commit 4a3ac8d
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 12 deletions.
18 changes: 8 additions & 10 deletions packages/opencensus-nodejs/src/trace/tracing.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ export class Tracing implements core.Tracing {
/** Plugin names */
private defaultPlugins: core.PluginNames;
/** A configuration object to start the tracing */
private configLocal: core.Config = null;
private configLocal: core.Config = {};
/** An object to log information to */
private logger: core.Logger = null;
/** Singleton instance */
Expand Down Expand Up @@ -94,31 +94,29 @@ export class Tracing implements core.Tracing {
this.activeLocal = false;
this.tracer.stop();
this.pluginLoader.unloadPlugins();
this.configLocal = null;
this.configLocal = {};
this.logger = null;
}


/** Gets the exporter. */
get exporter(): core.Exporter {
return this.configLocal ? this.configLocal.exporter as core.Exporter : null;
return this.configLocal.exporter ?
this.configLocal.exporter as core.Exporter :
null;
}

/**
* Registers an exporter to send the collected traces to.
* @param exporter The exporter to send the traces to.
*/
registerExporter(exporter: core.Exporter): core.Tracing {
if (this.configLocal.exporter) {
this.unregisterExporter(this.configLocal.exporter);
}
if (exporter) {
if (this.configLocal.exporter) {
this.unregisterExporter(this.configLocal.exporter);
}
this.configLocal.exporter = exporter;
this.tracer.registerSpanEventListener(exporter);
} else {
if (this.configLocal.exporter) {
this.unregisterExporter(this.configLocal.exporter);
}
}
return this;
}
Expand Down
3 changes: 1 addition & 2 deletions packages/opencensus-nodejs/test/test-tracing.ts
Original file line number Diff line number Diff line change
Expand Up @@ -168,10 +168,9 @@ describe('Tracing', () => {
assert.ok(tracing.config);
assert.ok(tracing.tracer.active);
tracing.stop();
assert.ok(!tracing.config);
assert.ok(!tracing.tracer.active);
assert.strictEqual(tracing.exporter, null);
assert.strictEqual(tracing.config, null);
assert.deepEqual(tracing.config, {});
});
});

Expand Down

0 comments on commit 4a3ac8d

Please sign in to comment.