public class ApplicationInsightsDiagnosticListener : ExecutionDiagnosticEventListener
{
      private readonly TelemetryClient _telemetryClient;

      public ApplicationInsightsDiagnosticListener(TelemetryClient telemetryClient)
      {
            _telemetryClient = telemetryClient;
      }

      public override void RequestError(IRequestContext context, Exception exception)
      {
          _telemetryClient.TrackException(error.Exception);
      }

      public override void ResolverError(IMiddlewareContext context, IError error)
      {
          if (error.Exception == null)
          {
              var exceptionTelemetry = new ExceptionTelemetry();
              exceptionTelemetry.Message = error.Message;
              _telemetryClient.TrackException(exceptionTelemetry);
          }
          else
          {
            _telemetryClient.TrackException(error.Exception);           
          }
      }
      
}