Bunyan in Production - Multiple Services

246 views
Skip to first unread message

Clay Himmelberger

unread,
May 12, 2015, 4:53:35 PM5/12/15
to bunyan-...@googlegroups.com
Reviewed the slides for Bunyan in Production and came across the final slides for multiple services. Could that be expanded a bit here?

Seems like some form of meta data would be passed with requests, and then included in the logging actions. Though it might be a little cumbersome to use
log.info( logMeta, "Here's a log message" )

all the time while that meta data is passed around, how else would it live across services? (or libraries for that matter...)

Any thoughts would be helpful : )

Trent Mick

unread,
May 13, 2015, 12:36:58 AM5/13/15
to Clay Himmelberger, bunyan-...@googlegroups.com
Hi Clay,

http://trentm.com/talk-bunyan-in-prod/#/20 shows Bunyan's `log.child` method for creating a Logger instance with associated metadata to include in all log records. Typically my usage with libraries is to pass a Logger instance (configured in the application code) to libraries. E.g.:

// app.js
var log = bunyan.createLogger({name: 'foo'});

var widgets = require('widgets');
var w = new widgets.Widget({
    log: log,
    ...
});


// widgets.js library
function Widget(opts) {
    this.log = opts.log.child({widget: true});
}
Widget.prototype.foo = function () {
    // ...
    this.log.trace('started Widget foo');   // this log record includes the `"widget": true` metadata
};


In the product I work on (SmartDataCenter) with many separate REST API services we pass around a request identifier as a "req_id" field on Logger instances. And the req_id gets between services (separate processes on separate VMs) via the request-id (or x-request-id) header.
The "RequestLogger" middleware with the restify REST API library (http://mcavage.me/node-restify/#requestlogger  https://github.com/mcavage/node-restify/blob/master/lib/plugins/bunyan.js#L31) adds a `log` Logger instance to each request object with the 'req_id' set as metadata. The default restify Request setup code will use the 'request-id' header for that req_id.  The last piece of the puzzle is to ensure that our client libraries pass along a request-id header in their request.

Hope that helps clarify.

Cheers,
Trent


--
Trent Mick

Clay Himmelberger

unread,
May 13, 2015, 8:26:34 AM5/13/15
to bunyan-...@googlegroups.com, clay.him...@gmail.com
Thanks Trent, that does help : ) Making a child logger for each http request does seem ideal, especially with multiple http services. 

Our setup is a few different libraries that might want to group logical flows by id or whatever, and it sounds like passing a logger or meta around to those is approach we'll take. The API side of things fares a little better as the request object gets passed around, but our other libs might need the logger or meta data passed in for their public interfaces. 

Thanks for replying, (and for your work on bunyan ; )

Clay
Reply all
Reply to author
Forward
0 new messages