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

Commit fed0ad4

Browse files
authored
Add start method to StatsEventListener (#259)
With the current approach, we are calling onRegisterView (whenever a new view is registered) and onRecord (whenever a new measurement is recorded). With the new approach, plan is to start exporter that polls Metric from Metrics library and send batched data to backend.
1 parent c5c1c4c commit fed0ad4

7 files changed

Lines changed: 46 additions & 0 deletions

File tree

packages/opencensus-core/src/exporters/console-exporter.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,4 +96,12 @@ export class ConsoleStatsExporter implements types.StatsEventListener {
9696
onRecord(views: View[], measurement: Measurement) {
9797
console.log(`Measurement recorded: ${measurement.measure.name}`);
9898
}
99+
100+
/**
101+
* Starts the Console exporter that polls Metric from Metrics library and
102+
* shows in the log console..
103+
*/
104+
start(): void {
105+
// TODO(mayurkale): dependency with PR#253.
106+
}
99107
}

packages/opencensus-core/src/exporters/types.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,15 +34,23 @@ export interface Exporter extends modelTypes.SpanEventListener {
3434
export interface StatsEventListener {
3535
/**
3636
* Is called whenever a new view is registered
37+
* @deprecated since version 0.0.9 - use {@link start} instead
3738
* @param view The registered view
3839
*/
3940
onRegisterView(view: View): void;
4041
/**
4142
* Is called whenever a new measurement is recorded.
43+
* @deprecated since version 0.0.9 - use {@link start} instead
4244
* @param views The views related to the measurement
4345
* @param measurement The recorded measurement
4446
*/
4547
onRecord(views: View[], measurement: Measurement): void;
48+
49+
/**
50+
* Starts the exporter that polls Metric from Metrics library and send
51+
* batched data to backend.
52+
*/
53+
start(): void;
4654
}
4755

4856
export type ExporterConfig = configTypes.BufferConfig;

packages/opencensus-core/src/stats/stats.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,10 @@ export class Stats {
9090
exporter.onRegisterView(view);
9191
}
9292
}
93+
94+
// dependency with PR#253 and once start method is implemented in all stats
95+
// exporters
96+
// exporter.start();
9397
}
9498

9599
/**

packages/opencensus-core/test/test-stats.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,10 @@ class TestExporter implements StatsEventListener {
3030
this.recordedMeasurements.push(measurement);
3131
}
3232

33+
start(): void {
34+
// TODO(mayurkale): dependency with PR#253.
35+
}
36+
3337
clean() {
3438
this.registeredViews = [];
3539
this.recordedMeasurements = [];

packages/opencensus-exporter-prometheus/src/prometheus-stats.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,15 @@ export class PrometheusStatsExporter implements StatsEventListener {
8484
}
8585
}
8686

87+
/**
88+
* Starts the Prometheus exporter that polls Metric from Metrics library and
89+
* send batched data to backend.
90+
*/
91+
start(): void {
92+
// TODO(mayurkale): add setInterval here to poll Metric, transform and send
93+
// // it to backend (dependency with PR#253).
94+
}
95+
8796
/**
8897
* Register or get a metric in Prometheus
8998
* @param view View will be used to register the metric

packages/opencensus-exporter-stackdriver/src/stackdriver-monitoring.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,15 @@ export class StackdriverStatsExporter implements StatsEventListener {
9797
}
9898
}
9999

100+
/**
101+
* Starts the Stackdriver exporter that polls Metric from Metrics library and
102+
* send batched data to backend.
103+
*/
104+
start(): void {
105+
// TODO(mayurkale): add setInterval here to poll Metric, transform and send
106+
// // it to backend (dependency with PR#253).
107+
}
108+
100109
/**
101110
* Clear the interval timer to stop uploading metrics. It should be called
102111
* whenever the exporter is not needed anymore.

packages/opencensus-exporter-zpages/src/zpages.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,10 @@ export class ZpagesExporter implements Exporter, StatsEventListener {
127127
});
128128
}
129129

130+
start(): void {
131+
// TODO(mayurkale): dependency with PR#253.
132+
}
133+
130134
/**
131135
* Send a trace to traces array
132136
* @param trace the rootSpan to be sent to the array list

0 commit comments

Comments
 (0)