in cloudprober/src/main/java/com/google/grpc/cloudprober/StackdriverUtils.java [71:100]
public void reportError(String error, String funcName, int line) {
// Report to the std error.
System.err.println(error);
// Report to the stackdriver.
if (errClient != null) {
String projectId = ServiceOptions.getDefaultProjectId();
ProjectName projectName = ProjectName.of(projectId);
// Custom error events require an error reporting location as well.
ErrorContext errorContext =
ErrorContext.newBuilder()
.setReportLocation(
SourceLocation.newBuilder()
.setFilePath("Prober.java")
.setLineNumber(line)
.setFunctionName(funcName)
.build())
.build();
// Report a custom error event
ReportedErrorEvent customErrorEvent =
ReportedErrorEvent.getDefaultInstance()
.toBuilder()
.setMessage(error)
.setContext(errorContext)
.build();
// Report an event synchronously, use .reportErrorEventCallable for asynchronous reporting.
errClient.reportErrorEvent(projectName, customErrorEvent);
}
}