Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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