index.js
function start(projectConfig) {
  var config = initConfig(projectConfig);

  if (traceApi.isActive() && !config.forceNewAgent_) { // already started.
    throw new Error('Cannot call start on an already started agent.');
  }

  if (!config.enabled) {
    return traceApi;
  }

  if (config.logLevel < 0) {
    config.logLevel = 0;
  } else if (config.logLevel >= Logger.LEVELS.length) {
    config.logLevel = Logger.LEVELS.length - 1;
  }
  var logger = new Logger(config.logLevel, config.logger === 'debug' ? 'vxx' : undefined);

  if (onUncaughtExceptionValues.indexOf(config.onUncaughtException) === -1) {
    logger.error('The value of onUncaughtException should be one of ',
      onUncaughtExceptionValues);
    throw new Error('Invalid value for onUncaughtException configuration.');
  }

  var headers = {};
  headers[constants.TRACE_AGENT_REQUEST_HEADER] = 1;

  if (modulesLoadedBeforeTrace.length > 0) {
    logger.error('Tracing might not work as the following modules ' +
      'were loaded before the trace agent was initialized: ' +
      JSON.stringify(modulesLoadedBeforeTrace));
  }

  agent = require('./src/trace-agent.js').get(config, logger);
  traceApi.enable_(agent);
  pluginLoader.activate(agent);

  traceApi.getCls = function() {
    return agent.getCls();
  };

  traceApi.getBus = function() {
    return agent.traceWriter;
  };

  return traceApi;
}
function start(projectConfig) {
  var config = initConfig(projectConfig);

  if (traceApi.isActive() && !config.forceNewAgent_) { // already started.
    throw new Error('Cannot call start on an already started agent.');
  }

  if (!config.enabled) {
    return traceApi;
  }

  if (config.logLevel < 0) {
    config.logLevel = 0;
  } else if (config.logLevel >= Logger.LEVELS.length) {
    config.logLevel = Logger.LEVELS.length - 1;
  }
  var logger = new Logger(config.logLevel, config.logger === 'debug' ? 'vxx' : undefined);

  if (onUncaughtExceptionValues.indexOf(config.onUncaughtException) === -1) {
    logger.error('The value of onUncaughtException should be one of ',
      onUncaughtExceptionValues);
    throw new Error('Invalid value for onUncaughtException configuration.');
  }

  var headers = {};
  headers[constants.TRACE_AGENT_REQUEST_HEADER] = 1;

  if (modulesLoadedBeforeTrace.length > 0) {
    logger.error('Tracing might not work as the following modules ' +
      'were loaded before the trace agent was initialized: ' +
      JSON.stringify(modulesLoadedBeforeTrace));
  }

  agent = require('./src/trace-agent.js').get(config, logger);
  traceApi.enable_(agent);
  pluginLoader.activate(agent);

  traceApi.getCls = function() {
    return agent.getCls();
  };

  traceApi.getBus = function() {
    return agent.traceWriter;
  };

  return traceApi;
}
function start ( projectConfig ) { var config = initConfig ( projectConfig ) ; if ( traceApi . isActive ( ) && ! config . forceNewAgent_ ) { // already started. throw new Error ( 'Cannot call start on an already started agent.' ) ; } if ( ! config . enabled ) { return traceApi ; } if ( config . logLevel < 0 ) { config . logLevel = 0 ; } else if ( config . logLevel >= Logger . LEVELS . length ) { config . logLevel = Logger . LEVELS . length - 1 ; } var logger = new Logger ( config . logLevel , config . logger === 'debug' ? 'vxx' : undefined ) ; if ( onUncaughtExceptionValues . indexOf ( config . onUncaughtException ) === - 1 ) { logger . error ( 'The value of onUncaughtException should be one of ' , onUncaughtExceptionValues ) ; throw new Error ( 'Invalid value for onUncaughtException configuration.' ) ; } var headers = { } ; headers [ constants . TRACE_AGENT_REQUEST_HEADER ] = 1 ; if ( modulesLoadedBeforeTrace . length > 0 ) { logger . error ( 'Tracing might not work as the following modules ' + 'were loaded before the trace agent was initialized: ' + JSON . stringify ( modulesLoadedBeforeTrace ) ) ; } agent = require ( './src/trace-agent.js' ) . get ( config , logger ) ; traceApi . enable_ ( agent ) ; pluginLoader . activate ( agent ) ; traceApi . getCls = function ( ) { return agent . getCls ( ) ; } ; traceApi . getBus = function ( ) { return agent . traceWriter ; } ; return traceApi ; }
Start the Trace agent that will make your application available for
tracing with Stackdriver Trace.

@param {object=} config - Trace configuration

@resource [Introductory video]{@link
https://www.youtube.com/watch?v=NCFDqeo7AeY}

@example
trace.start();
Start the Trace agent that will make your application available for tracing with Stackdriver Trace .