16
16
17
17
package com .example .errorreporting ;
18
18
19
- //[START errorreporting_quickstart]
19
+ // [START errorreporting_quickstart]
20
+ // [START error_reporting_quickstart]
21
+
20
22
import com .google .cloud .ServiceOptions ;
21
23
import com .google .cloud .errorreporting .v1beta1 .ReportErrorsServiceClient ;
22
24
import com .google .devtools .clouderrorreporting .v1beta1 .ErrorContext ;
26
28
27
29
/**
28
30
* Snippet demonstrates using the Stackdriver Error Reporting API to report a custom error event.
29
-
31
+ * <p>
30
32
* This library is not required on App Engine, errors written to stderr are automatically written
31
33
* to Stackdriver Error Reporting.
32
34
* It is also not required if you are writing logs to Stackdriver Logging.
@@ -46,21 +48,22 @@ public static void main(String[] args) throws Exception {
46
48
// Custom error events require an error reporting location as well.
47
49
ErrorContext errorContext = ErrorContext .newBuilder ()
48
50
.setReportLocation (SourceLocation .newBuilder ()
49
- .setFilePath ("Test.java" )
50
- .setLineNumber (10 )
51
- .setFunctionName ("myMethod" )
52
- .build ())
51
+ .setFilePath ("Test.java" )
52
+ .setLineNumber (10 )
53
+ .setFunctionName ("myMethod" )
54
+ .build ())
53
55
.build ();
54
56
55
57
//Report a custom error event
56
58
ReportedErrorEvent customErrorEvent = ReportedErrorEvent .getDefaultInstance ()
57
- .toBuilder ()
58
- .setMessage ("custom error event" )
59
- .setContext (errorContext )
60
- .build ();
59
+ .toBuilder ()
60
+ .setMessage ("custom error event" )
61
+ .setContext (errorContext )
62
+ .build ();
61
63
// Report an event synchronously, use .reportErrorEventCallable for asynchronous reporting.
62
64
reportErrorsServiceClient .reportErrorEvent (projectName , customErrorEvent );
63
65
}
64
66
}
65
67
}
68
+ // [END error_reporting_quickstart]
66
69
// [END errorreporting_quickstart]
0 commit comments