Skip to content

Commit bf584d2

Browse files
dmehalacataphract
andauthored
feat: support disablement of APM Tracing (the product) (#224)
Co-authored-by: Gustavo Lopes <[email protected]>
1 parent b44a8a3 commit bf584d2

33 files changed

+948
-129
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/config.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ enum class ConfigName : char {
2727
SPAN_SAMPLING_RULES,
2828
TRACE_BAGGAGE_MAX_BYTES,
2929
TRACE_BAGGAGE_MAX_ITEMS,
30+
APM_TRACING_ENABLED,
3031
};
3132

3233
// Represents metadata for configuration parameters

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/environment.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ namespace environment {
6060
MACRO(DD_INSTRUMENTATION_INSTALL_ID) \
6161
MACRO(DD_INSTRUMENTATION_INSTALL_TYPE) \
6262
MACRO(DD_INSTRUMENTATION_INSTALL_TIME) \
63+
MACRO(DD_APM_TRACING_ENABLED) \
6364
MACRO(DD_EXTERNAL_ENV)
6465

6566
#define WITH_COMMA(ARG) ARG,

include/datadog/sampling_mechanism.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ enum class SamplingMechanism {
4949
// The sampling decision was made explicitly by the user, who set a sampling
5050
// priority.
5151
MANUAL = 4,
52-
// Reserved for future use.
52+
// Trace was kept because of AppSec event.
5353
APP_SEC = 5,
5454
// Reserved for future use.
5555
REMOTE_RATE_USER_DEFINED = 6,

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_`.

0 commit comments

Comments
 (0)