Code Monkey home page Code Monkey logo

trace-nodejs's Introduction

Trace logo

Build status npm version Website Slack Status JavaScript Style Guide Twitter URL


App | Documentation | Status page | Case study


⚠️ Breaking change

With version 3.x.x we have dropped support for Node v0.10. This means that future releases under this major version might contain code changes that are incompatible with Node.js v0.10 to an extent of crashing your application. Please consider updating to a newer runtime, especially that the maintenance of v0.10 has already ended. See our compatibility table below.

Installation and usage

As Trace uses scoped packages, be sure to use npm version greater than 2.7.0.

npm install --save @risingstack/trace

If you can't update to [email protected] for whatever reason, you can still install Trace using npm i risingstack/trace-nodejs.

After you installed Trace as a dependency, you just require it at the beginning of your main file.

var trace = require('@risingstack/trace');

Configuration

You can specify the configuration two ways. Configuration options can be set via environment variables or using a config module. We look for a config module named trace.config.js at your current working directory by default, which can be overridden with the TRACE_CONFIG_PATH environment variable. Having a config module is optional, but some options may be set only with it. In order to use our service, you need to specify an api key and and a service name at minimum. The corresponding environment variables are: TRACE_API_KEY and TRACE_SERVICE_NAME.

An example for how to start your app with environment variables:

node TRACE_SERVICE_NAME=MyApp TRACE_API_KEY=1 index.js

An example with a custom config file using the Trace servers:

node TRACE_CONFIG_PATH=/path/to/my/config.js index.js

or simply

node index.js

if it's in the current working directory.

/**
* Your Trace configuration file at /path/to/my/config.js
*/

module.exports = {
  serviceName: 'your-awesome-app',
  apiKey: 'KEEP_ME_SECRET',
  ignoreHeaders: {
    'user-agent': ['007']
  },
  ignorePaths: [
    '/healthcheck'
  ],
  ignoreStatusCodes: [
    401,
    404
  ],
  ignoreOutgoingHosts: [
    'google.com'
  ],
  disableInstrumentations: [
    'mongodb'
  ],
  proxy: 'http://168.63.76.32:3128'
}

Note: Custom reporters are no longer supported in trace 2.x

Note: If you are running your app with NODE_ENV=test, Trace won't start

API

trace.report(String, [Object])

This method can be use to report additional data to the Trace servers which later on helps with debugging.

trace.report('name', {
  userId: 10
});

Throws an error if first parameter is not a String. Throws an error if second parameter is not an Object.

trace.reportError(String, Error)

This method can be used to send errors to the Trace servers - note that transactions that use this method are not subject to sampling, so it will be collected all the time.

trace.reportError('mysql_error', new Error('connection refused'));

Throws an error if first parameter is not a String.

trace.getTransactionId()

This method can be use to get the current transactionId. It can be useful if you want to integrate trace with your current logging systems.

var transactionId = trace.getTransactionId();

trace.recordMetric(name, value)

This method can be used to record custom metrics values.

trace.recordMetric('user/imageUpload', 6)

The name must have the following format: <Category>/<Name> The value must be a number.

trace.incrementMetric(name, [amount])

This method can be used to record increment-only type of metrics.

trace.incrementMetric('user/signup')

The name must have the following format: <Category>/<Name>

trace.stop()

This method gracefully stops trace.

trace.stop(cb)

Accepts a node-style callback to be called when trace stopped.

Note: There is no way to restart trace after calling this method. You should end your process after calling this method.

Compatibility with Node versions

  • node v0.12@latest
  • node v4@latest
  • node v5@latest
  • node v6@latest
  • node v7@latest

Migrating from previous versions

Versions below 2.x

The trace.config.js file changed, and has the following format:

module.exports = {
  serviceName: 'your-awesome-app',
  apiKey: 'KEEP_ME_SECRET'
}

Also, from 2.x you can specify these values using only environment variables: TRACE_SERVICE_NAME and TRACE_API_KEY.

Versions below 3.x

We dropped support for Node v0.10. Update your runtime to a more recent version to continue using Trace.

trace-nodejs's People

Contributors

gergelyke avatar peteyycz avatar dszakallas avatar shadowbeetle avatar szkrd avatar hekike avatar gabordobrei avatar jbpionnier avatar leon-good-life avatar ryan-sandy avatar

Watchers

NoScripter avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.