The Service Map for APM is here!

Ruby

Library Library

Overview

The Ruby integration allows you to monitor custom metrics by adding a few lines of code to your Ruby application. For example, a metric that returns the number of page views or the time of any function call.

Setup

Datadog offers two libraries to assist you with the implementation of Ruby application metrics:

Library Description
dogstatsd-ruby A client for DogStatsD, an extension of the StatsD metric server for Datadog.
dogapi-rb The Ruby client is a library suitable for inclusion in existing Ruby projects or for development of standalone scripts. It provides an abstraction on top of Datadog’s raw HTTP interface for reporting events and metrics.

Installation

To install the Ruby client for the Datadog API:

gem install dogapi

To install the dogstatsd-ruby client for DogStatsD:

gem install dogstatsd-ruby

Metric collection

For the Ruby integration, all metrics are custom metrics. For information on collecting custom metrics see the:

Below is an example of instrumenting your code using the Datadog API:


require 'rubygems'
require 'dogapi'

api_key = "<YOUR_DD_API_KEY>"
application_key = "<YOUR_DD_APP_KEY>"

# Submitting events does not require the application key.
dog = Dogapi::Client.new(api_key)

# Send a new event.
dog.emit_event(Dogapi::Event.new('msg_text', :msg_title => 'Title'))

Below is an example of instrumenting your code using the DogStatsD client:

# Load the dogstats module.
require 'datadog/statsd'

# Create a stats instance.
statsd = Datadog::Statsd.new('localhost', 8125)

# Increment a counter.
statsd.increment('page.views')

# Record a gauge 50% of the time.
statsd.gauge('users.online', 123, :sample_rate=>0.5)

Trace collection

See Datadog’s dedicated documentation for Tracing Ruby Applications.

Log collection

Available for Agent v6.0+

See Datadog’s dedicated documentation for Ruby on Rails log collection.

Troubleshooting

Need help? Contact Datadog support.

Further Reading

Additional helpful documentation, links, and articles: