Skip to content

Commit 987c190

Browse files
Add examples of how to set custom trace value.
1 parent 8d49298 commit 987c190

2 files changed

Lines changed: 26 additions & 2 deletions

File tree

packages/logging-bunyan/README.md

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,20 @@ If you use [@google-cloud/trace-agent][trace-agent] module, then this module wil
9898

9999
![Logs in Trace Example](/packages/logging-bunyan/doc/images/bunyan-logs-in-trace.png)
100100

101-
If you wish to set the Stackdriver LogEntry `trace` property with a custom value, then write a Bunyan log entry property for `'logging.googleapis.com/trace'`, which is exported by this module as `LOGGING_TRACE_KEY`.
101+
If you wish to set the Stackdriver LogEntry `trace` property with a custom value, then write a Bunyan log entry property for `'logging.googleapis.com/trace'`, which is exported by this module as `LOGGING_TRACE_KEY`. For example:
102+
103+
```js
104+
const bunyan = require('bunyan');
105+
const LoggingBunyan = require('@google-cloud/logging-bunyan');
106+
const loggingBunyan = LoggingBunyan();
107+
108+
...
109+
110+
logger.info({
111+
msg: 'Bunyan log entry with custom trace field',
112+
[LoggingBunyan.LOGGING_TRACE_KEY]: 'custom-trace-value'
113+
});
114+
```
102115

103116
[bunyan]: https://github.com/trentm/node-bunyan
104117
[@google-cloud/logging]: https://www.npmjs.com/package/@google-cloud/logging

packages/logging-winston/README.md

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,18 @@ If you use [@google-cloud/trace-agent][trace-agent] module, then this module wil
102102

103103
![Logs in Trace Example](/packages/logging-winston/doc/images/winston-logs-in-trace.png)
104104

105-
If you wish to set the LogEntry `trace` property with a custom value, then set a winston metadata property for `'logging.googleapis.com/trace'`, which is exported by this module as `LOGGING_TRACE_KEY`.
105+
If you wish to set the LogEntry `trace` property with a custom value, then set a winston metadata property for `'logging.googleapis.com/trace'`, which is exported by this module as `LOGGING_TRACE_KEY`. For example:
106+
107+
```js
108+
const winston = require('winston');
109+
const transport = require('@google-cloud/logging-winston');
110+
111+
...
112+
113+
winston.info('Log entry with custom trace value', {
114+
[transport.LOGGING_TRACE_KEY]: 'custom-trace-value'
115+
});
116+
```
106117

107118
[winston]: https://github.com/winstonjs/winston
108119
[@google-cloud/logging]: https://www.npmjs.com/package/@google-cloud/logging

0 commit comments

Comments
 (0)