Skip to content
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

http connect tracing #2847

Draft
wants to merge 3 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions lib/datadog/tracing/contrib/http/ext.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,10 @@ module Ext
ENV_ANALYTICS_SAMPLE_RATE = 'DD_TRACE_HTTP_ANALYTICS_SAMPLE_RATE'.freeze
ENV_ERROR_STATUS_CODES = 'DD_TRACE_HTTP_ERROR_STATUS_CODES'.freeze
DEFAULT_PEER_SERVICE_NAME = 'net/http'.freeze
SPAN_CONNECT = 'http.connect'.freeze
SPAN_REQUEST = 'http.request'.freeze
TAG_COMPONENT = 'net/http'.freeze
TAG_OPERATION_CONNECT = 'connect'.freeze
TAG_OPERATION_REQUEST = 'request'.freeze
end
end
Expand Down
46 changes: 46 additions & 0 deletions lib/datadog/tracing/contrib/http/instrumentation.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,52 @@ def self.after_request(&block)
module InstanceMethods
include Contrib::HttpAnnotationHelper

def connect
host = @address.split('/')[0] # trim path
port = @port
request_options = datadog_configuration(host)
client_config = Datadog.configuration_for(self)

# TODO: use actual ddog host
return super if host == Datadog::Transport::HTTP.default_hostname

Tracing.trace(Ext::SPAN_CONNECT, on_error: method(:annotate_span_with_error!)) do |span, trace|
begin
span.service = service_name(host, request_options, client_config)
span.span_type = Tracing::Metadata::Ext::HTTP::TYPE_OUTBOUND
span.resource = host

if Tracing.enabled? && !Contrib::HTTP.should_skip_distributed_tracing?(client_config)
Tracing::Propagation::HTTP.inject!(trace, req)
end

# Add additional request specific tags to the span.
span.set_tag(Tracing::Metadata::Ext::TAG_KIND, Tracing::Metadata::Ext::SpanKind::TAG_CLIENT)

span.set_tag(Tracing::Metadata::Ext::TAG_COMPONENT, Ext::TAG_COMPONENT)
span.set_tag(Tracing::Metadata::Ext::TAG_OPERATION, Ext::TAG_OPERATION_CONNECT)

host, port = host_and_port(request)
span.set_tag(Tracing::Metadata::Ext::NET::TAG_TARGET_HOST, host)
span.set_tag(Tracing::Metadata::Ext::NET::TAG_TARGET_PORT, port.to_s)

if Contrib::SpanAttributeSchema.default_span_attribute_schema?
# Tag as an external peer service
span.set_tag(Tracing::Metadata::Ext::TAG_PEER_SERVICE, span.service)
end

span.set_tag(Tracing::Metadata::Ext::TAG_PEER_HOSTNAME, host)

# Set analytics sample rate
set_analytics_sample_rate(span, request_options)
rescue StandardError => e
Datadog.logger.error("error preparing span for http connect: #{e}")
ensure
super
end
end
end

# :yield: +response+
def request(req, body = nil, &block)
host, = host_and_port(req)
Expand Down