Performance Monitoring

Introduction

Application Performance Monitoring with Airbrake makes it easy to:

  • Understand high-level performance: Quickly see a broad performance overview for your whole application.
  • Monitor user satisfaction: Measure user satisfaction with your app performance using Apdex.
  • Catch problem routes: Identify routes with slow or error-prone performance.
  • Analyze granular performance metrics: Zoom into specific endpoints to see time spent in the DB, view, cache, external requests, and more.
  • Dive into database performance: Analyze SQL database queries being called and how long they take.
  • Track your background jobs: Monitor background job performance, track job failures and durations.

Select your language

To start monitoring performance for your app, select a guide:

Key features

View all of your app’s performance stats at a glance. Trend cards highlight key performance metrics across your whole app. The charts show requests, response times, errors, and user satisfaction (Apdex) over time. The routes list exposes performance stats per route, making it easy to pinpoint and resolve issues.

Detailed route performance

Diving deeper into an individual route, you can see the proportion of time spent in the database, cache, views, or making external requests. There are similar trend cards and performance charts to quickly understand the route performance. You can also click through from a route to its linked Airbrake errors.

Background job monitoring

Automatically track background job performance for all your apps. Measure and improve the quality of your background jobs and easily gain insight into job failure rates and duration issues. You can find your app’s job performance from the jobs tab of the performance dashboard.

Supported Background Job libraries

Install, config, upgrade

Monitoring Rails apps

Performance Monitoring is built into the same notifier you use to report errors from your application. To start sending performance data for your app to Airbrake just install or upgrade the Airbrake gem to the latest version.

Step 1: Install the latest version of the Airbrake gem

Add the Airbrake gem to your Gemfile:

gem 'airbrake'

To integrate Airbrake with your Rails application, you need to know your project id and project key. Set AIRBRAKE_PROJECT_ID & AIRBRAKE_PROJECT_KEY environment variables with your project’s values and generate the Airbrake config:

export AIRBRAKE_PROJECT_ID=<PROJECT ID>
export AIRBRAKE_PROJECT_KEY=<PROJECT KEY>

rails g airbrake
Step 2: Update your config file

Check your config/initializers/airbrake.rb file to make sure the performance_stats options is set to true.

Airbrake.configure do |c|
  c.performance_stats = true
end
Congratulations!
Great job! If you’ve used this example in your app, you can visit your Airbrake project’s Performance Dashboard to see your performance data! Soon enough you’ll have more insights into your application’s performance. In the meantime why not check out the Performance Dashboard features. Have questions about Performance Monitoring? Check out our Performance Monitoring FAQ for more information.
Upgrading from a previous gem version?

If you are upgrading from a previous version of our gem, please follow our upgrade guide to get started with Performance Monitoring.

Monitoring Node.js apps

Get the most out of Airbrake’s features and stay up to date with the latest improvements by updating your project to the latest version of our Node.js error reporting library.

Name change note

Our JavaScript library’s name has recently changed from airbrake-js to @airbrake/node (for Node.js apps). If you are using airbrake-js check out our upgrade doc. If you are on the deprecated node-airbrake notifier, please visit our other upgrade guide.

Update your notifier

If you’re using our official notifier, all you need to do is update the version you’re using:

npm update @airbrake/node

Or, if you’re using yarn:

yarn upgrade @airbrake/node
Performance Monitoring for Express.js apps

To get started, install our Express.js middleware as shown in the install guide. Performance Monitoring is completely automatic after installation - no extra setup required.

Congratulations!
Great job! If you’ve used this example in your app, you can visit your Airbrake project’s Performance Dashboard to see your performance data! Soon enough you’ll have more insights into your application’s performance. In the meantime why not check out the Performance Dashboard features. Have questions about Performance Monitoring? Check out our Performance Monitoring FAQ for more information.

Monitoring Go apps

Go Support

Airbrake Performance Monitoring for Go supports:

  • Sending route stats
  • HTTP middlewares for Gin and Beego users
  • Wrapping important code blocks for detailed timing
  • Collecting stats about individual SQL queries
Step 1: Install the latest version of gobrake
go get github.com/airbrake/gobrake
Step 2: Configure gobrake and start sending route stats

Before you can send performance stats replace the placeholder ProjectId and ProjectKey values from the example below with the real values from your project’s setting page.

Now that your gobrake notifier is configured let’s collect some routes stats, we will use a simple net/http middleware in this example.

Note: If you use Gin or Beego, gobrake provides middleware out of the box and you may find our example apps more helpful: Gin example, BeeGo example.

package main

import (
  "fmt"
  "net/http"

  "github.com/airbrake/gobrake"
)

// Airbrake is used to report errors and track performance
var Airbrake = gobrake.NewNotifierWithOptions(&gobrake.NotifierOptions{
  ProjectId: 123123,               // <-- Fill in this value
  ProjectKey: "YourProjectAPIKey", // <-- Fill in this value
  Environment: "Production",
})

func indexHandler(w http.ResponseWriter, req *http.Request) {
  fmt.Fprintf(w, "Hello, There!")
}

func main() {
  fmt.Println("Server listening at http://localhost:5555/")
  // Wrap the indexHandler with Airbrake Performance Monitoring middleware:
  http.HandleFunc(airbrakePerformance("/", indexHandler))
  http.ListenAndServe(":5555", nil)
}

func airbrakePerformance(route string, h http.HandlerFunc) (string, http.HandlerFunc) {
  handler := http.HandlerFunc(func(w http.ResponseWriter, req *http.Request) {
    ctx := req.Context()
    ctx, routeMetric := gobrake.NewRouteMetric(ctx, req.Method, route) // Starts the timing
    arw := newAirbrakeResponseWriter(w)

    h.ServeHTTP(arw, req)

    routeMetric.StatusCode = arw.statusCode
    Airbrake.Routes.Notify(ctx, routeMetric) // Stops the timing and reports
    fmt.Printf("code: %v, method: %v, route: %v\n", arw.statusCode, req.Method, route)
  })

  return route, handler
}

type airbrakeResponseWriter struct {
  http.ResponseWriter
  statusCode int
}

func newAirbrakeResponseWriter(w http.ResponseWriter) *airbrakeResponseWriter {
  // Returns 200 OK if WriteHeader isn't called
  return &airbrakeResponseWriter{w, http.StatusOK}
}

func (arw *airbrakeResponseWriter) WriteHeader(code int) {
  arw.statusCode = code
  arw.ResponseWriter.WriteHeader(code)
}

Once you run this example and perform some curls or visit localhost:5555/ in your browser, you will see performance requests in your project’s performance dashboard.

Congratulations!
Great job! If you’ve used this example in your app, you can visit your Airbrake project’s Performance Dashboard to see your performance data! Soon enough you’ll have more insights into your application’s performance. In the meantime why not check out the Performance Dashboard features. Have questions about Performance Monitoring? Check out our Performance Monitoring FAQ for more information.
Measuring timing of specific operations

Need more visibility into a slow route? To get more detailed timing, you can wrap important blocks of code into spans. For example, you can create 2 spans sql and http to measure timing of specific operations:

metric := &gobrake.RouteMetric{
    Method: c.Request.Method,
    Route: routeName,
    StartTime: time.Now(),
}

metric.StartSpan("sql")
users, err := fetchUser(ctx, userID)
metric.EndSpan("sql")

metric.StartSpan("http")
resp, err := http.Get("http://example.com/")
metric.EndSpan("http")

metric.StatusCode = http.StatusOK
notifier.Routes.Notify(ctx, metric)
Want to learn more?

Want to learn more about gobrake? Check out our official GitHub repo.

Monitoring Python apps

Python Support

Airbrake Performance Monitoring for Python supports:

Tracking Performance manually

Not using the Django or Flask frameworks? Track performance manually by using the following API:

Sending route stats

notifier.routes.notify allows sending route stats to Airbrake. The library provides integrations with Django and Flask. (your routes are tracked automatically). You can also use this API manually:

import pybrake.RouteMetric as RouteMetric

metric = RouteMetric(method=request.method, route=route)
metric.status_code = response.status_code
metric.content_type = response.headers.get("Content-Type")
metric.end_time = time.time()

notifier.routes.notify(metric)
Sending route breakdowns

notifier.routes.breakdowns.notify allows sending performance breakdown stats to Airbrake. You can use this API manually:

import pybrake.RouteBreakdowns as RouteBreakdowns

metric = RouteBreakdowns(method=request.method, route=route)
metric.response_type = response.headers.get("Content-Type")
metric.end_time = time.time()

notifier.routes.notify(metric)
Sending query stats

notifier.queries.notify allows sending SQL query stats to Airbrake. The library provides integration with Django (your queries are tracked automatically). You can also use this API manually:

import pybrake.QueryStat as QueryStat

metric = QueryStat(
  method=request.method,
  route=route,
  query="SELECT * FROM foos"
)
metric.end_time = time.time()

notifier.queries.notify(metric)
Sending queue stats

notifier.queues.notify allows sending queue (job) stats to Airbrake. The library provides integration with Celery (your queues are tracked automatically). You can also use this API manually:

import pybrake.QueueMetric as QueueMetric

metric = QueryMetric(queue="foo_queue")
notifier.queues.notify(metric)
Congratulations!
Great job! If you’ve used this example in your app, you can visit your Airbrake project’s Performance Dashboard to see your performance data! Soon enough you’ll have more insights into your application’s performance. In the meantime why not check out the Performance Dashboard features. Have questions about Performance Monitoring? Check out our Performance Monitoring FAQ for more information.
Want to learn more?

Want to learn more about pybrake? Check out our official GitHub repo.

Monitoring Django apps

Django Support

The pybrake package makes it quick and easy to monitor your Django app’s performance. It only takes a few minutes to start collecting real performance data so let’s jump right in!

Step 1: Install the latest version of pybrake

Airbrake for Django uses our official Python notifier pybrake. To install run:

pip install -U pybrake
Step 2: Configure the Airbrake Django middleware

First, configure project_id and project_key in settings.py:

AIRBRAKE = dict(
    project_id=123,
    project_key='FIXME',
)

Next, activate the Airbrake middleware:

MIDDLEWARE = [
    ...
    'pybrake.django.AirbrakeMiddleware',
]

Finally, configure the airbrake logging handler:

LOGGING = {
    'version': 1,
    'disable_existing_loggers': False,
    'handlers': {
        'airbrake': {
            'level': 'ERROR',
            'class': 'pybrake.LoggingHandler',
        },
    },
    'loggers': {
        'app': {
            'handlers': ['airbrake'],
            'level': 'ERROR',
            'propagate': True,
        },
    },
}

Now you are ready to start reporting errors to Airbrake from your Django app.

Congratulations!
Great job! If you’ve used this example in your app, you can visit your Airbrake project’s Performance Dashboard to see your performance data! Soon enough you’ll have more insights into your application’s performance. In the meantime why not check out the Performance Dashboard features. Have questions about Performance Monitoring? Check out our Performance Monitoring FAQ for more information.
Want to learn more?

Want to learn more about pybrake? Check out our official GitHub repo.

Monitoring Flask apps

Flask Support

The pybrake package makes it quick and easy to monitor your Flask app’s performance. It only takes a few minutes to start collecting real performance data so let’s jump right in!

Step 1: Install the latest version of pybrake

Airbrake for Flask uses our official Python notifier pybrake. To install run:

pip install -U pybrake
Step 2: Configure the Airbrake Flask middleware

Replace the placeholder project_id and project_key values from the example below with the real values from your project’s setting page.

Note: Flask integration uses Flask signals and therefore requires the blinker library.

from flask import Flask
import pybrake.flask

app = Flask(__name__)

app.config['PYBRAKE'] = dict(
    project_id=123,
    project_key='FIXME',
)
app = pybrake.flask.init_app(app)
Congratulations!
Great job! If you’ve used this example in your app, you can visit your Airbrake project’s Performance Dashboard to see your performance data! Soon enough you’ll have more insights into your application’s performance. In the meantime why not check out the Performance Dashboard features. Have questions about Performance Monitoring? Check out our Performance Monitoring FAQ for more information.
Want to learn more?

Want to learn more about pybrake? Check out our official GitHub repo.

Updating from airbrake-js for Node.js projects

Name change note

Our JavaScript library’s name has recently changed from airbrake-js to @airbrake/node (for Node.js apps). If you are using airbrake-js, we would recommend following this guide to update to the latest version of our JavaScript library.

Step 1: Uninstall airbrake-js

Uninstall the old package:

npm uninstall airbrake-js
Step 2: Install @airbrake/node

Install the new package with npm:

npm install @airbrake/node

We also support installation via Yarn.

Step 3: Replace mentions with new library

Note: Express.js users should follow our Express.js install guide.

Imports: Replace old library import:
var AirbrakeClient = require('airbrake-js');

With new package name:

var Airbrake = require('@airbrake/node');
Class names:

Replace configuration snippet instantiation with new name:

Change AirbrakeClient() to new name: Airbrake.Notifier() in your configuration snippet:

var airbrake = new Airbrake.Notifier({
  // project credentials are set here...
});

Find advanced configuration options and examples on our official GitHub repo.

Updating from node-airbrake for Node.js projects

Library note

This update guide is for projects on node-airbrake. For projects on airbrake-js, please visit our other guide. For projects on @airbrake/node, please visit our other guide.

Step 1: Uninstall airbrake

Uninstall the old package:

npm uninstall airbrake
Step 2: Install @airbrake/node

Install the new package with npm:

npm install @airbrake/node

We also support installation via Yarn.

Step 3: Replace mentions with new library

Note: Express.js users should follow our Express.js install guide.

Replace old configuration snippet instantiation:

var airbrake = require('airbrake').createClient(
  '123987',       // Project ID
  'abcdefg123456' // Project key
);
airbrake.handleExceptions();

With new package format:

var Airbrake = require('@airbrake/node');

var airbrake = new Airbrake.Notifier({
  projectId: '123987',
  projectKey: 'abcdefg123456',
});

Find advanced configuration options and examples on our official GitHub repo.

Updating from older Python notifiers

Get the most out of Airbrake’s features and stay up to date with the latest improvements by updating your project to the latest version of our Python error reporting library for Django and Flask.

If you are using Python 3.4+, we would recommend upgrading the Airbrake library you use from airbrake-python to our new official notifier: pybrake.

Step 1: uninstall airbrake-python
pip uninstall airbrake
Step 2: remove references to the old notifier

Remove references to airbrake like imports:

import airbrake

logger = airbrake.getLogger(api_key=*****, project_id=123
Step 3: install new notifier
pip install -U pybrake
Configuration

To configure pybrake you will need your Airbrake project’s id and api_key, these are available from your project’s settings page.

import pybrake

notifier = pybrake.Notifier(project_id=123,
                            project_key='FIXME',
                            environment='production')
Sending errors to Airbrake
try:
    raise ValueError('hello')
except Exception as err:
    notifier.notify(err)

Updating your Go notifier

Get the most out of Airbrake’s features and stay up to date with the latest improvements by updating your project to the latest version of our Go error reporting library.

To update gobrake, run the following command:

go get -u github.com/airbrake/gobrake/v4

Updating your Python notifier

Get the most out of Airbrake’s features and stay up to date with the latest improvements by updating your project to the latest version of our Python error reporting library for Django and Flask.

To update your notifier, run this command:

pip install --upgrade pybrake

Haven’t installed Pybrake yet? Check out our install guide for your framework: