-
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.
Refactored: HTTP to use Datadog::Contrib::Integration. (#556)
- Loading branch information
Showing
7 changed files
with
114 additions
and
61 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,39 @@ | ||
|
||
module Datadog | ||
module Contrib | ||
module HTTP | ||
# HTTP integration circuit breaker behavior | ||
# For avoiding recursive traces. | ||
module CircuitBreaker | ||
def should_skip_tracing?(req, address, port, transport, pin) | ||
# we don't want to trace our own call to the API (they use net/http) | ||
# when we know the host & port (from the URI) we use it, else (most-likely | ||
# called with a block) rely on the URL at the end. | ||
if req.respond_to?(:uri) && req.uri | ||
if req.uri.host.to_s == transport.hostname.to_s && | ||
req.uri.port.to_i == transport.port.to_i | ||
return true | ||
end | ||
elsif address && port && | ||
address.to_s == transport.hostname.to_s && | ||
port.to_i == transport.port.to_i | ||
return true | ||
end | ||
# we don't want a "shotgun" effect with two nested traces for one | ||
# logical get, and request is likely to call itself recursively | ||
active = pin.tracer.active_span | ||
return true if active && (active.name == Ext::SPAN_REQUEST) | ||
false | ||
end | ||
|
||
def should_skip_distributed_tracing?(pin) | ||
if pin.config && pin.config.key?(:distributed_tracing) | ||
return !pin.config[:distributed_tracing] | ||
end | ||
|
||
!Datadog.configuration[:http][:distributed_tracing] | ||
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,17 @@ | ||
require 'ddtrace/contrib/configuration/settings' | ||
require 'ddtrace/contrib/http/ext' | ||
|
||
module Datadog | ||
module Contrib | ||
module HTTP | ||
module Configuration | ||
# Custom settings for the HTTP integration | ||
class Settings < Contrib::Configuration::Settings | ||
option :distributed_tracing, default: false | ||
option :service_name, default: Ext::SERVICE_NAME | ||
option :tracer, default: Datadog.tracer | ||
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 HTTP | ||
# HTTP integration constants | ||
module Ext | ||
APP = 'net/http'.freeze | ||
SERVICE_NAME = 'net/http'.freeze | ||
|
||
SPAN_REQUEST = 'http.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,32 @@ | ||
require 'ddtrace/contrib/integration' | ||
require 'ddtrace/contrib/http/configuration/settings' | ||
require 'ddtrace/contrib/http/patcher' | ||
require 'ddtrace/contrib/http/circuit_breaker' | ||
|
||
module Datadog | ||
module Contrib | ||
# HTTP integration | ||
module HTTP | ||
extend CircuitBreaker | ||
|
||
# Description of HTTP integration | ||
class Integration | ||
include Contrib::Integration | ||
|
||
register_as :http, auto_patch: true | ||
|
||
def self.version | ||
Gem::Version.new(RUBY_VERSION) | ||
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