-
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 #1591 from DataDog/ivoanjo/extract-trace-to-profil…
…e-refactor Refactor reading of trace identifiers in profiler
- Loading branch information
Showing
12 changed files
with
274 additions
and
115 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
# frozen_string_literal: true | ||
|
||
module Datadog | ||
module Profiling | ||
module TraceIdentifiers | ||
# Used by Datadog::Profiling::TraceIdentifiers::Helper to get the trace identifiers (trace id and span id) for a | ||
# given thread, if there is an active trace for that thread in Datadog.tracer. | ||
class Ddtrace | ||
def initialize(tracer: nil) | ||
@tracer = (tracer if tracer.respond_to?(:active_correlation)) | ||
end | ||
|
||
def trace_identifiers_for(thread) | ||
return unless @tracer | ||
|
||
correlation = @tracer.active_correlation(thread) | ||
trace_id = correlation.trace_id | ||
span_id = correlation.span_id | ||
|
||
[trace_id, span_id] if trace_id && trace_id != 0 && span_id && span_id != 0 | ||
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,34 @@ | ||
# frozen_string_literal: true | ||
|
||
require 'ddtrace/profiling/trace_identifiers/ddtrace' | ||
|
||
module Datadog | ||
module Profiling | ||
module TraceIdentifiers | ||
# Helper used to retrieve the trace identifiers (trace id and span id) for a given thread, | ||
# if there is an active trace for that thread for the supported tracing APIs. | ||
# | ||
# This data is used to connect profiles to the traces -- samples in a profile will be tagged with this data and | ||
# the profile can be filtered down to look at only the samples for a given trace. | ||
class Helper | ||
DEFAULT_SUPPORTED_APIS = [ | ||
::Datadog::Profiling::TraceIdentifiers::Ddtrace | ||
].freeze | ||
private_constant :DEFAULT_SUPPORTED_APIS | ||
|
||
def initialize(tracer:, supported_apis: DEFAULT_SUPPORTED_APIS.map { |api| api.new(tracer: tracer) }) | ||
@supported_apis = supported_apis | ||
end | ||
|
||
def trace_identifiers_for(thread) | ||
@supported_apis.each do |api| | ||
trace_identifiers = api.trace_identifiers_for(thread) | ||
return trace_identifiers unless trace_identifiers.nil? | ||
end | ||
|
||
nil | ||
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
Oops, something went wrong.