Ruby Example¶
Install Dependence¶
Rails Applications¶
- Add ddtrace gem to your Gemfile:
-
Install the gem using bundle.
-
Create the configuration file
config/initializers/datadog.rb
:
Datadog.configure do |c|
# Add additional configuration here.
# Activate integrations, change tracer settings, etc...
end
Ruby Applications¶
- Add ddtrace gem to your Gemfile:
- Install the gem using bundle.
- Add require 'ddtrace/auto_instrument' to Ruby code. Note: It needs to be loaded after all the library and framework are loaded.
# Example frameworks and libraries
require 'sinatra'
require 'faraday'
require 'redis'
require 'ddtrace/auto_instrument'
- Add configuration blocks to Ruby applications:
Datadog.configure do |c|
# Add additional configuration here.
# Activate integrations, change tracer settings, etc...
end
Configuring OpenTracing¶
- Add ddtrace gem to your Gemfile:
-
Install the gem using bundle.
-
Add the following code to the OpenTracing configuration:
require 'opentracing'
require 'datadog/tracing'
require 'datadog/opentracer'
# Activate the Datadog tracer for OpenTracing
OpenTracing.global_tracer = Datadog::OpenTracer::Tracer.new
- Add configuration blocks to Ruby applications:
Datadog.configure do |c|
# Configure the Datadog tracer here.
# Activate integrations, change tracer settings, etc...
# By default without additional configuration,
# no additional integrations will be traced, only
# what you have instrumented with OpenTracing.
end
Integration Instrumentation¶
Many libraries and frameworks support automatic detection out of the box. Automatic detection can be turned on by simple configuration. Using the Datadog.configure API:
Datadog.configure do |c|
# Activates and configures an integration
c.tracing.instrument :integration_name, options
end
Run¶
You can configure environment variables and start Ruby:
You can also configure the Datadog.configure code block by: