chatra:montiapm-server-only

v2.45.1Published 2 years ago

Monti APM - Performance Monitoring for Meteor

GitHub Workflow Status

Monti APM - Performance Monitoring for Meteor

This package is based on meteorhacks/kadira.

Getting started

  1. Create an account at https://montiapm.com
  2. From the UI, create an app. You'll get an AppId and an AppSecret.
  3. Run meteor add montiapm:agent in your project
  4. Configure your Meteor app with the AppId and AppSecret by adding the following code snippet to a server/monti.js file:
1Meteor.startup(function() {
2  Monti.connect('<AppId>', '<AppSecret>');
3});

Now you can deploy your application and it will send information to Monti APM. Wait up to one minute and you'll see data appearing in the Monti APM Dashboard.

Compatibility

montiapm:agent is compatible with:

  • Meteor 1.4.3.2 and newer
  • Internet Explorer 9 and newer web browsers
  • Can be used with Monti APM or the open sourced version of Kadira, though many new features are not supported by Kadira

Features that require a newer version of Meteor are only enabled when using a supported version. For example, monitoring incoming HTTP requests is automatically enabled when the app uses Meteor 1.7 or newer.

Auto Connect

Your app can connect to Monti APM using environment variables or Meteor.settings.

Using Meteor.settings

Use the following settings.json file with your app:

1{
2  ...
3  "monti": {
4    "appId": "<appId>",
5    "appSecret": "<appSecret>"
6  }
7  ...
8}

The run your app with meteor --settings=settings.json.

Using Environment Variables

Export the following environment variables before running or deploying your app:

export MONTI_APP_ID=<appId>
export MONTI_APP_SECRET=<appSecret>

Error Tracking

Monti APM comes with built in error tracking solution for Meteor apps. It has been enabled by default. Uncaught errors, unhandled promise rejections and errors logged by Meteor are automatically tracked.

To manually track an error, you can use Monti.trackError:

1try {
2  functionThatCouldFail();
3} catch (err) {
4  Monti.trackError(err);
5}

Monti APM can use source maps to show where in the original code the error occurred. Learn more in our docs.

Options

The Monti APM agent can be configured by

  • environment variables, prefixed with either MONTI_ or KADIRA_
  • settings.json in the monti or kadira object. Options other than appId and appSecret should be in monti.options or kadira.options.
  • code with Monti.connect('app id', 'app secret', options)

You should use the same method that you used to give the agent the app id and secret.

List of Options

nameenv variabledefaultdescription
appIdAPP_IDnone
appSecretAPP_SECRETnone
enableErrorTrackingOPTIONS_ENABLE_ERROR_TRACKINGtrueenable sending errors to Monti APM
endpointOPTIONS_ENDPOINThttps://engine.montiapm.comMonti / Kadira engine url
hostnameOPTIONS_HOSTNAMEServer's hostnameWhat the instance is named in Monti APM
uploadSourceMapsUPLOAD_SOURCE_MAPStrueEnables sending source maps to Monti APM to improve error stack traces
recordIPAddressRECORD_IP_ADDRESS'full'Set to 'full' to record IP Address, 'anonymized' to anonymize last octet of address, or 'none' to not record an IP Address for client errors
eventStackTraceEVENT_STACK_TRACEfalseIf true, records a stack trace when an event starts. Slightly decreases server performance.

Traces

The agent collects traces of methods and publish functions. Every minute, it sends the outlier traces to Monti APM for you to view.

By default, it tracks events for:

  • method/pubsub start
  • wait time
  • uncaught errors
  • db
  • http
  • email
  • async (time between the fiber yielding and running again)
  • method/pubsub complete

Time between an event ending and the next event starting becomes a compute event.

The agent records up to one level of nested events.

You can add custom events to the traces to time specific code or events, or to provide more details to the trace.

1const event = Monti.startEvent('event name', {
2  details: true
3});
4
5// After code runs or event happens
6Monti.endEvent(event, {
7  additionalDetails: true
8});

You can use any name you want. The second parameter is an object with data that is shown to you in the Monti APM UI. The data objects from starting and ending the event are merged together.

Please note that the total size of all traces uploaded per server every 20 seconds is limited (usually around 5mb), and if it is too large the traces and metrics are not stored. Avoid having 1,000's of custom events per trace or adding very large data objects.

Filtering Trace Data

The agent stores user ids, queries, arguments, and other data with each trace to help you fix performance issues and errors. If your app deals with sensitive information, you can use filters to limit what is sent.

Add a filter with:

1Monti.tracer.addFilter((eventType, data, { type: traceType, name: traceName }) => {
2  if (
3    // traceType can be 'method', 'sub', or 'http'
4    traceType === 'method' &&
5    // traceName has the method or publication name. For http traces
6    // it is '<http method>-<route name>', for example 'POST-/user/:id'.
7    traceName === 'account.setPassword' &&
8    // The eventType can be start, db, http, email, wait, async,
9    // custom, fs, error, or complete.
10    eventType === 'start'
11  ) {
12    // data is the object shown in Monti APM when clicking "Show More" in a trace.
13    // What is in data depends on the event type.
14    delete data.params;
15  }
16
17  return data;
18});
19
20Monti.tracer.addFilter((eventType, data) => {
21  if (eventType === 'db') {
22    delete data.selector;
23  }
24
25  return data;
26});

Development

Tests:

npm run test

# Run tests for specific Meteor version
npm run test -- --release 1.8.1

Lint

Make sure you install the dev dependencies first with npm install.

npm run lint