Skip to content

Commit

Permalink
Doc error-reporting integration with logs (#2333)
Browse files Browse the repository at this point in the history
Document loggin-{winston,bunyan} and error-reporting from each other's
README files.
  • Loading branch information
ofrobots authored and stephenplusplus committed May 31, 2017
1 parent 0421ba8 commit 32e341a
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 3 deletions.
21 changes: 18 additions & 3 deletions packages/error-reporting/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,21 @@
This module provides Stackdriver Error Reporting support for Node.js applications.
[Stackdriver Error Reporting](https://cloud.google.com/error-reporting/) is a feature of
Google Cloud Platform that allows in-depth monitoring and viewing of errors reported by
applications running in almost any environment.
applications running in almost any environment.

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

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

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

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

## Prerequisites

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

// Report an error to the Stackdriver Error Reporting API
errors.report(new Error('Something broke!'));

// We also provide error handling middleware for express, hapi, restify & koa.
// See sections below.
```

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

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

app.listen(3000);
Expand Down Expand Up @@ -253,10 +265,13 @@ server.head('/hello/:name', respond);
server.listen(3000);
```

[gcloud-sdk]: https://cloud.google.com/sdk/gcloud/
[app-default-credentials]: https://developers.google.com/identity/protocols/application-default-credentials
[service-account]: https://console.developers.google.com/apis/credentials/serviceaccountkey
[express-error-docs]: https://expressjs.com/en/guide/error-handling.html
[gcloud-sdk]: https://cloud.google.com/sdk/gcloud/
[logging-bunyan]: https://www.npmjs.com/package/@google-cloud/logging-bunyan
[logging-winston]: https://www.npmjs.com/package/@google-cloud/logging-winston
[npm-image]: https://badge.fury.io/js/%40google-cloud%2Ferror-reporting.svg
[npm-url]: https://npmjs.org/package/@google-cloud/error-reporting
[service-account]: https://console.developers.google.com/apis/credentials/serviceaccountkey
[snyk-image]: https://snyk.io/test/npm/@google-cloud/error-reporting/badge.svg
[snyk-url]: https://snyk.io/test/npm/@google-cloud/error-reporting
6 changes: 6 additions & 0 deletions packages/logging-bunyan/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,10 @@ var loggingBunyan = require('@google-cloud/logging-bunyan')({
// ...you're good to go!
```

## Error Reporting

Any `Error` objects you log at severity `error` or 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 the [@google-cloud/error-reporting][@google-cloud/error-reporting] module which provides direct access to the Error Reporting API.

## Formatting Request Logs

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:
Expand All @@ -92,3 +96,5 @@ The `httpRequest` proprety must be a properly formatted [`HttpRequest`][http-req
[gce-how-to]: https://cloud.google.com/compute/docs/authentication#using
[http-request-message]: https://cloud.google.com/logging/docs/reference/v2/rest/v2/LogEntry#HttpRequest
[dev-console]: https://console.developers.google.com/project
[error-reporting]: https://cloud.google.com/error-reporting/
[@google-cloud/error-reporting]: https://www.npmjs.com/package/@google-cloud/error-reporting
6 changes: 6 additions & 0 deletions packages/logging-winston/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,10 @@ winston.add(transport, {
// ...you're good to go!
```

## Error Reporting

Any `Error` objects you log at severity `error` or 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 the [@google-cloud/error-reporting][@google-cloud/error-reporting] module which provides direct access to the Error Reporting API.

## Formatting Request Logs

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:
Expand All @@ -95,3 +99,5 @@ The `httpRequest` proprety must be a properly formatted [`HttpRequest`][http-req
[gce-how-to]: https://cloud.google.com/compute/docs/authentication#using
[dev-console]: https://console.developers.google.com/project
[http-request-message]: https://cloud.google.com/logging/docs/reference/v2/rest/v2/LogEntry#HttpRequest
[error-reporting]: https://cloud.google.com/error-reporting/
[@google-cloud/error-reporting]: https://www.npmjs.com/package/@google-cloud/error-reporting

0 comments on commit 32e341a

Please sign in to comment.