Skip to content

Commit 749f18b

Browse files
committed
Rename the new injection option
1 parent 025aafe commit 749f18b

File tree

3 files changed

+23
-13
lines changed

3 files changed

+23
-13
lines changed

include/datadog/injection_options.h

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,18 @@
44
// parameters to `Span::inject` that alter the behavior of trace context
55
// propagation.
66

7+
#include <array>
8+
9+
#include "optional.h"
10+
711
namespace datadog {
812
namespace tracing {
913

1014
struct InjectionOptions {
11-
bool has_appsec_matches{};
15+
// If DD_APM_TRACING_ENABLED=false and what we're injecting is not an APM
16+
// trace, then the code for the trace source (e.g. 02 for Appsec) can be
17+
// set here.
18+
Optional<std::array<char, 2>> trace_source{};
1219
};
1320

1421
} // namespace tracing

src/datadog/trace_segment.cpp

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -350,8 +350,11 @@ bool TraceSegment::inject(DictWriter& writer, const SpanData& span,
350350
return false;
351351
}
352352

353-
if (inj_opts.has_appsec_matches) {
354-
trace_tags_.emplace_back(tags::internal::trace_source, "02");
353+
if (inj_opts.trace_source) {
354+
std::string trace_source = std::string(inj_opts.trace_source->begin(),
355+
inj_opts.trace_source->end());
356+
trace_tags_.emplace_back(tags::internal::trace_source,
357+
std::move(trace_source));
355358
}
356359

357360
// The sampling priority can change (it can be overridden on another thread),

test/test_span.cpp

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -861,7 +861,7 @@ TEST_CASE("128-bit trace ID injection") {
861861
REQUIRE(found->second == "deadbeefdeadbeefcafebabecafebabe");
862862
}
863863

864-
TEST_CASE("injection with has_appsec_matches option") {
864+
TEST_CASE("injection with trace_source option") {
865865
TracerConfig config;
866866
config.service = "testsvc";
867867
config.collector = std::make_shared<MockCollector>();
@@ -872,16 +872,16 @@ TEST_CASE("injection with has_appsec_matches option") {
872872
REQUIRE(finalized_config);
873873
Tracer tracer{*finalized_config};
874874

875-
SECTION("has_appsec_matches = false (default)") {
875+
SECTION("trace_source is not set (default)") {
876876
auto span = tracer.create_span();
877877
InjectionOptions options;
878-
options.has_appsec_matches = false;
878+
options.trace_source = std::nullopt;
879879

880880
MockDictWriter writer;
881881
span.inject(writer, options);
882882

883883
const auto& headers = writer.items;
884-
// When has_appsec_matches is false, there should be no x-datadog-tags
884+
// When there is no trace source, there should be no x-datadog-tags
885885
// header or if there is one, it should not contain _dd.p.ts
886886
if (headers.count("x-datadog-tags") > 0) {
887887
const auto decoded_tags = decode_tags(headers.at("x-datadog-tags"));
@@ -893,10 +893,10 @@ TEST_CASE("injection with has_appsec_matches option") {
893893
}
894894
}
895895

896-
SECTION("has_appsec_matches = true") {
896+
SECTION("trace_source is 02 (appsec)") {
897897
auto span = tracer.create_span();
898898
InjectionOptions options;
899-
options.has_appsec_matches = true;
899+
options.trace_source = {'0', '2'};
900900

901901
MockDictWriter writer;
902902
span.inject(writer, options);
@@ -918,7 +918,7 @@ TEST_CASE("injection with has_appsec_matches option") {
918918
REQUIRE(found_trace_source);
919919
}
920920

921-
SECTION("has_appsec_matches with existing trace tags") {
921+
SECTION("trace source is 02 (appsec) with existing trace tags") {
922922
// Extract a span with existing trace tags
923923
const std::unordered_map<std::string, std::string> headers{
924924
{"x-datadog-trace-id", "123"},
@@ -930,7 +930,7 @@ TEST_CASE("injection with has_appsec_matches option") {
930930
REQUIRE(span);
931931

932932
InjectionOptions options;
933-
options.has_appsec_matches = true;
933+
options.trace_source = {'0', '2'};
934934

935935
MockDictWriter writer;
936936
span->inject(writer, options);
@@ -961,7 +961,7 @@ TEST_CASE("injection with has_appsec_matches option") {
961961
REQUIRE(found_another);
962962
}
963963

964-
SECTION("has_appsec_matches with APM tracing disabled") {
964+
SECTION("trace_source with APM tracing disabled") {
965965
// Test the scenario where APM tracing is disabled
966966
TracerConfig apm_disabled_config;
967967
apm_disabled_config.service = "testsvc";
@@ -983,7 +983,7 @@ TEST_CASE("injection with has_appsec_matches option") {
983983
span.trace_segment().override_sampling_priority(1);
984984

985985
InjectionOptions options;
986-
options.has_appsec_matches = true;
986+
options.trace_source = {'0', '2'};
987987

988988
MockDictWriter writer;
989989
span.inject(writer, options);

0 commit comments

Comments
 (0)