-
Notifications
You must be signed in to change notification settings - Fork 373
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Turn
rails
into regular contribution
- Loading branch information
Showing
7 changed files
with
107 additions
and
83 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
module Datadog | ||
module Contrib | ||
module Rails | ||
# Patcher | ||
module Patcher | ||
include Base | ||
register_as :rails, auto_patch: true | ||
|
||
option :enabled, default: true | ||
option :auto_instrument, default: false | ||
option :auto_instrument_redis, default: false | ||
option :auto_instrument_grape, default: false | ||
option :default_service, default: 'rails-app' | ||
option :default_controller_service, default: 'rails-controller' | ||
option :default_cache_service, default: 'rails-cache' | ||
option :default_grape_service, default: 'grape' | ||
option :default_database_service | ||
option :distributed_tracing_enabled, default: false | ||
option :template_base_path, default: 'views/' | ||
option :tracer, default: Datadog.tracer | ||
option :debug, default: false | ||
option :trace_agent_hostname, default: Datadog::Writer::HOSTNAME | ||
option :trace_agent_port, default: Datadog::Writer::PORT | ||
option :env, default: nil | ||
option :tags, default: {} | ||
option :sidekiq_service | ||
|
||
@patched = false | ||
|
||
class << self | ||
def patch | ||
return @patched if patched? || !compatible? | ||
require_relative 'framework' | ||
@patched = true | ||
rescue => e | ||
Datadog::Tracer.log.error("Unable to apply Rails integration: #{e}") | ||
@patched | ||
end | ||
|
||
def patched? | ||
@patched | ||
end | ||
|
||
def compatible? | ||
return if ENV['DISABLE_DATADOG_RAILS'] | ||
|
||
defined?(::Rails::VERSION) && ::Rails::VERSION::MAJOR.to_i >= 3 | ||
end | ||
end | ||
end | ||
end | ||
end | ||
end | ||
|
||
require 'ddtrace/contrib/rails/railtie' if Datadog.registry[:rails].compatible? |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
require 'ddtrace/contrib/rails/framework' | ||
require 'ddtrace/contrib/rails/middlewares' | ||
require 'ddtrace/contrib/rack/middlewares' | ||
|
||
module Datadog | ||
# Railtie class initializes | ||
class Railtie < Rails::Railtie | ||
config.app_middleware.use(Datadog::Contrib::Rails::ExceptionMiddleware) | ||
|
||
config.after_initialize do |app| | ||
Datadog::Contrib::Rails::Framework.configure(config: app.config) | ||
Datadog::Contrib::Rails::Framework.auto_instrument | ||
Datadog::Contrib::Rails::Framework.auto_instrument_redis | ||
Datadog::Contrib::Rails::Framework.auto_instrument_grape | ||
end | ||
|
||
# Configure datadog settings before building the middleware stack. | ||
# This is required because the middleware stack is frozen after | ||
# the initialization and so it's too late to add our tracing | ||
# functionalities. | ||
initializer :datadog_config, before: :build_middleware_stack do |app| | ||
app.config.middleware.insert_before( | ||
0, Datadog::Contrib::Rack::TraceMiddleware | ||
) | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters