All files / app/service diagnostics.ts

100% Statements 16/16
100% Branches 0/0
100% Functions 1/1
100% Lines 16/16

Press n or j to go to the next uncovered block, b, p or k for the previous block.

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 351x 1x   1x                 1x       1x 1x   1x 1x 1x 1x 1x   1x 1x 1x   1x     1x    
import { Timestamp } from "google-protobuf/google/protobuf/timestamp_pb";
import { DiagnosticInfo, ReportDiagnosticsReq } from "proto/bugs_pb";
 
import client from "./client";
 
export interface DiagnosticEvent {
  tag: string;
  propertiesJson: string;
  value: number;
  occurred: Date;
}
 
export async function reportDiagnostics(
  events: DiagnosticEvent[],
  frontendVersion: string,
) {
  const req = new ReportDiagnosticsReq();
  req.setFrontendVersion(frontendVersion);
 
  for (const event of events) {
    const info = new DiagnosticInfo();
    info.setTag(event.tag);
    info.setPropertiesJson(event.propertiesJson);
    info.setValue(event.value);
 
    const ts = new Timestamp();
    ts.fromDate(event.occurred);
    info.setOccurred(ts);
 
    req.addInfos(info);
  }
 
  await client.bugs.reportDiagnostics(req);
}