Skip to content

Instantly share code, notes, and snippets.

@kigster
Created February 21, 2020 22:18
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kigster/40497c194f99ed58fd94015447a0fdf5 to your computer and use it in GitHub Desktop.
Save kigster/40497c194f99ed58fd94015447a0fdf5 to your computer and use it in GitHub Desktop.
Datadog Rails Configuration
# config/initializers/datadog.rb
require 'ddtrace'
require 'redis'
Datadog::Tracer.log = Logger.new(nil)
# This is the port we have configured in the /etc/datadog/datadog.yml (apm_config)
Datadog.tracer.configure(port: 9126, enabled: true)
# TODO: change me
program = 'App Name'
if %w(staging production).include?(ENV['RAILS_ENV'])
require 'active_record'
require 'dalli'
# Here we register Rails services and override automatically generated names by Datadog
# with something more sensible in our context. We rename the tracers based on what process
# they are (i.e. -rails-tasks, or -rails-puma) and whether it's not rails at all, but redis
# or dalli.
Datadog.configure do |c|
c.tracer enabled: true
# https://github.com/DataDog/dd-trace-rb/blob/master/docs/GettingStarted.md#rails
c.use :rails,
service_name: program,
database_service: program + '-database',
controller_service: program + '-controller',
cache_service: program + '-cache',
distributed_tracing: true,
middleware_names: true
# https://github.com/DataDog/dd-trace-rb/blob/master/docs/GettingStarted.md#active-record
c.use :active_record,
service_name: program + '-activerecord',
orm_service_name: program + '-activerecord'
c.use :http, service_name: program + '-http-outbound'
# https://github.com/DataDog/dd-trace-rb/blob/master/docs/GettingStarted.md#sidekiq
c.use :sidekiq, service_name: program
# https://github.com/DataDog/dd-trace-rb/blob/master/docs/GettingStarted.md#redis
c.use :redis, service_name: program + '-redis'
# https://github.com/DataDog/dd-trace-rb/blob/master/docs/GettingStarted.md#dalli
c.use :dalli, service_name: program + '-memcached'
# https://github.com/DataDog/dd-trace-rb/blob/master/docs/GettingStarted.md#aws
c.use :aws, service_name: program + '-aws'
end
else
Datadog.configure do |c|
c.tracer enabled: false
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment