-
Notifications
You must be signed in to change notification settings - Fork 96
Make Stats singleton (globalStats), separate registerView from createView #291
Make Stats singleton (globalStats), separate registerView from createView #291
Conversation
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 general motivation for the breaking change?
// Stats singleton instance | ||
import {BaseStats} from './stats/stats'; | ||
import {Stats} from './stats/types'; | ||
const globalStats: Stats = BaseStats.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 the : Stats
type specifier needed here?
Those are useful for enforcing the type assignment to a structural type like const x: Y = {...}
, but since BaseStats.instance
already has a type I would think it isn't needed.
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.
This is added to avoid compiler error -> Exported variable 'globalStats' has or is using name 'Stats' from external module "/opencensus-core/src/stats/types" but cannot be named.
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.
@draffensperger Are you ok with my comment or you have better approach to handle this?
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, that makes sense, thanks for clarifying.
// Create a new MetricProducerForStats and register it to | ||
// MetricProducerManager when Stats is initialized. | ||
// const metricProducer: MetricProducer = new MetricProducerForStats(this); | ||
// Metrics.getMetricProducerManager().add(metricProducer); | ||
const metricProducer: MetricProducer = new MetricProducerForStats(this); |
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.
Similar here on not needing the : MetricProducer
type annotation since it's implied.
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.
done.
} | ||
|
||
/** | ||
* Registers a view to listen to new measurements in its measure. Prefer using | ||
* the method createView() that creates an already registered view. | ||
* @param view The view to be registered | ||
*/ | ||
registerView(view: View) { | ||
registerView(view: View): void { |
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.
Nit: do we need to include : void
here? (Same comment applies to the other methods below)
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.
This not really required, but we are already using the same notion in other classes. I was trying to make things consistent.
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, I think that's fine.
|
||
/** | ||
* Registers a view to listen to new measurements in its measure. Prefer using | ||
* the method createView() that creates an already registered view. |
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 comment about creating an already registered view still true given the change above to remove the registerView
call in the createView
implementation above?
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.
Good catch, removed obsolete comment.
* the method createView() that creates an already registered view. | ||
* @param view The view to be registered | ||
*/ | ||
registerView(view: View): void; |
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.
Do we need : void
here? (Same comment applies to registerExporter
below).
|
Thanks for the explanation. Is the plan to go directly to GA or will there be an intermediate Beta release? |
I am not 100% sure about this. All the work related to GA Release / Feature Parity work effort available here : https://github.com/census-instrumentation/opencensus-node/issues?q=is%3Aopen+is%3Aissue+label%3AGA-Effort |
0ce384e
to
5e8ac8c
Compare
This PR is based on #276.
This PR contains two breaking changes:
new Stats()
has been deprecated on Stats class. The global singletonglobalStats
object should be used instead.registerView()
hook has been removed fromcreateView()
API. This is related to No need tostats.registerView(view)
#287.Fixes #290 #276