Skip to content

Commit

Permalink
Support for Datadog's tracing client
Browse files Browse the repository at this point in the history
  • Loading branch information
darnaut committed Feb 22, 2021
1 parent c07a196 commit 8ae0957
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 1 deletion.
4 changes: 4 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,7 @@ group :newrelic do
gem 'newrelic_rpm', '~> 3.18.1'
gem 'newrelic-zookeeper', '~> 1.0.0'
end

group :ddtrace do
gem 'ddtrace', '~> 0.45.0'
end
30 changes: 29 additions & 1 deletion config.ru
Original file line number Diff line number Diff line change
Expand Up @@ -110,11 +110,39 @@ when false, nil then false
else raise 'unknown value for ip_check option'
end

# start the app
# load the app
require './optica.rb'

# configure tracing client
def datadog_config(log)
Datadog.configure do |c|
service = ENV.fetch('DD_SERVICE', 'optica')
c.use :sinatra, service_name: service
# Statsd instance used for sending runtime metrics
c.runtime_metrics.statsd = STATSD
end

# register tracer extension
Optica.register Datadog::Contrib::Sinatra::Tracer

# add correlation IDs to logger
log.formatter = proc do |severity, datetime, progname, msg|
"[#{datetime}][#{progname}][#{severity}][#{Datadog.tracer.active_correlation}] #{msg}\n"
end
end

begin
require 'ddtrace/auto_instrument'
datadog_config(log)
rescue LoadError
log.info "Datadog's tracing client not found, skipping..."
end

Optica.set :logger, log
Optica.set :store, store
Optica.set :events, events
Optica.set :ip_check, ip_check

# start the app
log.info "Starting sinatra server..."
run Optica
4 changes: 4 additions & 0 deletions optica.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@
require 'oj'

class Optica < Sinatra::Base
before do
env['rack.logger'] = settings.logger
end

configure :production, :development do
enable :logging
end
Expand Down

0 comments on commit 8ae0957

Please sign in to comment.