Sinatra

Supported OS Linux Mac OS Windows

Overview

This integration enables you to get web access logging from your Sinatra applications in order to monitor:

  • Errors logs (4xx codes, 5xx codes)
  • Web pages response time
  • Number of requests
  • Number of bytes exchanged

Setup

Installation

Install the Agent on the instance that runs your Sinatra application.

Configuration

The default Sinatra logging feature logs to stdout. Datadog recommends that you use the Rack Common Logger in order to log to a file and in the console.

Here is a configuration example that generate logs in a file and the console. This can be set in the Rack configuration file (config.ru) or the configuration block for your Sinatra application.

require 'sinatra'

configure do
  # logging is enabled by default in classic style applications,
  # so `enable :logging` is not needed
  file = File.new("/var/log/sinatra/access.log", 'a+')
  file.sync = true
  use Rack::CommonLogger, file
end

get '/' do
  'Hello World'
end

This logger uses the common Apache Access format and generates logs in the following format:

127.0.0.1 - - [15/Jul/2018:17:41:40 +0000] "GET /uptime_status HTTP/1.1" 200 34 0.0004
127.0.0.1 - - [15/Jul/2018 23:40:31] "GET /uptime_status HTTP/1.1" 200 6997 1.8096

Log collection

Available for Agent versions >6.0

  1. Collecting logs is disabled by default in the Datadog Agent. Enable it in your datadog.yaml file with:

    logs_enabled: true
    
  2. Add this configuration block to your sinatra.d/conf.yaml file at the root of your Agent’s configuration directory to start collecting your Sinatra application logs:

    logs:
      - type: file
        path: /var/log/sinatra/access.log
        source: sinatra
        service: webapp
    

    Change the path and service parameter values and configure them for your environment.

  3. Restart the Agent

PREVIEWING: mervebolat/span-id-preprocessing