-
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.
- Loading branch information
Showing
11 changed files
with
119 additions
and
44 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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
# frozen_string_literal: true | ||
|
||
require_relative 'distributed/b3_multi' | ||
require_relative 'distributed/b3_single' | ||
require_relative 'distributed/datadog' | ||
require_relative 'distributed/none' | ||
require_relative 'distributed/propagation' | ||
require_relative 'distributed/trace_context' | ||
require_relative 'contrib/component' | ||
|
||
module Datadog | ||
module Tracing | ||
# Namespace for distributed tracing propagation and correlation | ||
module Distributed | ||
module_function | ||
|
||
# Inject distributed headers into the given request | ||
# @param digest [Datadog::Tracing::TraceDigest] the trace to inject | ||
# @param data [Hash] the request to inject | ||
def inject(digest, data) | ||
raise 'Please invoke Datadog.configure at least once before calling this method' unless @propagation | ||
|
||
@propagation.inject!(digest, data) | ||
end | ||
|
||
# Extract distributed headers from the given request | ||
# @param data [Hash] the request to extract from | ||
# @return [Datadog::Tracing::TraceDigest,nil] the extracted trace digest or nil if none was found | ||
def extract(data) | ||
raise 'Please invoke Datadog.configure at least once before calling this method' unless @propagation | ||
|
||
@propagation.extract(data) | ||
end | ||
|
||
Contrib::Component.register('distributed') do |config| | ||
tracing = config.tracing | ||
# DEV: evaluate propagation_style in case it overrides propagation_style_extract & propagation_extract_first | ||
tracing.propagation_style | ||
|
||
@propagation = Propagation.new( | ||
propagation_styles: { | ||
Configuration::Ext::Distributed::PROPAGATION_STYLE_B3_MULTI_HEADER => | ||
B3Multi.new(fetcher: Fetcher), | ||
Configuration::Ext::Distributed::PROPAGATION_STYLE_B3_SINGLE_HEADER => | ||
B3Single.new(fetcher: Fetcher), | ||
Configuration::Ext::Distributed::PROPAGATION_STYLE_DATADOG => | ||
Datadog.new(fetcher: Fetcher), | ||
Configuration::Ext::Distributed::PROPAGATION_STYLE_TRACE_CONTEXT => | ||
TraceContext.new(fetcher: Fetcher), | ||
Configuration::Ext::Distributed::PROPAGATION_STYLE_NONE => None.new | ||
}, | ||
propagation_style_inject: tracing.propagation_style_inject, | ||
propagation_style_extract: tracing.propagation_style_extract, | ||
propagation_extract_first: tracing.propagation_extract_first | ||
) | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
module Datadog | ||
module Tracing | ||
module Distributed | ||
@propagation: Propagation | ||
|
||
def inject: (TraceDigest digest, ::Hash[untyped, untyped] data) -> (bool | nil) | ||
|
||
def extract: (::Hash[untyped, untyped] data) -> (TraceDigest | nil) | ||
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,33 @@ | ||
require 'datadog/tracing/distributed' | ||
|
||
RSpec.describe Datadog::Tracing::Distributed do | ||
context 'integration test' do | ||
before { Datadog.configure {} } | ||
|
||
describe '#inject' do | ||
subject(:inject) { described_class.inject(digest, data) } | ||
let(:trace_id) { Datadog::Tracing::Utils::TraceId.next_id } | ||
let(:span_id) { Datadog::Tracing::Utils.next_id } | ||
let(:digest) do | ||
Datadog::Tracing::TraceDigest.new(trace_id: trace_id, span_id: span_id) | ||
end | ||
let(:data) { {} } | ||
|
||
it 'injects distributed headers' do | ||
inject | ||
expect(data).to include('x-datadog-trace-id') | ||
expect(data).to include('x-datadog-parent-id') | ||
end | ||
end | ||
|
||
describe '#extract' do | ||
subject(:extract) { described_class.extract(data) } | ||
|
||
let(:data) { { 'x-datadog-trace-id' => '1', 'x-datadog-parent-id' => '2' } } | ||
|
||
it 'extracts distributed headers' do | ||
is_expected.to be_a_kind_of(Datadog::Tracing::TraceDigest) | ||
end | ||
end | ||
end | ||
end |