Skip to content

Commit 9de91cd

Browse files
committed
Doc error-reporting integration with logs
Document loggin-{winston,bunyan} and error-reporting from each other's README files.
1 parent 0ef2737 commit 9de91cd

3 files changed

Lines changed: 30 additions & 3 deletions

File tree

packages/error-reporting/README.md

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,21 @@
99
This module provides Stackdriver Error Reporting support for Node.js applications.
1010
[Stackdriver Error Reporting](https://cloud.google.com/error-reporting/) is a feature of
1111
Google Cloud Platform that allows in-depth monitoring and viewing of errors reported by
12-
applications running in almost any environment.
12+
applications running in almost any environment.
1313

1414
![Stackdriver Error Reporting overview](doc/images/errors-overview.png)
1515

1616
Here's an introductory video that provides some more details:
1717

1818
[![Learn about Error Reporting in Stackdriver](https://img.youtube.com/vi/cVpWVD75Hs8/0.jpg)](https://www.youtube.com/watch?v=cVpWVD75Hs8)
1919

20+
Note that [@google-cloud/logging-winston][logging-winston] and
21+
[@google-cloud/logging-bunyan][logging-bunyan] automatically integrate with the
22+
Error Reporting service for Error objects logged at severity `error` or higher,
23+
for applications running on Google Cloud Platform. If you are already using
24+
Winston or Bunyan in your application, and don't need direct access/control of
25+
error reporting, you may want to check those modules as well.
26+
2027
## Prerequisites
2128

2229
1. Your application needs to use Node.js version 4.x or greater.
@@ -48,6 +55,9 @@ var errors = require('@google-cloud/error-reporting')({
4855

4956
// Report an error to the Stackdriver Error Reporting API
5057
errors.report(new Error('Something broke!'));
58+
59+
// We also provide error handling middleware for express, hapi, restify & koa.
60+
// See sections below.
5161
```
5262

5363
3. **View reported errors:**
@@ -184,6 +194,8 @@ app.get('/exception', () => {
184194
JSON.parse('{\"malformedJson\": true');
185195
});
186196

197+
// Note that express error handling middleware should be attached after all
198+
// the other routes and use() calls. See [express docs][express-error-docs].
187199
app.use(errors.express);
188200

189201
app.listen(3000);
@@ -253,10 +265,13 @@ server.head('/hello/:name', respond);
253265
server.listen(3000);
254266
```
255267

256-
[gcloud-sdk]: https://cloud.google.com/sdk/gcloud/
257268
[app-default-credentials]: https://developers.google.com/identity/protocols/application-default-credentials
258-
[service-account]: https://console.developers.google.com/apis/credentials/serviceaccountkey
269+
[express-error-docs]: https://expressjs.com/en/guide/error-handling.html
270+
[gcloud-sdk]: https://cloud.google.com/sdk/gcloud/
271+
[logging-bunyan]: https://www.npmjs.com/package/@google-cloud/logging-bunyan
272+
[logging-winston]: https://www.npmjs.com/package/@google-cloud/logging-winston
259273
[npm-image]: https://badge.fury.io/js/%40google-cloud%2Ferror-reporting.svg
260274
[npm-url]: https://npmjs.org/package/@google-cloud/error-reporting
275+
[service-account]: https://console.developers.google.com/apis/credentials/serviceaccountkey
261276
[snyk-image]: https://snyk.io/test/npm/@google-cloud/error-reporting/badge.svg
262277
[snyk-url]: https://snyk.io/test/npm/@google-cloud/error-reporting

packages/logging-bunyan/README.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,10 @@ var loggingBunyan = require('@google-cloud/logging-bunyan')({
6666
// ...you're good to go!
6767
```
6868

69+
## Error Reporting
70+
71+
Any `Error` objects you log at severity `error` at higher can automatically be picked up by [Stackdriver Error Reporting][error-reporting] if your application is running on Google Cloud Platform. You may also want to see [@google-cloud/error-reporting][@google-cloud/error-reporting] module which provides direct access to the Error Reporting API.
72+
6973
## Formatting Request Logs
7074

7175
To format your request logs you can provide a `httpRequest` property on the bunyan metadata you provide along with the log message. We will treat this as the [`HttpRequest`][http-request-message] message and Stackdriver logging will show this as a request log. Example:
@@ -92,3 +96,5 @@ The `httpRequest` proprety must be a properly formatted [`HttpRequest`][http-req
9296
[gce-how-to]: https://cloud.google.com/compute/docs/authentication#using
9397
[http-request-message]: https://cloud.google.com/logging/docs/reference/v2/rest/v2/LogEntry#HttpRequest
9498
[dev-console]: https://console.developers.google.com/project
99+
[error-reporting]: https://cloud.google.com/error-reporting/
100+
[@google-cloud/error-reporting]: https://www.npmjs.com/package/@google-cloud/error-reporting

packages/logging-winston/README.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,10 @@ winston.add(transport, {
7070
// ...you're good to go!
7171
```
7272

73+
## Error Reporting
74+
75+
Any `Error` objects you log at severity `error` at higher can automatically be picked up by [Stackdriver Error Reporting][error-reporting] if your application is running on Google Cloud Platform. You may also want to see [@google-cloud/error-reporting][@google-cloud/error-reporting] module which provides direct access to the Error Reporting API.
76+
7377
## Formatting Request Logs
7478

7579
To format your request logs you can provide a `httpRequest` property as part of the log metadata you provide to winston. We will treat this as the [`HttpRequest`][http-request-message] message and Stackdriver logging will show this as a request log. Example:
@@ -95,3 +99,5 @@ The `httpRequest` proprety must be a properly formatted [`HttpRequest`][http-req
9599
[gce-how-to]: https://cloud.google.com/compute/docs/authentication#using
96100
[dev-console]: https://console.developers.google.com/project
97101
[http-request-message]: https://cloud.google.com/logging/docs/reference/v2/rest/v2/LogEntry#HttpRequest
102+
[error-reporting]: https://cloud.google.com/error-reporting/
103+
[@google-cloud/error-reporting]: https://www.npmjs.com/package/@google-cloud/error-reporting

0 commit comments

Comments
 (0)