Skip to content

Commit d8af691

Browse files
authoredFeb 9, 2017
Merge pull request #7 from Binarytales/master
Set record.message to ensure msg is shown in the Stackdriver UI
2 parents 388f4c5 + 37dae09 commit d8af691

File tree

3 files changed

+26
-2
lines changed

3 files changed

+26
-2
lines changed
 

‎README.md

+18
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,24 @@ limit is 20 RPS. The default setting for BunyanStackDriver is 500 ms.)
7474

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

77+
## Stackdriver Error Reporting
78+
79+
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)
80+
81+
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:
82+
83+
```
84+
const logger = bunyan.createLogger({
85+
name: 'Example',
86+
serializers: ...
87+
streams: ...,
88+
serviceContext: {
89+
service: 'example',
90+
version: 'x.x.x'
91+
}
92+
});
93+
```
94+
7795
## Links
7896

7997
[Stackdriver Logging - Method entries.write](https://cloud.google.com/logging/docs/api/ref_v2beta1/rest/v2beta1/entries/write)

‎lib/bunyan-stackdriver.js

+6
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,12 @@ BunyanStackDriver.prototype._write = function write(record, encoding, callback)
9393
record = destroyCircular(record);
9494
strictJSON(record);
9595

96+
if (record.err && record.err.stack) {
97+
record.message = record.err.stack;
98+
} else if (!record.message) {
99+
record.message = record.msg;
100+
}
101+
96102
var metadata = {
97103
resource: this.resource,
98104
timestamp: timestamp,

‎package.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "bunyan-stackdriver",
3-
"version": "1.2.2",
3+
"version": "1.3.0",
44
"description": "StackDriver stream for Bunyan",
55
"main": "./lib/bunyan-stackdriver",
66
"repository": {
@@ -21,7 +21,7 @@
2121
},
2222
"homepage": "https://github.com/mlazarov/bunyan-stackdriver",
2323
"dependencies": {
24-
"@google-cloud/logging": "^0.5.0",
24+
"@google-cloud/logging": "^0.7.0",
2525
"destroy-circular": "^1.1.0"
2626
},
2727
"devDependencies": {

0 commit comments

Comments
 (0)
Failed to load comments.