-
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.
Merge pull request #660 from DataDog/feature/add_correlation_identifier
Add correlation identifier
- Loading branch information
Showing
5 changed files
with
127 additions
and
0 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,17 @@ | ||
module Datadog | ||
# Contains behavior for managing correlations with tracing | ||
# e.g. Retrieve a correlation to the current trace for logging, etc. | ||
module Correlation | ||
# Struct representing correlation | ||
Identifier = Struct.new(:trace_id, :span_id) | ||
NULL_IDENTIFIER = Identifier.new.freeze | ||
|
||
module_function | ||
|
||
# Produces a CorrelationIdentifier from the Context provided | ||
def identifier_from_context(context) | ||
return NULL_IDENTIFIER if context.nil? | ||
Identifier.new(context.trace_id, context.span_id).freeze | ||
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,39 @@ | ||
require 'spec_helper' | ||
|
||
require 'ddtrace/correlation' | ||
require 'ddtrace/context' | ||
|
||
RSpec.describe Datadog::Correlation do | ||
describe '::identifier_from_context' do | ||
subject(:correlation_ids) { described_class.identifier_from_context(context) } | ||
|
||
context 'given nil' do | ||
let(:context) { nil } | ||
|
||
it 'returns an empty Correlation::Identifier' do | ||
is_expected.to be_a_kind_of(Datadog::Correlation::Identifier) | ||
expect(correlation_ids.trace_id).to be nil | ||
expect(correlation_ids.span_id).to be nil | ||
end | ||
end | ||
|
||
context 'given a Context object' do | ||
let(:context) do | ||
instance_double( | ||
Datadog::Context, | ||
trace_id: trace_id, | ||
span_id: span_id | ||
) | ||
end | ||
|
||
let(:trace_id) { double('trace id') } | ||
let(:span_id) { double('span id') } | ||
|
||
it 'returns a Correlation::Identifier matching the Context' do | ||
is_expected.to be_a_kind_of(Datadog::Correlation::Identifier) | ||
expect(correlation_ids.trace_id).to eq(trace_id) | ||
expect(correlation_ids.span_id).to eq(span_id) | ||
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