import * as appinsights from "applicationinsights" ; import { ITelemetryBaseEvent } from "@fluidframework/common-definitions" ; import { ITelemetryBufferedLogger } from "@fluidframework/test-driver-definitions" ; export class AppInsightsTestLogger implements ITelemetryBufferedLogger { protected readonly telemetryClient : appinsights . TelemetryClient ; public constructor ( ) { appinsights . setup ( ) . start ( ) ; this . telemetryClient = appinsights . defaultClient ; if ( process . env . FLUID_TEST_UID !== undefined ) { this . telemetryClient . commonProperties . testUid = process . env . FLUID_TEST_UID ; } if ( process . env . login__odsp__test__accounts !== undefined ) { const passwords = JSON . parse ( process . env . login__odsp__test__accounts ) ; const users = Object . keys ( passwords ) ; const username = users [ 0 ] ; this . telemetryClient . commonProperties . envUserName = username ; } } async flush ( runInfo ? ) { await new Promise < void > ( ( resolve ) => { this . telemetryClient . flush ( { callback : ( ) => resolve ( ) } ) ; } ) ; } send ( event ) { event . Event_Time = Date . now ( ) ; if ( event . category === "metric" ) { this . telemetryClient . trackMetric ( { name : event . eventName , value : event . value as number , tagOverrides : { category : event . category } , properties : event } ) ; } else { this . telemetryClient . trackEvent ( { name : event . eventName , tagOverrides : { category : event . category } , properties : event } ) ; } } } const _global = global ; _global . getTestLogger = ( ) => new AppInsightsTestLogger ( ) ;