diff --git a/errorreporting/README.md b/errorreporting/README.md
new file mode 100644
index 00000000000..1b99992710b
--- /dev/null
+++ b/errorreporting/README.md
@@ -0,0 +1,35 @@
+# Stackdriver Error Reporting sample
+
+[Stackdriver Error Reporting][error-reporting] Stackdriver Error Reporting counts, analyzes and aggregates the crashes in your running cloud services.
+A [centralized error management interface](https://console.cloud.google.com/errors) displays the results with sorting and filtering capabilities.
+
+This sample Java application demonstrates how to send custom error events using the [Error Reporting API][api-ref-docs].
+Note: Runtime exceptions and stack traces are automatically sent to Error reporting in applications running in [App Engine Flex environment][ae-flex].
+
+[ae-flex]: https://cloud.google.com/appengine/docs/flexible/java
+[error-reporting]: https://cloud.google.com/error-reporting/
+[api-ref-docs]: https://googlecloudplatform.github.io/google-cloud-java/latest/apidocs/index.html?com/google/cloud/errorreporting/v1beta1/package-summary.html
+
+## Setup
+
+1. Install [Maven](http://maven.apache.org/).
+1. [Enable](https://console.cloud.google.com/apis/api/clouderrorreporting.googleapis.com/overview) Stack Driver Error Reporting API.
+
+## Build
+
+Build your project with:
+```
+ mvn clean package
+```
+
+## Local testing
+
+1. [Create a service account](https://cloud.google.com/docs/authentication/getting-started#creating_the_service_account)
+and set the `GOOGLE_APPLICATION_CREDENTIALS` environment variable.
+2. Run
+```
+ mvn clean verify
+```
+Check the [error reporting console](https://console.cloud.google.com/errors).
+
+Confirm that you see the custom errors reported using the Error Reporting API.
diff --git a/errorreporting/pom.xml b/errorreporting/pom.xml
new file mode 100644
index 00000000000..3b8a21f7825
--- /dev/null
+++ b/errorreporting/pom.xml
@@ -0,0 +1,49 @@
+
+
Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of the License at + * + *
http://www.apache.org/licenses/LICENSE-2.0 + * + *
Unless required by applicable law or agreed to in writing, software distributed under the + * License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either + * express or implied. See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.example.errorreporting; + +//[START errorreporting_quickstart] +import com.google.cloud.ServiceOptions; +import com.google.cloud.errorreporting.v1beta1.ReportErrorsServiceClient; +import com.google.devtools.clouderrorreporting.v1beta1.ErrorContext; +import com.google.devtools.clouderrorreporting.v1beta1.ProjectName; +import com.google.devtools.clouderrorreporting.v1beta1.ReportedErrorEvent; +import com.google.devtools.clouderrorreporting.v1beta1.SourceLocation; + +/** + * Snippet demonstrates using the Stackdriver Error Reporting API to report a custom error event. + + * This library is not required on App Engine, errors written to stderr are automatically written + * to Stackdriver Error Reporting. + * It is also not required if you are writing logs to Stackdriver Logging. + * Errors written to Stackdriver Logging that contain an exception or stack trace + * are automatically written out to Stackdriver Error Reporting. + */ +public class QuickStart { + 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.create(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); + } + } +} +// [END errorreporting_quickstart] diff --git a/errorreporting/src/test/java/com/example/errorreporting/QuickStartIT.java b/errorreporting/src/test/java/com/example/errorreporting/QuickStartIT.java new file mode 100644 index 00000000000..b0f08a1f620 --- /dev/null +++ b/errorreporting/src/test/java/com/example/errorreporting/QuickStartIT.java @@ -0,0 +1,30 @@ +/** + * Copyright 2017 Google Inc. + * + *
Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of the License at + * + *
http://www.apache.org/licenses/LICENSE-2.0 + * + *
Unless required by applicable law or agreed to in writing, software distributed under the
+ * License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
+ * express or implied. See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.example.errorreporting;
+
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.junit.runners.JUnit4;
+
+@RunWith(JUnit4.class)
+@SuppressWarnings("AbbreviationAsWordInName")
+public class QuickStartIT {
+
+ @Test
+ public void testQuickStart() throws Exception {
+ // Ensure quick start runs without any exception
+ QuickStart.main(new String[]{});
+ }
+}
diff --git a/flexible/errorreporting/README.md b/flexible/errorreporting/README.md
index 089cbfb8fb3..b27ba8ca1f0 100644
--- a/flexible/errorreporting/README.md
+++ b/flexible/errorreporting/README.md
@@ -24,10 +24,9 @@ Build your project with:
```
## Local testing
-1. Authorize the local environment
-```
- gcloud auth application-default login
-```
+[Create a service account](https://cloud.google.com/docs/authentication/getting-started#creating_the_service_account)
+and set the `GOOGLE_APPLICATION_CREDENTIALS` environment variable.
+
For local testing, we will be using the [Jetty Maven plugin](http://www.eclipse.org/jetty/documentation/9.4.x/jetty-maven-plugin.html).
Run:
```
diff --git a/flexible/errorreporting/pom.xml b/flexible/errorreporting/pom.xml
index 6254dfb9952..6d4ea073bc9 100644
--- a/flexible/errorreporting/pom.xml
+++ b/flexible/errorreporting/pom.xml
@@ -36,22 +36,6 @@