Node-bunyan: improve control and UX with dtrace-provider usage

Created on 22 Mar 2017  路  5Comments  路  Source: trentm/node-bunyan

Some common pains with using Bunyan related to its usage of dtrace-provider. Dtrace-provider includes binary bits (DTraceProviderBindings.node) on platforms on which it there is expected to be dtrace support (sunos, darwin, freebsd). However there are reasons the build can fail:

  • It is installed with a new major version of node that breaks NAN compat (the binary API module used by dtrace-provider for cross-node-version compat).
  • The user doesn't have a compiler, or doesn't have it activated (e.g. XCode requires a one-time interactive UX to enable the compiler as mentioned in this comment: https://github.com/trentm/node-bunyan/issues/216#issuecomment-71074784 "Agreeing to the Xcode/iOS license requires admin privileges, please re-run as root via sudo.")

Proposal:

  • Update dtrace-provider to not write to stderr for import errors of its binding. Instead it provides a way to say explicitly on mod_dtrace_provider.createDTraceProvider(...) that it should error out (throw) if the dtrace provider binding isn't there and we are on a platform where it should be.
  • Change bunyan to support requiring dtrace-provider to be functional. The default will stay silent (i.e. not strict). Something like this:
var bunyan = require('./')
var log = bunyan.createLogger({
    name: 'bar',
    requireDtrace: true
});
log.info('hi');

That requireDtrace option will need to wait for https://github.com/trentm/node-bunyan/issues/460 in bunyan 2.x.

Most helpful comment

Hi @trentm, thanks for the work you do on Bunyan. Is there any reason dtrace-provider couldn't be removed and then users would have to install it + enable it explicitly, possibly with some graceful fallback on systems that wouldn't support it?

Our use case is we have a proxy CompanyLogger that we use as an npm module, which has Bunyan as a dependency. We don't intend to use the dtrace functionality but there's no way for us to prevent it from being installed since we npm install company-logger which installs bunyan, which will then trigger an install of optionalDependencies.

Asking end users of the library to install with --no-optionals kind of stinks and installing dtrace takes time.

What I propose would work similar to Knex, which doesn't require any of the database libraries to be installed until you try to configure that type (e.g. Postgres) of connection http://knexjs.org/#Installation-node

All 5 comments

Example of a prototype of bunyan and dtrace-provider changes for this. In this setup I've intentionally broken the DTraceProviderBinding.node file.

$ cat bar.js
var bunyan = require('./')
var log = bunyan.createLogger({
   name: 'bar',
   requireDtrace: true
});
log.info('hi');

$ node bar.js
/Users/trentm/tm/node-bunyan/lib/bunyan.js:452
           throw new Error('Bunyan dtrace support is failing. See '
           ^

Error: Bunyan dtrace support is failing. See <https://github.com/trentm/node-bunyan/#troubleshooting>. dtrace-provider error: Error: dtrace-provider could not import its bindings from /Users/trentm/src/node-dtrace-provider/{Release,default,Debug}/DTraceProviderBindings.node: dlopen(/Users/trentm/src/node-dtrace-provider/build/Release/DTraceProviderBindings.node, 1): no suitable image found.  Did find:
   /Users/trentm/src/node-dtrace-provider/build/Release/DTraceProviderBindings.node: file too short
   at new Logger (/Users/trentm/tm/node-bunyan/lib/bunyan.js:452:19)
   at Function.createLogger (/Users/trentm/tm/node-bunyan/lib/bunyan.js:1630:12)
   at Object.<anonymous> (/Users/trentm/tm/node-bunyan/bar.js:2:18)
   at Module._compile (module.js:409:26)
   at Object.Module._extensions..js (module.js:416:10)
   at Module.load (module.js:343:32)
   at Function.Module._load (module.js:300:12)
   at Function.Module.runMain (module.js:441:10)
   at startup (node.js:140:18)
   at node.js:1043:3

Bunyan 2.x should probably use VError to get the cause chaining.

As a library provider using this module, one barrier for my costumers to use my library was that DTrace needed a special install, otherwise bunyan would fail. (We're behind a corporate proxy, and unless proxy settings are exported then the install.js will fail. Getting my devs to do this was too much of an issue, which is /almost/ understandable since it should be a simple npm install). Is it not possible to go the other way, and make DTrace an optional dependency?

@danielkwinsor dtrace-provider is an optionalDependency: https://github.com/trentm/node-bunyan/blob/master/package.json#L22-L23

If you are able, I would love to see (a) confirmation of that whole "npm install ..." failing if that optional dep fails to install and (b) example output from both npm install your-module (so I can see what it looks like) and V=1 npm install your-module (the "V=1" environment variable will tell the dtrace-provider install to emit more output).

I couldn't reproduce today, I must have something cached. Here's the JIRA issue I filed a while ago.

DTraceJIRA.txt

Hi @trentm, thanks for the work you do on Bunyan. Is there any reason dtrace-provider couldn't be removed and then users would have to install it + enable it explicitly, possibly with some graceful fallback on systems that wouldn't support it?

Our use case is we have a proxy CompanyLogger that we use as an npm module, which has Bunyan as a dependency. We don't intend to use the dtrace functionality but there's no way for us to prevent it from being installed since we npm install company-logger which installs bunyan, which will then trigger an install of optionalDependencies.

Asking end users of the library to install with --no-optionals kind of stinks and installing dtrace takes time.

What I propose would work similar to Knex, which doesn't require any of the database libraries to be installed until you try to configure that type (e.g. Postgres) of connection http://knexjs.org/#Installation-node

Was this page helpful?
0 / 5 - 0 ratings

Related issues

kbirger picture kbirger  路  4Comments

mouhong picture mouhong  路  6Comments

mickaeltr picture mickaeltr  路  7Comments

LeonFedotov picture LeonFedotov  路  7Comments

shaucorp picture shaucorp  路  5Comments