Search in sources :

Example 1 with ReportedErrorEvent

use of com.google.devtools.clouderrorreporting.v1beta1.ReportedErrorEvent in project google-cloud-java by GoogleCloudPlatform.

the class ReportErrorsServiceClientTest method reportErrorEventTest.

@Test
@SuppressWarnings("all")
public void reportErrorEventTest() {
    ReportErrorEventResponse expectedResponse = ReportErrorEventResponse.newBuilder().build();
    mockReportErrorsService.addResponse(expectedResponse);
    ProjectName projectName = ProjectName.create("[PROJECT]");
    ReportedErrorEvent event = ReportedErrorEvent.newBuilder().build();
    ReportErrorEventResponse actualResponse = client.reportErrorEvent(projectName, event);
    Assert.assertEquals(expectedResponse, actualResponse);
    List<GeneratedMessageV3> actualRequests = mockReportErrorsService.getRequests();
    Assert.assertEquals(1, actualRequests.size());
    ReportErrorEventRequest actualRequest = (ReportErrorEventRequest) actualRequests.get(0);
    Assert.assertEquals(projectName, actualRequest.getProjectNameAsProjectName());
    Assert.assertEquals(event, actualRequest.getEvent());
}
Also used : ReportErrorEventRequest(com.google.devtools.clouderrorreporting.v1beta1.ReportErrorEventRequest) ProjectName(com.google.devtools.clouderrorreporting.v1beta1.ProjectName) ReportedErrorEvent(com.google.devtools.clouderrorreporting.v1beta1.ReportedErrorEvent) ReportErrorEventResponse(com.google.devtools.clouderrorreporting.v1beta1.ReportErrorEventResponse) GeneratedMessageV3(com.google.protobuf.GeneratedMessageV3) Test(org.junit.Test)

Example 2 with ReportedErrorEvent

use of com.google.devtools.clouderrorreporting.v1beta1.ReportedErrorEvent in project google-cloud-java by GoogleCloudPlatform.

the class ReportErrorsServiceClientTest method reportErrorEventExceptionTest.

@Test
@SuppressWarnings("all")
public void reportErrorEventExceptionTest() throws Exception {
    StatusRuntimeException exception = new StatusRuntimeException(Status.INVALID_ARGUMENT);
    mockReportErrorsService.addException(exception);
    try {
        ProjectName projectName = ProjectName.create("[PROJECT]");
        ReportedErrorEvent event = ReportedErrorEvent.newBuilder().build();
        client.reportErrorEvent(projectName, event);
        Assert.fail("No exception raised");
    } catch (ApiException e) {
        Assert.assertEquals(Status.INVALID_ARGUMENT.getCode(), e.getStatusCode());
    }
}
Also used : ProjectName(com.google.devtools.clouderrorreporting.v1beta1.ProjectName) StatusRuntimeException(io.grpc.StatusRuntimeException) ReportedErrorEvent(com.google.devtools.clouderrorreporting.v1beta1.ReportedErrorEvent) ApiException(com.google.api.gax.grpc.ApiException) Test(org.junit.Test)

Example 3 with ReportedErrorEvent

use of com.google.devtools.clouderrorreporting.v1beta1.ReportedErrorEvent 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 4 with ReportedErrorEvent

use of com.google.devtools.clouderrorreporting.v1beta1.ReportedErrorEvent 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

ProjectName (com.google.devtools.clouderrorreporting.v1beta1.ProjectName)4 ReportedErrorEvent (com.google.devtools.clouderrorreporting.v1beta1.ReportedErrorEvent)4 ReportErrorsServiceClient (com.google.cloud.errorreporting.v1beta1.ReportErrorsServiceClient)2 ErrorContext (com.google.devtools.clouderrorreporting.v1beta1.ErrorContext)2 Test (org.junit.Test)2 ApiException (com.google.api.gax.grpc.ApiException)1 ReportErrorEventRequest (com.google.devtools.clouderrorreporting.v1beta1.ReportErrorEventRequest)1 ReportErrorEventResponse (com.google.devtools.clouderrorreporting.v1beta1.ReportErrorEventResponse)1 GeneratedMessageV3 (com.google.protobuf.GeneratedMessageV3)1 StatusRuntimeException (io.grpc.StatusRuntimeException)1 IOException (java.io.IOException)1 ServletException (javax.servlet.ServletException)1