import ApplicationInsights = require ( "applicationinsights" ) ; import { channel , IStandardEvent } from "diagnostic-channel" ; import { mongodb } from "diagnostic-channel-publishers" ; export const subscriber = ( event ) => { if ( ApplicationInsights . defaultClient ) { const dbName = ( event . data . startedData && event . data . startedData . databaseName ) || "Unknown database" ; ApplicationInsights . defaultClient . trackDependency ( { target : dbName , name : event . data . event . commandName , data : event . data . event . commandName , duration : event . data . event . duration , success : event . data . succeeded , resultCode : event . data . succeeded ? "0" : "1" , dependencyTypeName : "mongodb" } ) ; if ( ! event . data . succeeded ) { ApplicationInsights . defaultClient . trackException ( { exception : new Error ( event . data . event . failure ) } ) ; } } } ; channel . subscribe < mongodb . IMongoData > ( "mongodb" , subscriber ) ;