Skip to content

This integration allows you to log issues that occur directly from your gateway.

Notifications You must be signed in to change notification settings

maxamante/rollbar-nginx

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Rollbar Nginx Integration

This is a Rollbar integration written in Lua for the nginx web server.

This integration allows you to log issues that occur directly from your gateway.

Why use an nginx plugin?

Instead of using a logging aggregator to find anomalies in your gateway, you use this integration to send custom logs to Rollbar to more easily track and organize issues within your backend.

location /secret/api/ {
    content_by_lua_block {
        local rollbar = require("rollbar-nginx")
        rollbar.createMessageItem('Someone found the secret API')
    }
}

When a user makes a request to /secret/api, you can log it to Rollbar.

Installation

Rollbar's nginx integration requires the use of OpenResty. To use the nginx integration, make sure you have the following installed and configured:

  • OpenResty - a distribution of the nginx web server that includes the lua plugin
  • Lua - the Lua programming language
  • Luarocks - a Lua package manager

If you're new to OpenResty, the following tips will help you make sure you configure Lua properly:

  • When installing Lua, don't forget to sudo make install after building Lua with make linux test
  • You should add Luarocks modules to your lua path by running this command and adding it to your .bash_profile file: eval $(luarocks path --bin). Otherwise, nginx will not detect your Luarocks modules.

With Luarocks, you can install the Rollbar nginx plugin with:

luarocks install rollbar-nginx --local

Usage

If it's your first time using OpenResty, check out the Getting Started with OpenResty guide on how to configure and run nginx.

The Rollbar plugin allows you to log pretty much anything by adding code in the content_by_lua_block hooks exposed by OpenResty.

Configuring the Rollbar API Key

As with any other nginx integration, the Rollbar nginx plugin reads environment variables to find the Rollbar API key. Sign into your Rollbar account and find the project key that has the post_server_item scope by running this and adding to your .bash_profile:

export ROLLBAR_API_TOKEN=<Rollbar API token>

With nginx, you need to explicitly expose an environment variable to modules in the configuration, so you need to add into the top level configuration:

env ROLLBAR_API_TOKEN;

Using the Rollbar message endpoint

You can send message-based items using the following:

location = /admin/api/ {
    content_by_lua_block {
        local rollbar = require('rollbar-nginx')
        local fromIp = ngx.var.http_x_forwarded_for
        rollbar.createMessageItem(fromIp .. ' has accessed the admin API')
    }
}

Creating Rollbar message items will not break or exit execute unless you set it to do so.

About

This integration allows you to log issues that occur directly from your gateway.

Resources

Stars

Watchers

Forks

Packages

No packages published