Skip to content

Commit

Permalink
move extract headers to its own method, this is broken
Browse files Browse the repository at this point in the history
  • Loading branch information
mabdinur committed Dec 23, 2024
1 parent 55ec27d commit 1484a48
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 10 deletions.
7 changes: 7 additions & 0 deletions include/datadog/tracer.h
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down Expand Up @@ -61,6 +62,9 @@ class Tracer {
Span create_span();
Span create_span(const SpanConfig& config);

// ...
Expected<ExtractedData> extract_headers(const DictReader& reader, std::unique_ptr<SpanData> 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
Expand All @@ -69,6 +73,9 @@ class Tracer {
Expected<Span> extract_span(const DictReader& reader);
Expected<Span> extract_span(const DictReader& reader,
const SpanConfig& config);
Expected<Span> extract_span(ExtractedData& merged_context,
const SpanConfig& config,
std::unique_ptr<SpanData> 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
Expand Down
31 changes: 21 additions & 10 deletions src/datadog/tracer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -143,17 +142,9 @@ Span Tracer::create_span(const SpanConfig& config) {
return span;
}

Expected<Span> Tracer::extract_span(const DictReader& reader) {
return extract_span(reader, SpanConfig{});
}

Expected<Span> Tracer::extract_span(const DictReader& reader,
const SpanConfig& config) {
Expected<ExtractedData> Tracer::extract_headers(const DictReader& reader, std::unique_ptr<SpanData> span_data) {
assert(!extraction_styles_.empty());

AuditedReader audited_reader{reader};

auto span_data = std::make_unique<SpanData>();
Optional<PropagationStyle> first_style_with_trace_id;
Optional<PropagationStyle> first_style_with_parent_id;
std::unordered_map<PropagationStyle, ExtractedData> extracted_contexts;
Expand Down Expand Up @@ -272,6 +263,26 @@ Expected<Span> Tracer::extract_span(const DictReader& reader,
merged_context.headers_examined));
}

return std::move(merged_context);
}

Expected<Span> Tracer::extract_span(const DictReader& reader) {
return extract_span(reader, SpanConfig{});
}

Expected<Span> Tracer::extract_span(const DictReader& reader,
const SpanConfig& config) {
auto span_data = std::make_unique<SpanData>();
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<Span> Tracer::extract_span(ExtractedData& merged_context,
const SpanConfig& config,
std::unique_ptr<SpanData> 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_);
Expand Down

0 comments on commit 1484a48

Please sign in to comment.