@@ -21,13 +21,17 @@ var aspect = require('./lib/aspect.js');
2121var request = require ( './lib/request.js' ) ;
2222var fs = require ( 'fs' ) ;
2323var agent = require ( "./appmetrics" )
24- // Set the plugin search path
24+
2525agent . spath ( path . join ( module_dir , "plugins" ) )
26- // pass in the main file name for use in identifying the app in mqtt connection
27- agent . start ( main_filename ) ;
26+
2827
2928var hcAPI = require ( "./appmetrics-api.js" ) ;
3029var jsonProfilingMode = false ;
30+ var propertyMappings = { 'mqttPort' :'com.ibm.diagnostics.healthcenter.mqtt.broker.port' ,
31+ 'mqttHost' :'com.ibm.diagnostics.healthcenter.mqtt.broker.host' ,
32+ 'applicationID' :'com.ibm.diagnostics.healthcenter.mqtt.application.id' ,
33+ 'mqtt' :'com.ibm.diagnostics.healthcenter.mqtt' ,
34+ 'profiling' :'com.ibm.diagnostics.healthcenter.data.profiling' } ;
3135
3236/*
3337 * Load module probes into probes array by searching the probes directory.
@@ -238,7 +242,9 @@ module.exports.emit = function (topic, data) {
238242
239243// Export monitor() API for consuming data in-process
240244module . exports . monitor = function ( ) {
245+
241246 if ( typeof ( this . api ) == 'undefined' ) {
247+ agent . start ( ) ;
242248 this . api = hcAPI . getAPI ( agent , module . exports ) ;
243249 }
244250 return this . api ;
@@ -250,6 +256,16 @@ module.exports.configure = function(options) {
250256 options = options || { } ;
251257 this . strongTracerInstrument =
252258 options . strongTracer ? options . strongTracer . tracer : null ;
259+ for ( var key in options ) {
260+ if ( propertyMappings [ key ] ) {
261+ agent . setOptions ( propertyMappings [ key ] , options [ key ] ) ;
262+ } else {
263+ agent . setOptions ( key , options [ key ] ) ;
264+ }
265+ }
266+
267+ // If user has not specified application ID, use main filename
268+ main_filename = options . applicationID ? options . applicationID : main_filename ;
253269} ;
254270
255271module . exports . transactionLink = function ( linkName , callback ) {
@@ -264,3 +280,10 @@ module.exports.setJSONProfilingMode = function(val) {
264280module . exports . getJSONProfilingMode = function ( ) {
265281 return jsonProfilingMode ;
266282}
283+
284+ module . exports . start = function ( ) {
285+ agent . setOptions ( propertyMappings [ 'applicationID' ] , main_filename ) ;
286+ agent . start ( ) ;
287+ }
288+
289+
0 commit comments