/// <summary> /// Creates a <seealso cref="ReportRequest"/> from a given exception. /// </summary> private static ReportRequest CreateReportRequest(Exception e) { // Create the service. ClouderrorreportingService service = CreateErrorReportingClient(); // Get the project ID from the environement variables. string projectId = Environment.GetEnvironmentVariable("GOOGLE_PROJECT_ID"); // Format the project id to the format Error Reporting expects. See: // https://cloud.google.com/error-reporting/reference/rest/v1beta1/projects.events/report string formattedProjectId = string.Format("projects/{0}", projectId); // Add a service context to the report. For more details see: // https://cloud.google.com/error-reporting/reference/rest/v1beta1/projects.events#ServiceContext ServiceContext serviceContext = new ServiceContext() { Service = "myapp", Version = "8c1917a9eca3475b5a3686d1d44b52908463b989", }; ReportedErrorEvent errorEvent = new ReportedErrorEvent() { Message = e.ToString(), ServiceContext = serviceContext, }; return(new ReportRequest(service, errorEvent, formattedProjectId)); }
/// <param name="body">A valid Clouderrorreporting v1beta1 body.</param> /// <returns>ErrorGroupResponse</returns> public static ErrorGroup Update(ClouderrorreportingService service, string name, ErrorGroup body) { try { // Initial validation. if (service == null) { throw new ArgumentNullException("service"); } if (body == null) { throw new ArgumentNullException("body"); } if (name == null) { throw new ArgumentNullException(name); } // Make the request. return(service.Groups.Update(body, name).Execute()); } catch (Exception ex) { throw new Exception("Request Groups.Update failed.", ex); } }
/// <summary> /// Creates a <seealso cref="ReportRequest"/> from a given exception. /// </summary> private static ReportRequest CreateReportRequest(Exception e) { // Create the service. ClouderrorreportingService service = CreateErrorReportingClient(); // Format the project id to the format Error Reporting expects. See: // https://cloud.google.com/error-reporting/reference/rest/v1beta1/projects.events/report string formattedProjectId = string.Format("projects/{0}", ProjectId); // Add a service context to the report. For more details see: // https://cloud.google.com/error-reporting/reference/rest/v1beta1/projects.events#ServiceContext ServiceContext serviceContext = new ServiceContext() { Service = "e_reporting", Version = "the-exceptional-api-version" }; ErrorContext errorContext = new ErrorContext() { ReportLocation = new SourceLocation() { FunctionName = "A hidden Name" } }; ReportedErrorEvent errorEvent = new ReportedErrorEvent() { Message = e.ToString(), ServiceContext = serviceContext, Context = errorContext }; return(new ReportRequest(service, errorEvent, formattedProjectId)); }
/// <summary> /// Create the Error Reporting service (<seealso cref="ClouderrorreportingService"/>) /// with the Application Default Credentials and the proper scopes. /// See: https://developers.google.com/identity/protocols/application-default-credentials. /// </summary> private static ClouderrorreportingService CreateErrorReportingClient() { // Get the Application Default Credentials. GoogleCredential credential = GoogleCredential.GetApplicationDefaultAsync().Result; // Add the needed scope to the credentials. credential.CreateScoped(ClouderrorreportingService.Scope.CloudPlatform); // Create the Error Reporting Service. ClouderrorreportingService service = new ClouderrorreportingService(new BaseClientService.Initializer { HttpClientInitializer = credential, }); return service; }
/// <summary> /// Create the Error Reporting service (<seealso cref="ClouderrorreportingService"/>) /// with the Application Default Credentials and the proper scopes. /// See: https://developers.google.com/identity/protocols/application-default-credentials. /// </summary> private static ClouderrorreportingService CreateErrorReportingClient() { // Get the Application Default Credentials. GoogleCredential credential = GoogleCredential.GetApplicationDefaultAsync().Result; // Add the needed scope to the credentials. credential.CreateScoped(ClouderrorreportingService.Scope.CloudPlatform); // Create the Error Reporting Service. ClouderrorreportingService service = new ClouderrorreportingService(new BaseClientService.Initializer { HttpClientInitializer = credential, }); return(service); }