Skip to content

Commit 6063d6a

Browse files
committed
Implement DD_TRACE_ENABLED=false
1 parent a328a6d commit 6063d6a

30 files changed

+658
-38
lines changed

include/datadog/collector.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ namespace datadog {
1919
namespace tracing {
2020

2121
struct SpanData;
22-
class TraceSampler;
22+
class ErasedTraceSampler;
2323

2424
class Collector {
2525
public:
@@ -29,7 +29,7 @@ class Collector {
2929
// occurs.
3030
virtual Expected<void> send(
3131
std::vector<std::unique_ptr<SpanData>>&& spans,
32-
const std::shared_ptr<TraceSampler>& response_handler) = 0;
32+
const std::shared_ptr<ErasedTraceSampler>& response_handler) = 0;
3333

3434
// Return a JSON representation of this object's configuration. The JSON
3535
// representation is an object with the following properties:

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: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,9 @@ struct DatadogAgentConfig {
6666
// How often, in seconds, to query the Datadog Agent for remote configuration
6767
// updates.
6868
Optional<double> remote_configuration_poll_interval_seconds;
69+
// Whether APM tracing is enabled. This affects whether the
70+
// "Datadog-Client-Computed-Stats: yes" header is sent with trace requests.
71+
Optional<bool> apm_tracing_enabled;
6972
};
7073

7174
class FinalizedDatadogAgentConfig {
@@ -87,6 +90,7 @@ class FinalizedDatadogAgentConfig {
8790
std::chrono::steady_clock::duration shutdown_timeout;
8891
std::chrono::steady_clock::duration remote_configuration_poll_interval;
8992
std::unordered_map<ConfigName, ConfigMetadata> metadata;
93+
bool apm_tracing_enabled;
9094

9195
// Origin detection
9296
Optional<std::string> admission_controller_uid;

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,9 @@
77
namespace datadog {
88
namespace tracing {
99

10-
struct InjectionOptions {};
10+
struct InjectionOptions {
11+
bool has_appsec_matches{};
12+
};
1113

1214
} // namespace tracing
1315
} // namespace datadog

include/datadog/null_collector.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ namespace tracing {
1111
class NullCollector : public Collector {
1212
public:
1313
Expected<void> send(std::vector<std::unique_ptr<SpanData>>&&,
14-
const std::shared_ptr<TraceSampler>&) override {
14+
const std::shared_ptr<ErasedTraceSampler>&) override {
1515
return {};
1616
}
1717

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

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -53,15 +53,16 @@ class Logger;
5353
struct SpanData;
5454
struct SpanDefaults;
5555
class SpanSampler;
56-
class TraceSampler;
56+
class ErasedTraceSampler;
5757
class ConfigManager;
5858

5959
class TraceSegment {
6060
mutable std::mutex mutex_;
6161

6262
std::shared_ptr<Logger> logger_;
6363
std::shared_ptr<Collector> collector_;
64-
std::shared_ptr<TraceSampler> trace_sampler_;
64+
std::shared_ptr<ErasedTraceSampler> trace_sampler_;
65+
bool apm_tracing_enabled_;
6566
std::shared_ptr<SpanSampler> span_sampler_;
6667

6768
std::shared_ptr<const SpanDefaults> defaults_;
@@ -83,7 +84,8 @@ class TraceSegment {
8384
public:
8485
TraceSegment(const std::shared_ptr<Logger>& logger,
8586
const std::shared_ptr<Collector>& collector,
86-
const std::shared_ptr<TraceSampler>& trace_sampler,
87+
std::shared_ptr<ErasedTraceSampler> trace_sampler,
88+
bool apm_tracing_enabled,
8789
const std::shared_ptr<SpanSampler>& span_sampler,
8890
const std::shared_ptr<const SpanDefaults>& defaults,
8991
const std::shared_ptr<ConfigManager>& config_manager,

include/datadog/tracer.h

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ namespace tracing {
2929
class ConfigManager;
3030
class DictReader;
3131
struct SpanConfig;
32-
class TraceSampler;
32+
class ErasedTraceSampler;
3333
class SpanSampler;
3434
class IDGenerator;
3535
class InMemoryFile;
@@ -39,6 +39,8 @@ class Tracer {
3939
RuntimeID runtime_id_;
4040
TracerSignature signature_;
4141
std::shared_ptr<ConfigManager> config_manager_;
42+
std::shared_ptr<ErasedTraceSampler>
43+
apm_tracing_disabled_sampler_; // empty if enabled
4244
std::shared_ptr<Collector> collector_;
4345
std::shared_ptr<SpanSampler> span_sampler_;
4446
std::shared_ptr<const IDGenerator> generator_;
@@ -104,6 +106,10 @@ class Tracer {
104106
// same JSON object that was logged when this Tracer was created.
105107
std::string config() const;
106108

109+
bool is_apm_tracing_enabled() const {
110+
return apm_tracing_disabled_sampler_ == nullptr;
111+
}
112+
107113
private:
108114
void store_config();
109115
};

include/datadog/tracer_config.h

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ class Collector;
2828
class Logger;
2929
class SpanSampler;
3030
class TraceSampler;
31+
class ErasedTraceSampler;
3132

3233
struct TracerConfig {
3334
// Set the service name.
@@ -80,6 +81,16 @@ struct TracerConfig {
8081
// `telemetry/configuration.h` By default, the telemetry module is enabled.
8182
telemetry::Configuration telemetry;
8283

84+
// `apm_tracing_enabled` indicates whether APM traces and APM trace metrics
85+
// are enabled. If `false`, APM-specific traces are dropped and APM trace
86+
// metrics are not computed. This allows other products (e.g., AppSec) to
87+
// operate independently.
88+
// This is distinct from `report_traces`, which controls whether any traces
89+
// are sent at all.
90+
// `apm_tracing_enabled` is overridden by the `DD_APM_TRACING_ENABLED`
91+
// environment variable. Defaults to `true`.
92+
Optional<bool> apm_tracing_enabled;
93+
8394
// `trace_sampler` configures trace sampling. Trace sampling determines which
8495
// traces are sent to Datadog. See `trace_sampler_config.h`.
8596
TraceSamplerConfig trace_sampler;
@@ -197,6 +208,7 @@ class FinalizedTracerConfig final {
197208
std::shared_ptr<Logger> logger;
198209
bool log_on_startup;
199210
bool generate_128bit_trace_ids;
211+
bool apm_tracing_enabled;
200212
Optional<RuntimeID> runtime_id;
201213
Clock clock;
202214
std::string integration_name;

0 commit comments

Comments
 (0)