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());
}
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());
}
}
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);
}
}
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);
}
}
Aggregations