29
29
30
30
/**
31
31
* Snippet demonstrates using the Cloud Error Reporting API to report a custom error event.
32
- * <p>
33
- * This library is not required on App Engine, errors written to stderr are automatically written
34
- * to Cloud Error Reporting.
35
- * It is also not required if you are writing logs to Cloud Logging.
36
- * Errors written to Cloud Logging that contain an exception or stack trace
37
- * are automatically written out to Cloud Error Reporting.
32
+ *
33
+ * <p>This library is not required on App Engine, errors written to stderr are automatically written
34
+ * to Cloud Error Reporting. It is also not required if you are writing logs to Cloud Logging.
35
+ * Errors written to Cloud Logging that contain an exception or stack trace are automatically
36
+ * written out to Cloud Error Reporting.
38
37
*/
39
38
public class QuickStart {
40
39
public static void main (String [] args ) throws Exception {
@@ -47,20 +46,23 @@ public static void main(String[] args) throws Exception {
47
46
try (ReportErrorsServiceClient reportErrorsServiceClient = ReportErrorsServiceClient .create ()) {
48
47
49
48
// Custom error events require an error reporting location as well.
50
- ErrorContext errorContext = ErrorContext .newBuilder ()
51
- .setReportLocation (SourceLocation .newBuilder ()
52
- .setFilePath ("Test.java" )
53
- .setLineNumber (10 )
54
- .setFunctionName ("myMethod" )
55
- .build ())
56
- .build ();
49
+ ErrorContext errorContext =
50
+ ErrorContext .newBuilder ()
51
+ .setReportLocation (
52
+ SourceLocation .newBuilder ()
53
+ .setFilePath ("Test.java" )
54
+ .setLineNumber (10 )
55
+ .setFunctionName ("myMethod" )
56
+ .build ())
57
+ .build ();
57
58
58
- //Report a custom error event
59
- ReportedErrorEvent customErrorEvent = ReportedErrorEvent .getDefaultInstance ()
60
- .toBuilder ()
61
- .setMessage ("custom error event" )
62
- .setContext (errorContext )
63
- .build ();
59
+ // Report a custom error event
60
+ ReportedErrorEvent customErrorEvent =
61
+ ReportedErrorEvent .getDefaultInstance ()
62
+ .toBuilder ()
63
+ .setMessage ("custom error event" )
64
+ .setContext (errorContext )
65
+ .build ();
64
66
// Report an event synchronously, use .reportErrorEventCallable for asynchronous reporting.
65
67
reportErrorsServiceClient .reportErrorEvent (projectName , customErrorEvent );
66
68
}
0 commit comments