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

Commit 4a3ac8d

Browse files
authored
Uses object as base for local config definition [nodejs] (#159)
Fixes #158
1 parent 8fb4146 commit 4a3ac8d

File tree

2 files changed

+9
-12
lines changed

2 files changed

+9
-12
lines changed

packages/opencensus-nodejs/src/trace/tracing.ts

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ export class Tracing implements core.Tracing {
3232
/** Plugin names */
3333
private defaultPlugins: core.PluginNames;
3434
/** A configuration object to start the tracing */
35-
private configLocal: core.Config = null;
35+
private configLocal: core.Config = {};
3636
/** An object to log information to */
3737
private logger: core.Logger = null;
3838
/** Singleton instance */
@@ -94,31 +94,29 @@ export class Tracing implements core.Tracing {
9494
this.activeLocal = false;
9595
this.tracer.stop();
9696
this.pluginLoader.unloadPlugins();
97-
this.configLocal = null;
97+
this.configLocal = {};
9898
this.logger = null;
9999
}
100100

101101

102102
/** Gets the exporter. */
103103
get exporter(): core.Exporter {
104-
return this.configLocal ? this.configLocal.exporter as core.Exporter : null;
104+
return this.configLocal.exporter ?
105+
this.configLocal.exporter as core.Exporter :
106+
null;
105107
}
106108

107109
/**
108110
* Registers an exporter to send the collected traces to.
109111
* @param exporter The exporter to send the traces to.
110112
*/
111113
registerExporter(exporter: core.Exporter): core.Tracing {
114+
if (this.configLocal.exporter) {
115+
this.unregisterExporter(this.configLocal.exporter);
116+
}
112117
if (exporter) {
113-
if (this.configLocal.exporter) {
114-
this.unregisterExporter(this.configLocal.exporter);
115-
}
116118
this.configLocal.exporter = exporter;
117119
this.tracer.registerSpanEventListener(exporter);
118-
} else {
119-
if (this.configLocal.exporter) {
120-
this.unregisterExporter(this.configLocal.exporter);
121-
}
122120
}
123121
return this;
124122
}

packages/opencensus-nodejs/test/test-tracing.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -168,10 +168,9 @@ describe('Tracing', () => {
168168
assert.ok(tracing.config);
169169
assert.ok(tracing.tracer.active);
170170
tracing.stop();
171-
assert.ok(!tracing.config);
172171
assert.ok(!tracing.tracer.active);
173172
assert.strictEqual(tracing.exporter, null);
174-
assert.strictEqual(tracing.config, null);
173+
assert.deepEqual(tracing.config, {});
175174
});
176175
});
177176

0 commit comments

Comments
 (0)