Skip to content

Commit

Permalink
[WIP] Propagate sampling_priority
Browse files Browse the repository at this point in the history
  • Loading branch information
p-lambert committed Nov 3, 2017
1 parent 2c02803 commit 57f18fa
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 4 deletions.
10 changes: 6 additions & 4 deletions lib/ddtrace/contrib/faraday/middleware.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ module Contrib
module Faraday
# Middleware implements a faraday-middleware for ddtrace instrumentation
class Middleware < ::Faraday::Middleware
include Ext::DistributedTracing

DEFAULT_ERROR_HANDLER = lambda do |env|
Ext::HTTP::ERROR_RANGE.cover?(env[:status])
end
Expand Down Expand Up @@ -54,10 +56,10 @@ def handle_response(span, env)
end

def propagate!(span, env)
env[:request_headers].merge!(
Ext::DistributedTracing::HTTP_HEADER_TRACE_ID => span.trace_id.to_s,
Ext::DistributedTracing::HTTP_HEADER_PARENT_ID => span.span_id.to_s
)
env[:request_headers][HTTP_HEADER_TRACE_ID] = span.trace_id.to_s
env[:request_headers][HTTP_HEADER_PARENT_ID] = span.span_id.to_s
return unless span.sampling_priority
env[:request_headers][HTTP_HEADER_SAMPLING_PRIORITY] = span.sampling_priority.to_s
end

def dd_pin
Expand Down
3 changes: 3 additions & 0 deletions lib/ddtrace/contrib/http/patcher.rb
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,9 @@ def request(req, body = nil, &block) # :yield: +response+
unless Datadog::Contrib::HTTP.should_skip_distributed_tracing?(pin)
req.add_field(Datadog::Ext::DistributedTracing::HTTP_HEADER_TRACE_ID, span.trace_id)
req.add_field(Datadog::Ext::DistributedTracing::HTTP_HEADER_PARENT_ID, span.span_id)
if span.sampling_priority
req.add_field(Datadog::Ext::DistributedTracing::HTTP_HEADER_SAMPLING_PRIORITY, span.sampling_priority)
end
end
rescue StandardError => e
Datadog::Tracer.log.error("error preparing span for http request: #{e}")
Expand Down
2 changes: 2 additions & 0 deletions lib/ddtrace/span.rb
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ def initialize(tracer, name, options = {})
@span_id = Datadog::Utils.next_id
@parent_id = options.fetch(:parent_id, 0)
@trace_id = options.fetch(:trace_id, Datadog::Utils.next_id)
@sampling_priority = options[:sampling_priority]

@context = options.fetch(:context, nil)

Expand Down Expand Up @@ -160,6 +161,7 @@ def parent=(parent)
@parent_id = parent.span_id
@service ||= parent.service
@sampled = parent.sampled
@sampling_priority = parent.sampling_priority
end
end

Expand Down

0 comments on commit 57f18fa

Please sign in to comment.