-
Notifications
You must be signed in to change notification settings - Fork 375
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactored: Faraday to use Datadog::Contrib::Integration. (#570)
- Loading branch information
Showing
7 changed files
with
127 additions
and
70 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 |
---|---|---|
@@ -0,0 +1,22 @@ | ||
require 'ddtrace/contrib/configuration/settings' | ||
require 'ddtrace/ext/http' | ||
require 'ddtrace/contrib/faraday/ext' | ||
|
||
module Datadog | ||
module Contrib | ||
module Faraday | ||
module Configuration | ||
# Custom settings for the Faraday integration | ||
class Settings < Contrib::Configuration::Settings | ||
DEFAULT_ERROR_HANDLER = lambda do |env| | ||
Datadog::Ext::HTTP::ERROR_RANGE.cover?(env[:status]) | ||
end | ||
|
||
option :distributed_tracing, default: false | ||
option :error_handler, default: DEFAULT_ERROR_HANDLER | ||
option :service_name, default: Ext::SERVICE_NAME | ||
end | ||
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,13 @@ | ||
module Datadog | ||
module Contrib | ||
module Faraday | ||
# Faraday integration constants | ||
module Ext | ||
APP = 'faraday'.freeze | ||
SERVICE_NAME = 'faraday'.freeze | ||
|
||
SPAN_REQUEST = 'faraday.request'.freeze | ||
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,36 @@ | ||
require 'ddtrace/contrib/integration' | ||
require 'ddtrace/contrib/faraday/configuration/settings' | ||
require 'ddtrace/contrib/faraday/patcher' | ||
|
||
module Datadog | ||
module Contrib | ||
module Faraday | ||
# Description of Faraday integration | ||
class Integration | ||
include Contrib::Integration | ||
|
||
register_as :faraday, auto_patch: true | ||
|
||
def self.version | ||
Gem.loaded_specs['faraday'] && Gem.loaded_specs['faraday'].version | ||
end | ||
|
||
def self.present? | ||
super && defined?(::Faraday) | ||
end | ||
|
||
def self.compatible? | ||
super && version < Gem::Version.new('1.0.0') | ||
end | ||
|
||
def default_configuration | ||
Configuration::Settings.new | ||
end | ||
|
||
def patcher | ||
Patcher | ||
end | ||
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
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