Skip to content

Commit

Permalink
Merge pull request #7 from Binarytales/master
Browse files Browse the repository at this point in the history
Set record.message to ensure msg is shown in the Stackdriver UI
  • Loading branch information
mlazarov authored Feb 9, 2017
2 parents 388f4c5 + 37dae09 commit d8af691
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 2 deletions.
18 changes: 18 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,24 @@ limit is 20 RPS. The default setting for BunyanStackDriver is 500 ms.)

* errorCallback. Will report errors during the logging process itself.

## Stackdriver Error Reporting

When errors with stack traces are logged - `bunyan.error(new Error('message'))` - these can automatically be captured by the [Error Reporting](https://cloud.google.com/error-reporting/) interface in Google Cloud Platform. To do so some additional configuration is required as per [Stackdriver Formatting Error Messages](https://cloud.google.com/error-reporting/docs/formatting-error-messages)

When logging, a _service context_ is required. This can be added on a per log basis or configured for all logs during logger creation like so:

```
const logger = bunyan.createLogger({
name: 'Example',
serializers: ...
streams: ...,
serviceContext: {
service: 'example',
version: 'x.x.x'
}
});
```

## Links

[Stackdriver Logging - Method entries.write](https://cloud.google.com/logging/docs/api/ref_v2beta1/rest/v2beta1/entries/write)
Expand Down
6 changes: 6 additions & 0 deletions lib/bunyan-stackdriver.js
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,12 @@ BunyanStackDriver.prototype._write = function write(record, encoding, callback)
record = destroyCircular(record);
strictJSON(record);

if (record.err && record.err.stack) {
record.message = record.err.stack;
} else if (!record.message) {
record.message = record.msg;
}

var metadata = {
resource: this.resource,
timestamp: timestamp,
Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "bunyan-stackdriver",
"version": "1.2.2",
"version": "1.3.0",
"description": "StackDriver stream for Bunyan",
"main": "./lib/bunyan-stackdriver",
"repository": {
Expand All @@ -21,7 +21,7 @@
},
"homepage": "https://github.com/mlazarov/bunyan-stackdriver",
"dependencies": {
"@google-cloud/logging": "^0.5.0",
"@google-cloud/logging": "^0.7.0",
"destroy-circular": "^1.1.0"
},
"devDependencies": {
Expand Down

0 comments on commit d8af691

Please sign in to comment.