-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMultiExporters.ts
77 lines (76 loc) · 2.57 KB
/
MultiExporters.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
import {
InstrumentType, ResourceMetrics, PushMetricExporter, AggregationTemporality
} from '@opentelemetry/sdk-metrics';
import { ReadableSpan, SpanExporter } from "@opentelemetry/sdk-trace-base";
import { ExportResult } from '@opentelemetry/core';
export class MultiMetricExporter implements PushMetricExporter {
private exporters: PushMetricExporter[];
private isshutdown: boolean = false;
constructor(exporters: PushMetricExporter[]) {
this.exporters = exporters;
}
count() {
return this.exporters.length;
}
addExporter(exporter: PushMetricExporter) {
this.exporters.push(exporter);
}
export(metrics: ResourceMetrics, callback: (result: ExportResult) => void): void {
if (!this.exporters) return;
if (this.exporters.length == 0) return;
for (let i = 0; this.exporters.length > i; i++) {
try {
this.exporters[i].export(metrics, callback);
} catch (error) {
console.error(error);
}
}
}
async shutdown(): Promise<void> {
this.isshutdown = true;
await Promise.all(this.exporters.map((e) => e.shutdown()));
}
async forceFlush(): Promise<void> {
this.exporters.forEach((exporter) => {
});
}
selectAggregationTemporality(instrumentType: InstrumentType): AggregationTemporality {
var res: AggregationTemporality = AggregationTemporality.CUMULATIVE;
for (let i = 0; this.exporters.length > i; i++) {
var experter = this.exporters[i];
try {
// @ts-ignore
res = experter.selectAggregationTemporality(instrumentType);
} catch (error) {
console.error(error);
}
}
return res;
}
}
export class MultiSpanExporter implements SpanExporter {
private exporters: SpanExporter[];
constructor(exporters: SpanExporter[]) {
this.exporters = exporters;
}
addExporter(exporter: SpanExporter) {
this.exporters.push(exporter);
}
export(
spans: ReadableSpan[],
callback: (result: ExportResult) => void,
): void {
if (!this.exporters) return;
if (this.exporters.length == 0) return;
for (let i = 0; this.exporters.length > i; i++) {
try {
this.exporters[i].export(spans, callback);
} catch (error) {
console.error(error);
}
}
}
async shutdown(): Promise<void> {
await Promise.all(this.exporters.map((e) => e.shutdown()));
}
}