forked from vercel/next.js
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.ts
53 lines (47 loc) · 1.08 KB
/
index.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
import { SpanId } from '../shared'
import reportToTelemetry from './to-telemetry'
import reportToJson from './to-json'
type Reporter = {
flushAll: () => Promise<void> | void
report: (
spanName: string,
duration: number,
timestamp: number,
id: SpanId,
parentId?: SpanId,
attrs?: Object,
startTime?: number
) => void
}
class MultiReporter implements Reporter {
private reporters: Reporter[] = []
constructor(reporters: Reporter[]) {
this.reporters = reporters
}
async flushAll() {
await Promise.all(this.reporters.map((reporter) => reporter.flushAll()))
}
report(
spanName: string,
duration: number,
timestamp: number,
id: SpanId,
parentId?: SpanId,
attrs?: Object,
startTime?: number
) {
this.reporters.forEach((reporter) =>
reporter.report(
spanName,
duration,
timestamp,
id,
parentId,
attrs,
startTime
)
)
}
}
// JSON is always reported to allow for diagnostics
export const reporter = new MultiReporter([reportToJson, reportToTelemetry])