-
Notifications
You must be signed in to change notification settings - Fork 21
Refactor Tracer to check presence of Zone global variable #103
Refactor Tracer to check presence of Zone global variable #103
Conversation
Codecov Report
@@ Coverage Diff @@
## master #103 +/- ##
==========================================
+ Coverage 96.23% 96.29% +0.05%
==========================================
Files 26 26
Lines 637 647 +10
Branches 80 83 +3
==========================================
+ Hits 613 623 +10
Misses 24 24
Continue to review full report at Codecov.
|
private static singletonInstance: Tracer; | ||
|
||
/** Gets the tracer instance. */ | ||
static get instance(): Tracer { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What's the motivation for adding this instance
getter?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I saw that opencensus node does it and I think is more understandable that Tracer
is a Singleton class.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OK, makes sense.
@@ -23,7 +23,7 @@ export const NOOP_EXPORTER = new NoopExporter(); | |||
/** Main interface for tracing. */ | |||
export class Tracing implements webTypes.Tracing { | |||
/** Object responsible for managing a trace. */ | |||
readonly tracer = new Tracer(); | |||
readonly tracer = Tracer.instance; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this similar to how OpenCensus Node does it?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, I saw they do it like this, and it is more understandable that this class is Singleton.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sounds good!
This checks the presence of
Zone
in Tracer as there might be some case wherezone.js
library is not imported.Also, modify
Tracer
to be Singleton as there will be only one instance.