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

Commit 0cde438

Browse files
eldreygalindokjin
authored andcommitted
feat: add config logger in start and unit test
1 parent b5fee87 commit 0cde438

2 files changed

Lines changed: 36 additions & 9 deletions

File tree

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

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,12 @@ import {Sampler} from '@opencensus/opencensus-core';
2323
import {Logger} from '@opencensus/opencensus-core';
2424
import {ConsoleExporter, Exporter, NoopExporter} from '@opencensus/opencensus-core';
2525
import {Config} from '@opencensus/opencensus-core';
26-
import * as extend from 'extend';
26+
import * as logger from '@opencensus/opencensus-core';
2727

2828
import {defaultConfig} from './config/config';
2929
import {CONSTANTS} from './constants';
3030
import {PluginLoader} from './instrumentation/plugingloader';
31-
31+
import * as extend from 'extend';
3232

3333
/** Implements a Tracing. */
3434
export class TracingImpl implements Tracing {
@@ -69,13 +69,15 @@ export class TracingImpl implements Tracing {
6969
this.config = extend(
7070
true, {}, defaultConfig, {plugins: this.defaultPlugins}, userConfig);
7171
// TODO: Instance logger if no logger was passed
72-
this.logger = this.config.logger;
72+
this.logger = this.config.logger || logger.logger();
7373
debug('config: %o', this.config);
7474
this.pluginLoader.loadPlugins(this.config.plugins);
7575

7676
if (!this.config.exporter) {
7777
const exporter = new ConsoleExporter(this.config);
7878
this.registerExporter(exporter);
79+
}else{
80+
this.registerExporter(this.config.exporter);
7981
}
8082
this.active = true;
8183
this.tracerLocal.start(this.config);

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

Lines changed: 31 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,22 @@
1414
* limitations under the License.
1515
*/
1616

17-
import {ConsoleExporter, Exporter, Tracer, TracerImpl, Tracing} from '@opencensus/opencensus-core';
18-
import * as assert from 'assert';
17+
import {ConsoleExporter} from '@opencensus/opencensus-core';
18+
import {Exporter} from '@opencensus/opencensus-core';
19+
import {Tracer} from '@opencensus/opencensus-core';
20+
import {TracerImpl} from '@opencensus/opencensus-core';
21+
import {Tracing} from '@opencensus/opencensus-core';
22+
import {Logger} from '@opencensus/opencensus-core';
23+
import {Config, TracingConfig} from '@opencensus/opencensus-core';
24+
import {NoopExporter} from '@opencensus/opencensus-core';
25+
26+
import * as logger from '@opencensus/opencensus-core';
1927

2028
import {TracingImpl} from '../src/trace/tracing';
29+
import * as assert from 'assert';
2130

31+
32+
const NOOP_EXPORTER = new NoopExporter();
2233
describe('Tracing', () => {
2334
/** Should create a Tracing instance */
2435
describe('new Tracing()', () => {
@@ -39,16 +50,30 @@ describe('Tracing', () => {
3950
/** Should return a started tracing instance */
4051
describe('start()', () => {
4152
let tracingStarted: Tracing;
42-
before(() => {
43-
const tracing = new TracingImpl();
44-
tracingStarted = tracing.start();
45-
});
53+
const tracing = new TracingImpl();
54+
// tslint:disable:no-any
55+
function instanceOfLogger(object: any): object is Logger {
56+
return 'debug' in object;
57+
}
58+
4659
it('should return a tracing instance', () => {
60+
tracingStarted = tracing.start();
4761
assert.ok(tracingStarted instanceof TracingImpl);
4862
});
4963

5064
it('the tracing was started', () => {
65+
tracingStarted = tracing.start();
5166
assert.ok(tracingStarted.tracer.active);
67+
});
68+
it('should tracing.tracer instance with logger', () =>{
69+
70+
tracingStarted = tracing.start({logger:logger.logger('debug')});
71+
assert.ok(instanceOfLogger(tracingStarted.tracer.logger));
72+
});
73+
it('should tracing.tracer instance with exporter', () =>{
74+
75+
tracingStarted = tracing.start({exporter: NOOP_EXPORTER});
76+
assert.equal(tracingStarted.exporter, NOOP_EXPORTER);
5277
});
5378
});
5479

0 commit comments

Comments
 (0)