-
Notifications
You must be signed in to change notification settings - Fork 373
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Implement HTTP integration configuration #556
Merged
delner
merged 1 commit into
refactor/upgrade_to_integration_configuration
from
refactor/http_integration_configuration
Sep 26, 2018
+114
−61
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Might be a bit confusing with CircuitBreaker pattern. But I don't have better suggestion :D
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is there a "circuit breaker" pattern? I was trying to think of something that encapsulated the idea of "if looping, escape", like a short-circuit where the circuit breaker trips to prevent an overload. But maybe a metaphor here isn't the best choice of naming scheme.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
FYI https://martinfowler.com/bliki/CircuitBreaker.html
on a high level it also breaks circuit, but its a bit more dynamic and serves a bit different purpose.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Right... a microservices related pattern. Forgot about this one.