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