-
Notifications
You must be signed in to change notification settings - Fork 235
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2885 from zendesk/sathish/BRE-865
Datadog APM
- Loading branch information
Showing
23 changed files
with
639 additions
and
20 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -45,4 +45,4 @@ | |
|
||
# .bak files | ||
*.bak | ||
/vendor/cache/**/ | ||
/vendor/cache |
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
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
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
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,44 @@ | ||
# frozen_string_literal: true | ||
module Samson | ||
module PerformanceTracer | ||
# It's used to trace the hook fire event, | ||
# We can't use the samson hook to fetch the available plugins. | ||
TRACER_PLUGINS = ['SamsonNewRelic', 'SamsonDatadogTracer::APM'].freeze | ||
|
||
class << self | ||
def included(clazz) | ||
clazz.extend ClassMethods | ||
end | ||
|
||
def trace_execution_scoped(scope_name) | ||
# Tracing the scope is restricted to avoid into slow startup | ||
# Refer Samson::BootCheck | ||
if ['staging', 'production'].include?(Rails.env) | ||
plugins = TRACER_PLUGINS.map(&:safe_constantize).compact | ||
execution = using_plugins plugins, scope_name do | ||
yield | ||
end | ||
execution.call | ||
else | ||
yield | ||
end | ||
end | ||
|
||
def using_plugins(plugins, scope_name, &block) | ||
plugins.inject(block) { |inner, plugin| plugin.trace_method_execution_scope(scope_name) { inner } } | ||
end | ||
end | ||
|
||
# for Newrelic and Datadog -> for tracer plugins. | ||
module ClassMethods | ||
def add_tracer(method) | ||
Samson::Hooks.fire(:performance_tracer, self, method) | ||
end | ||
|
||
# TODO: Add asynchronous tracer for Datadog. | ||
def add_asynchronous_tracer(method, options) | ||
Samson::Hooks.fire(:asynchronous_performance_tracer, self, method, options) | ||
end | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
# Datadog Plugin | ||
|
||
Plugin that trace requests and notify to Datadog APM |
43 changes: 43 additions & 0 deletions
43
plugins/datadog_tracer/config/initializers/datadog_tracer.rb
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,43 @@ | ||
# frozen_string_literal: true | ||
if SamsonDatadogTracer.enabled? | ||
|
||
SamsonDatadogTracer::IGNORED_URLS = Set[ | ||
'/ping', | ||
'/cable', | ||
].freeze | ||
|
||
require 'ddtrace' | ||
Datadog.configure do |c| | ||
# Tracer | ||
c.tracer( | ||
hostname: ENV['STATSD_HOST'] || '127.0.0.1', | ||
tags: { | ||
env: ENV['RAILS_ENV'], | ||
'rails.version': Rails.version, | ||
'ruby.version': RUBY_VERSION | ||
} | ||
) | ||
|
||
c.use :rails, | ||
service_name: 'samson', | ||
controller_service: 'samson-rails-controller', | ||
cache_service: 'samson-cache', | ||
database_service: 'samson-mysql', | ||
distributed_tracing: true | ||
|
||
c.use :faraday, service_name: 'samson-faraday' | ||
c.use :dalli, service_name: 'samson-dalli' | ||
|
||
require 'aws-sdk-ecr' | ||
c.use :aws, service_name: 'samson-aws' | ||
end | ||
|
||
# Span Filters | ||
# Filter out the health checks, version checks, and diagnostics | ||
uninteresting_controller_filter = Datadog::Pipeline::SpanFilter.new do |span| | ||
span.name == 'rack.request' && | ||
SamsonDatadogTracer::IGNORED_URLS.any? { |path| span.get_tag('http.url').include?(path) } | ||
end | ||
|
||
Datadog::Pipeline.before_flush(uninteresting_controller_filter) | ||
end |
Oops, something went wrong.