diff --git a/include/datadog/tracer.h b/include/datadog/tracer.h index 1e3e6650..659f1d3f 100644 --- a/include/datadog/tracer.h +++ b/include/datadog/tracer.h @@ -18,6 +18,7 @@ #include "id_generator.h" #include "optional.h" #include "span.h" +#include "extraction_util.h" #include "tracer_config.h" #include "tracer_signature.h" @@ -61,6 +62,9 @@ class Tracer { Span create_span(); Span create_span(const SpanConfig& config); + // ... + Expected extract_headers(const DictReader& reader, std::unique_ptr span_data); + // Return a span whose parent and other context is parsed from the specified // `reader`, and whose attributes are determined by the optionally specified // `config`. If there is no tracing information in `reader`, then return an @@ -69,6 +73,9 @@ class Tracer { Expected extract_span(const DictReader& reader); Expected extract_span(const DictReader& reader, const SpanConfig& config); + Expected extract_span(ExtractedData& merged_context, + const SpanConfig& config, + std::unique_ptr span_data); // Return a span extracted from the specified `reader` (see `extract_span`). // If there is no span to extract, then return a span that is the root of a diff --git a/src/datadog/tracer.cpp b/src/datadog/tracer.cpp index 321ce308..4a8029df 100644 --- a/src/datadog/tracer.cpp +++ b/src/datadog/tracer.cpp @@ -16,7 +16,6 @@ #include "config_manager.h" #include "datadog_agent.h" #include "extracted_data.h" -#include "extraction_util.h" #include "hex.h" #include "json.hpp" #include "platform_util.h" @@ -143,17 +142,9 @@ Span Tracer::create_span(const SpanConfig& config) { return span; } -Expected Tracer::extract_span(const DictReader& reader) { - return extract_span(reader, SpanConfig{}); -} - -Expected Tracer::extract_span(const DictReader& reader, - const SpanConfig& config) { +Expected Tracer::extract_headers(const DictReader& reader, std::unique_ptr span_data) { assert(!extraction_styles_.empty()); - AuditedReader audited_reader{reader}; - - auto span_data = std::make_unique(); Optional first_style_with_trace_id; Optional first_style_with_parent_id; std::unordered_map extracted_contexts; @@ -272,6 +263,26 @@ Expected Tracer::extract_span(const DictReader& reader, merged_context.headers_examined)); } + return std::move(merged_context); +} + +Expected Tracer::extract_span(const DictReader& reader) { + return extract_span(reader, SpanConfig{}); +} + +Expected Tracer::extract_span(const DictReader& reader, + const SpanConfig& config) { + auto span_data = std::make_unique(); + auto merged_context = extract_headers(reader, std::move(span_data)); + if (auto* error = merged_context.if_error()) { + return *error; + } + return extract_span(*merged_context, config, std::move(span_data)); +} + +Expected Tracer::extract_span(ExtractedData& merged_context, + const SpanConfig& config, + std::unique_ptr span_data) { // We're done extracting fields. Now create the span. // This is similar to what we do in `create_span`. span_data->apply_config(*config_manager_->span_defaults(), config, clock_);