@@ -6,40 +6,36 @@ var format = require('util').format
66
77var shimmer = require ( '../utils/shimmer' )
88
9- // TODO[NODE-18]: unify INSTRUMENTED_LIBS and CORE_LIBS
10-
11- var INSTRUMENTED_LIBS = [
12- // from npm
13- 'mongoose' ,
14- 'mongodb' ,
15- 'bluebird' ,
16- 'redis' ,
17- 'ioredis' ,
18- 'mysql' ,
19- 'when' ,
20- 'q' ,
21- 'koa' ,
22- 'express' ,
23- 'pg' ,
24- 'amqplib'
25- ]
26-
27- var CORE_LIBS = [
28- 'http' ,
29- 'https'
30- ]
9+ var INSTRUMENTED_LIBS = {
10+ 'http' : './core/http' ,
11+ 'https' : './core/https' ,
12+ 'mongoose' : './mongoose' ,
13+ 'mongodb' : './mongodb' ,
14+ 'bluebird' : './bluebird' ,
15+ 'redis' : './redis' ,
16+ 'ioredis' : './ioredis' ,
17+ 'mysql' : './mysql' ,
18+ 'when' : './when' ,
19+ 'q' : './q' ,
20+ 'koa' : './koa' ,
21+ 'express' : './express' ,
22+ 'pg' : './pg' ,
23+ 'amqplib' : './amqplib'
24+ }
3125
32- function loadInstrumentationsForTarget ( name , prefix ) {
33- prefix = prefix || ''
34- var instrumentationsPath = path . resolve ( __dirname , prefix , name )
26+ function loadInstrumentationsForTarget ( name , path ) {
3527 var instrumentations
3628 try {
37- instrumentations = require ( instrumentationsPath )
29+ instrumentations = require ( path )
3830 } catch ( err ) {
3931 debug ( '#loadInstrumentationsForTarget' ,
40- format ( '[Warning] instrumentation group `%s` not found on path `%s`. Skipping ' ,
41- name , instrumentationsPath )
32+ format ( '[Warning] instrumentation failed for `%s`. Could not load `%s`. Reason: %s ' ,
33+ name , path , err )
4234 )
35+ debug ( err )
36+ }
37+ if ( ! instrumentations ) {
38+ return
4339 }
4440 if ( typeof instrumentations === 'function' ) {
4541 return {
@@ -139,27 +135,16 @@ module.exports.create = function (options) {
139135 var config = options . config || { }
140136 var disableInstrumentations = config . disableInstrumentations || [ ]
141137
142- // TODO[NODE-18]: unify INSTRUMENTED_LIBS and CORE_LIBS
143-
144- var coreTargets = CORE_LIBS
145- . filter ( function ( tgt ) {
146- return disableInstrumentations . indexOf ( tgt ) === - 1
147- } )
148- . map ( function ( tgt ) {
149- return loadInstrumentationsForTarget ( tgt , 'core' )
150- } )
151- . filter ( function ( tgt ) { return ! ! tgt } )
152-
153- var libraryTargets = INSTRUMENTED_LIBS
138+ var libraryTargets = Object . keys ( INSTRUMENTED_LIBS )
154139 . filter ( function ( tgt ) {
155140 return disableInstrumentations . indexOf ( tgt ) === - 1
156141 } )
157142 . map ( function ( tgt ) {
158- return loadInstrumentationsForTarget ( tgt )
143+ return loadInstrumentationsForTarget ( tgt , INSTRUMENTED_LIBS [ tgt ] )
159144 } )
160145 . filter ( function ( tgt ) { return ! ! tgt } )
161146
162- var instrumentationLookup = buildInstrumentationLookup ( coreTargets . concat ( libraryTargets ) )
147+ var instrumentationLookup = buildInstrumentationLookup ( libraryTargets )
163148
164149 shimmer . wrap ( Module , '_load' , function ( load ) {
165150 return function ( file , parent ) {
@@ -193,8 +178,9 @@ module.exports.create = function (options) {
193178 }
194179 } )
195180
196- loadTargetsEagerly ( coreTargets )
181+ loadTargetsEagerly ( libraryTargets . filter ( function ( lib ) {
182+ return lib . type === 'core'
183+ } ) )
197184}
198185
199186module . exports . INSTRUMENTED_LIBS = INSTRUMENTED_LIBS
200- module . exports . CORE_LIBS = CORE_LIBS
0 commit comments