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

Commit 0a49765

Browse files
authored
Adds 1 minute delay on record for [exporter-stackdriver] (#150)
1 parent fe4d4ae commit 0a49765

File tree

3 files changed

+15
-2
lines changed

3 files changed

+15
-2
lines changed

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

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,13 @@ const monitoring = google.monitoring('v3');
2525

2626
/** Format and sends Stats to Stackdriver */
2727
export class StackdriverStatsExporter implements StatsEventListener {
28+
private delay: number;
2829
private projectId: string;
30+
static readonly DELAY: number = 60000;
2931
logger: Logger;
3032

3133
constructor(options: StackdriverExporterOptions) {
34+
this.delay = options.delay || StackdriverStatsExporter.DELAY;
3235
this.projectId = options.projectId;
3336
this.logger = options.logger || logger.logger();
3437
}
@@ -59,7 +62,11 @@ export class StackdriverStatsExporter implements StatsEventListener {
5962
* @param views The views associated with the measure
6063
* @param measurement The measurement recorded
6164
*/
62-
onRecord(views: View[], measurement: Measurement) {
65+
async onRecord(views: View[], measurement: Measurement) {
66+
await new Promise(resolve => {
67+
setTimeout(resolve, this.delay);
68+
});
69+
6370
const timeSeries = views.map(view => {
6471
return this.createTimeSeriesData(view, measurement);
6572
});

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,8 @@ export type TranslatedSpan = {
3636
* Options for stackdriver configuration
3737
*/
3838
export interface StackdriverExporterOptions extends ExporterConfig {
39+
/** Delay in milliseconds */
40+
delay?: number;
3941
/**
4042
* projectId project id defined to stackdriver
4143
*/

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

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,11 @@ describe('Stackdriver Stats Exporter', function() {
173173
}
174174
}
175175

176-
exporterOptions = {projectId: PROJECT_ID, logger: exporterTestLogger};
176+
exporterOptions = {
177+
delay: 0,
178+
projectId: PROJECT_ID,
179+
logger: exporterTestLogger
180+
};
177181
exporter = new StackdriverStatsExporter(exporterOptions);
178182
stats.registerExporter(exporter);
179183

0 commit comments

Comments
 (0)