Search in sources :

Example 1 with ReportErrorsServiceClient

use of com.google.cloud.errorreporting.v1beta1.ReportErrorsServiceClient in project java-docs-samples by GoogleCloudPlatform.

the class ErrorReportingExample method logCustomErrorEvent.

private void logCustomErrorEvent() {
    try (ReportErrorsServiceClient reportErrorsServiceClient = ReportErrorsServiceClient.create()) {
        // Custom error events require an error reporting location as well.
        ErrorContext errorContext = ErrorContext.newBuilder().setReportLocation(SourceLocation.newBuilder().setFilePath("Test.java").setLineNumber(10).setFunctionName("myMethod").build()).build();
        // Report a custom error event
        ReportedErrorEvent customErrorEvent = ReportedErrorEvent.getDefaultInstance().toBuilder().setMessage("custom error event").setContext(errorContext).build();
        // default project id
        ProjectName projectName = ProjectName.of(ServiceOptions.getDefaultProjectId());
        reportErrorsServiceClient.reportErrorEvent(projectName, customErrorEvent);
    } catch (Exception e) {
        logger.log(Level.SEVERE, "Exception encountered logging custom event", e);
    }
}
Also used : ProjectName(com.google.devtools.clouderrorreporting.v1beta1.ProjectName) ErrorContext(com.google.devtools.clouderrorreporting.v1beta1.ErrorContext) ReportedErrorEvent(com.google.devtools.clouderrorreporting.v1beta1.ReportedErrorEvent) ReportErrorsServiceClient(com.google.cloud.errorreporting.v1beta1.ReportErrorsServiceClient) ServletException(javax.servlet.ServletException) IOException(java.io.IOException)

Example 2 with ReportErrorsServiceClient

use of com.google.cloud.errorreporting.v1beta1.ReportErrorsServiceClient in project java-docs-samples by GoogleCloudPlatform.

the class QuickStart method main.

public static void main(String[] args) throws Exception {
    // Google Cloud Platform Project ID
    String projectId = (args.length > 0) ? args[0] : ServiceOptions.getDefaultProjectId();
    ProjectName projectName = ProjectName.of(projectId);
    // Instantiate an Error Reporting Client
    try (ReportErrorsServiceClient reportErrorsServiceClient = ReportErrorsServiceClient.create()) {
        // Custom error events require an error reporting location as well.
        ErrorContext errorContext = ErrorContext.newBuilder().setReportLocation(SourceLocation.newBuilder().setFilePath("Test.java").setLineNumber(10).setFunctionName("myMethod").build()).build();
        // Report a custom error event
        ReportedErrorEvent customErrorEvent = ReportedErrorEvent.getDefaultInstance().toBuilder().setMessage("custom error event").setContext(errorContext).build();
        // Report an event synchronously, use .reportErrorEventCallable for asynchronous reporting.
        reportErrorsServiceClient.reportErrorEvent(projectName, customErrorEvent);
    }
}
Also used : ProjectName(com.google.devtools.clouderrorreporting.v1beta1.ProjectName) ErrorContext(com.google.devtools.clouderrorreporting.v1beta1.ErrorContext) ReportedErrorEvent(com.google.devtools.clouderrorreporting.v1beta1.ReportedErrorEvent) ReportErrorsServiceClient(com.google.cloud.errorreporting.v1beta1.ReportErrorsServiceClient)

Aggregations

ReportErrorsServiceClient (com.google.cloud.errorreporting.v1beta1.ReportErrorsServiceClient)2 ErrorContext (com.google.devtools.clouderrorreporting.v1beta1.ErrorContext)2 ProjectName (com.google.devtools.clouderrorreporting.v1beta1.ProjectName)2 ReportedErrorEvent (com.google.devtools.clouderrorreporting.v1beta1.ReportedErrorEvent)2 IOException (java.io.IOException)1 ServletException (javax.servlet.ServletException)1