Skip to content

Commit 2b1e5a8

Browse files
committed
overall improvements
1 parent 7a3a6c5 commit 2b1e5a8

30 files changed

+819
-382
lines changed

BUILD.bazel

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ cc_library(
4242
"src/datadog/string_util.cpp",
4343
"src/datadog/tag_propagation.cpp",
4444
"src/datadog/tags.cpp",
45+
"src/datadog/trace_source.cpp",
4546
"src/datadog/telemetry_metrics.cpp",
4647
"src/datadog/threaded_event_scheduler.cpp",
4748
"src/datadog/tracer_config.cpp",
@@ -117,6 +118,7 @@ cc_library(
117118
"include/datadog/tracer_config.h",
118119
"include/datadog/tracer_signature.h",
119120
"include/datadog/trace_id.h",
121+
"include/datadog/trace_source.h",
120122
"include/datadog/trace_sampler_config.h",
121123
"include/datadog/trace_segment.h",
122124
"include/datadog/version.h",

CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,7 @@ target_sources(dd_trace_cpp-objects
150150
src/datadog/trace_sampler_config.cpp
151151
src/datadog/trace_sampler.cpp
152152
src/datadog/trace_segment.cpp
153+
src/datadog/trace_source.cpp
153154
src/datadog/telemetry_metrics.cpp
154155
src/datadog/version.cpp
155156
src/datadog/w3c_propagation.cpp

include/datadog/datadog_agent_config.h

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@
2222
#include "expected.h"
2323
#include "http_client.h"
2424
#include "remote_config/listener.h"
25-
#include "string_view.h"
2625

2726
namespace datadog {
2827
namespace tracing {
@@ -90,6 +89,11 @@ class FinalizedDatadogAgentConfig {
9089

9190
// Origin detection
9291
Optional<std::string> admission_controller_uid;
92+
93+
// Indicate if stats computation should be delegated to the Agent.
94+
// This feature is not supported yet, however, we need to inform the Agent to
95+
// not compute stats when APM Tracing `DD_APM_TRACING_ENABLED` is disabled.
96+
bool stats_computation_enabled;
9397
};
9498

9599
Expected<FinalizedDatadogAgentConfig> finalize_config(

include/datadog/dict_writer.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,9 @@ class DictWriter {
2121
// implementation may, but is not required to, overwrite any previous value at
2222
// `key`.
2323
virtual void set(StringView key, StringView value) = 0;
24+
25+
// Removes the entry associated with the given key.
26+
virtual void erase(StringView){};
2427
};
2528

2629
} // namespace tracing

include/datadog/injection_options.h

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,19 +4,10 @@
44
// parameters to `Span::inject` that alter the behavior of trace context
55
// propagation.
66

7-
#include <array>
8-
9-
#include "optional.h"
10-
117
namespace datadog {
128
namespace tracing {
139

14-
struct InjectionOptions {
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{};
19-
};
10+
struct InjectionOptions {};
2011

2112
} // namespace tracing
2213
} // namespace datadog

include/datadog/span.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@
4949
#include "optional.h"
5050
#include "string_view.h"
5151
#include "trace_id.h"
52+
#include "trace_source.h"
5253

5354
namespace datadog {
5455
namespace tracing {
@@ -162,6 +163,8 @@ class Span {
162163
// Set end time of this span. Doing so will override the default behavior of
163164
// using the current time in the destructor.
164165
void set_end_time(std::chrono::steady_clock::time_point);
166+
// Specifies the product (AppSec, DBM) that created this span.
167+
void set_source(Source);
165168

166169
// Write information about this span and its trace into the specified `writer`
167170
// using all of the configured injection propagation styles.

include/datadog/trace_sampler_config.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ struct TraceSamplerRule final {
2424
Rate rate;
2525
SpanMatcher matcher;
2626
SamplingMechanism mechanism;
27+
bool bypass_limiter = false;
2728
};
2829

2930
struct TraceSamplerConfig {
@@ -50,6 +51,10 @@ class FinalizedTraceSamplerConfig {
5051
double max_per_second;
5152
std::vector<TraceSamplerRule> rules;
5253
std::unordered_map<ConfigName, ConfigMetadata> metadata;
54+
55+
public:
56+
/// Returns the trace sampler configuration when APM Tracing is disabled.
57+
static FinalizedTraceSamplerConfig apm_tracing_disabled_config();
5358
};
5459

5560
Expected<FinalizedTraceSamplerConfig> finalize_config(

include/datadog/trace_segment.h

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@
3232
#include <utility>
3333
#include <vector>
3434

35-
#include "expected.h"
3635
#include "optional.h"
3736
#include "propagation_style.h"
3837
#include "runtime_id.h"
@@ -80,6 +79,8 @@ class TraceSegment {
8079

8180
std::shared_ptr<ConfigManager> config_manager_;
8281

82+
bool tracing_enabled_;
83+
8384
public:
8485
TraceSegment(const std::shared_ptr<Logger>& logger,
8586
const std::shared_ptr<Collector>& collector,
@@ -95,7 +96,8 @@ class TraceSegment {
9596
Optional<SamplingDecision> sampling_decision,
9697
Optional<std::string> additional_w3c_tracestate,
9798
Optional<std::string> additional_datadog_w3c_tracestate,
98-
std::unique_ptr<SpanData> local_root);
99+
std::unique_ptr<SpanData> local_root,
100+
bool tracing_enabled = true);
99101

100102
const SpanDefaults& defaults() const;
101103
const Optional<std::string>& hostname() const;
@@ -118,10 +120,13 @@ class TraceSegment {
118120
void span_finished();
119121

120122
// Set the sampling decision to be a local, manual decision with the specified
121-
// sampling `priority`. Overwrite any previous sampling decision.
123+
// sampling `priority`. Overwrite any previous sampling decision.
122124
void override_sampling_priority(int priority);
123125
void override_sampling_priority(SamplingPriority priority);
124126

127+
// Retrieves the local root span.
128+
SpanData& local_root() const;
129+
125130
private:
126131
// If `sampling_decision_` is null, use `trace_sampler_` to make a
127132
// sampling decision and assign it to `sampling_decision_`.

include/datadog/trace_source.h

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
#pragma once
2+
3+
#include <datadog/string_view.h>
4+
5+
namespace datadog {
6+
namespace tracing {
7+
8+
/// Enumerates the possible trace sources that can generate a span.
9+
///
10+
/// This enum class identifies the different products that can create a span.
11+
/// Each source is represented by a distinct bit flag, allowing for bitwise
12+
/// operations.
13+
enum class Source : char {
14+
apm = 0x01,
15+
appsec = 0x02,
16+
datastream_monitoring = 0x04,
17+
datajob_monitoring = 0x08,
18+
database_monitoring = 0x10,
19+
};
20+
21+
/// Validates if a given string corresponds to a valid trace source.
22+
///
23+
/// This function checks whether the provided string matches any of the
24+
/// predefined trace sources specified in the Source enum. It is useful for
25+
/// ensuring that a source string obtained from an external input is valid
26+
/// before further processing.
27+
///
28+
/// @param source_str A string view representing the trace source to validate.
29+
///
30+
/// @return true if the source string is valid and corresponds to a known trace
31+
/// source, false otherwise.
32+
bool validate_trace_source(StringView source_str);
33+
34+
/// Converts a Source enum value to its corresponding string representation
35+
inline constexpr StringView to_tag(Source source) {
36+
switch (source) {
37+
case Source::apm:
38+
return "01";
39+
case Source::appsec:
40+
return "02";
41+
case Source::database_monitoring:
42+
return "04";
43+
case Source::datajob_monitoring:
44+
return "08";
45+
case Source::datastream_monitoring:
46+
return "10";
47+
}
48+
49+
return "";
50+
}
51+
52+
} // namespace tracing
53+
} // namespace datadog

include/datadog/tracer.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ class Tracer {
5454
Baggage::Options baggage_opts_;
5555
bool baggage_injection_enabled_;
5656
bool baggage_extraction_enabled_;
57+
bool tracing_enabled_;
5758

5859
public:
5960
// Create a tracer configured using the specified `config`, and optionally:

0 commit comments

Comments
 (0)