Skip to content

Commit

Permalink
refactor: address comments, pt 4
Browse files Browse the repository at this point in the history
  • Loading branch information
kjin committed May 17, 2018
1 parent 3b159ea commit 6f00010
Showing 1 changed file with 16 additions and 14 deletions.
30 changes: 16 additions & 14 deletions src/tracing.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,6 @@ export class Tracing implements Component {
constructor(
config: NormalizedConfig, private readonly traceAgent: TraceAgent) {
this.config = config;
this.traceAgent = traceAgent;
let logLevel = config.enabled ? config.logLevel : 0;
// Clamp the logger level.
if (logLevel < 0) {
Expand Down Expand Up @@ -103,27 +102,30 @@ export class Tracing implements Component {
return;
}

// Initialize context propagation mechanism configuration.
const clsConfig: Forceable<TraceCLSConfig> = {
mechanism: this.config.clsMechanism as TraceCLSMechanism,
[FORCE_NEW]: this.config[FORCE_NEW]
};
try {
// Initialize context propagation mechanism.
const clsConfig: Forceable<TraceCLSConfig> = {
mechanism: this.config.clsMechanism as TraceCLSMechanism,
[FORCE_NEW]: this.config[FORCE_NEW]
};
cls.create(clsConfig, this.logger).enable();

traceWriter.create(this.config, this.logger).initialize((err) => {
if (err) {
this.disable();
}
});
traceWriter.create(this.config, this.logger);
cls.create(clsConfig, this.logger);
} catch (e) {
this.logger.error(
'TraceAgent#start: Disabling the Trace Agent for the',
`following reason: ${e.message}`);
this.disable();
return;
}

traceWriter.get().initialize((err) => {
if (err) {
this.logger.error(
'TraceAgent#start: Disabling the Trace Agent for the',
`following reason: ${err.message}`);
this.disable();
}
});
cls.get().enable();
this.traceAgent.enable(this.config, this.logger);
pluginLoader.create(this.config, this.logger).activate();

Expand Down

0 comments on commit 6f00010

Please sign in to comment.