Skip to content

Commit 95d5a01

Browse files
committed
overall improvements
1 parent 7a3a6c5 commit 95d5a01

27 files changed

+781
-383
lines changed

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/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:

include/datadog/tracer_config.h

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -169,8 +169,15 @@ struct TracerConfig {
169169
/// separate thread.
170170
std::shared_ptr<EventScheduler> event_scheduler;
171171

172-
/// TBD
173-
Optional<bool> apm_tracing_enabled;
172+
/// `tracing_enabled` indicates whether APM traces and APM trace metrics
173+
/// are enabled. If `false`, APM-specific traces are and metrics are dropped
174+
/// This allows other products to operate independently (for example, AppSec).
175+
/// This is distinct from `report_traces`, which controls whether any traces
176+
/// are sent at all.
177+
///
178+
/// Overridden by the `DD_APM_TRACING_ENABLED` environment variable. Defaults
179+
/// to `true`.
180+
Optional<bool> tracing_enabled;
174181
};
175182

176183
// `FinalizedTracerConfig` contains `Tracer` implementation details derived from
@@ -210,7 +217,7 @@ class FinalizedTracerConfig final {
210217
HTTPClient::URL agent_url;
211218
std::shared_ptr<EventScheduler> event_scheduler;
212219
std::shared_ptr<HTTPClient> http_client;
213-
bool apm_tracing_enabled;
220+
bool tracing_enabled;
214221
};
215222

216223
// Return a `FinalizedTracerConfig` from the specified `config` and from any

src/datadog/datadog_agent.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,9 @@ DatadogAgent::DatadogAgent(
167167
tracer_signature.library_language_version);
168168
headers_.emplace("Datadog-Meta-Tracer-Version",
169169
tracer_signature.library_version);
170+
if (config.stats_computation_enabled) {
171+
headers_.emplace("Datadog-Client-Computed-Stats", "yes");
172+
}
170173

171174
// Origin Detection headers are not necessary when Unix Domain Socket (UDS)
172175
// is used to communicate with the Datadog Agent.

0 commit comments

Comments
 (0)