File size: 684 Bytes
1e92f2d
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
import type { TraceEvent } from '../types'
import reportToTelemetry from './to-telemetry'
import reportToJson from './to-json'
import type { Reporter } from './types'

class MultiReporter implements Reporter {
  private reporters: Reporter[] = []

  constructor(reporters: Reporter[]) {
    this.reporters = reporters
  }

  async flushAll(opts?: { end: boolean }) {
    await Promise.all(this.reporters.map((reporter) => reporter.flushAll(opts)))
  }

  report(event: TraceEvent) {
    this.reporters.forEach((reporter) => reporter.report(event))
  }
}

// JSON is always reported to allow for diagnostics
export const reporter = new MultiReporter([reportToJson, reportToTelemetry])