Skip to content

Commit 5b5beaf

Browse files
author
elsa
committed
feat: add option to enable correlation
* include/datadog/environment.h * include/datadog/tracer.h * include/datadog/tracer_config.h * src/datadog/tracer.cpp * src/datadog/tracer_config.cpp
1 parent 0347cd6 commit 5b5beaf

File tree

6 files changed

+29
-7
lines changed

6 files changed

+29
-7
lines changed

include/datadog/environment.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ namespace environment {
5050
MACRO(DD_TRACE_TAGS_PROPAGATION_MAX_LENGTH) \
5151
MACRO(DD_VERSION) \
5252
MACRO(DD_TRACE_128_BIT_TRACEID_GENERATION_ENABLED) \
53+
MACRO(DD_TRACE_CORRELATE_FULL_HOST_PROFILES) \
5354
MACRO(DD_TELEMETRY_HEARTBEAT_INTERVAL) \
5455
MACRO(DD_TELEMETRY_METRICS_ENABLED) \
5556
MACRO(DD_TELEMETRY_METRICS_INTERVAL_SECONDS) \

include/datadog/tracer.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ class Tracer {
6464
Baggage::Options baggage_opts_;
6565
bool baggage_injection_enabled_;
6666
bool baggage_extraction_enabled_;
67+
bool correlate_full_host_profiles_;
6768

6869
public:
6970
// Create a tracer configured using the specified `config`, and optionally:

include/datadog/tracer_config.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,14 @@ struct TracerConfig {
133133
// the `DD_TRACE_128_BIT_TRACEID_GENERATION_ENABLED` environment variable.
134134
Optional<bool> generate_128bit_trace_ids;
135135

136+
// `correlate_full_host_profiles` indicates whether we want to correlate
137+
// traces and spans with profiles generated by the eBPF full host profiler.
138+
// This correlation only works on linux, due to the eBPF-based nature of
139+
// the profiler. It implies writing some process-level and thread-level
140+
// data in variables which the profiler will then read from the process's
141+
// memory.
142+
Optional<bool> correlate_full_host_profiles;
143+
136144
// `runtime_id` denotes the current run of the application in which the tracer
137145
// is embedded. If `runtime_id` is not specified, then it defaults to a
138146
// pseudo-randomly generated value. A server that contains multiple tracers,
@@ -197,6 +205,7 @@ class FinalizedTracerConfig final {
197205
std::shared_ptr<Logger> logger;
198206
bool log_on_startup;
199207
bool generate_128bit_trace_ids;
208+
bool correlate_full_host_profiles;
200209
Optional<RuntimeID> runtime_id;
201210
Clock clock;
202211
std::string integration_name;

src/datadog/trace_segment.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -247,7 +247,8 @@ void TraceSegment::span_finished() {
247247

248248
#ifdef __linux__
249249
// When all spans are finished, so is the current trace.
250-
elastic_apm_profiling_correlation_tls_v1->trace_present = 0;
250+
if (elastic_apm_profiling_correlation_process_storage_v1 != nullptr)
251+
elastic_apm_profiling_correlation_tls_v1->trace_present = 0;
251252
#endif
252253

253254
telemetry::metrics().tracer.trace_segments_closed.inc();

src/datadog/tracer.cpp

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,8 @@ Tracer::Tracer(const FinalizedTracerConfig& config,
6868
tags_header_max_size_(config.tags_header_size),
6969
baggage_opts_(config.baggage_opts),
7070
baggage_injection_enabled_(false),
71-
baggage_extraction_enabled_(false) {
71+
baggage_extraction_enabled_(false),
72+
correlate_full_host_profiles_(config.correlate_full_host_profiles) {
7273
telemetry::init(config.telemetry, logger_, config.http_client,
7374
std::vector<std::shared_ptr<telemetry::Metric>>{},
7475
config.event_scheduler, config.agent_url);
@@ -107,9 +108,9 @@ Tracer::Tracer(const FinalizedTracerConfig& config,
107108

108109
#ifdef __linux__
109110
// TODO: change the way this is done to handle programs that fork.
110-
// TODO: add a flag to disable this by default.
111-
elastic_apm_profiling_correlation_process_storage_v1 =
112-
*signature_.generate_process_correlation_storage();
111+
if (correlate_full_host_profiles_)
112+
elastic_apm_profiling_correlation_process_storage_v1 =
113+
*signature_.generate_process_correlation_storage();
113114
#endif
114115

115116
if (config.log_on_startup) {
@@ -239,7 +240,7 @@ Span Tracer::create_span(const SpanConfig& config) {
239240
[generator = generator_]() { return generator->span_id(); },
240241
clock_};
241242
#ifdef __linux__
242-
correlate(span);
243+
if (correlate_full_host_profiles_) correlate(span);
243244
#endif
244245
return span;
245246
}
@@ -444,7 +445,7 @@ Expected<Span> Tracer::extract_span(const DictReader& reader,
444445
[generator = generator_]() { return generator->span_id(); },
445446
clock_};
446447
#ifdef __linux__
447-
correlate(span);
448+
if (correlate_full_host_profiles_) correlate(span);
448449
#endif
449450
return span;
450451
}

src/datadog/tracer_config.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,10 @@ Expected<TracerConfig> load_tracer_env_config(Logger &logger) {
127127
lookup(environment::DD_TRACE_128_BIT_TRACEID_GENERATION_ENABLED)) {
128128
env_cfg.generate_128bit_trace_ids = !falsy(*enabled_env);
129129
}
130+
if (auto enabled_env =
131+
lookup(environment::DD_TRACE_CORRELATE_FULL_HOST_PROFILES)) {
132+
env_cfg.correlate_full_host_profiles = !falsy(*enabled_env);
133+
}
130134

131135
// Baggage
132136
if (auto baggage_items_env =
@@ -361,6 +365,11 @@ Expected<FinalizedTracerConfig> finalize_config(const TracerConfig &user_config,
361365
ConfigMetadata(ConfigName::GENEREATE_128BIT_TRACE_IDS,
362366
to_string(final_config.generate_128bit_trace_ids), origin);
363367

368+
// Correlate with Full Host Profiles
369+
final_config.correlate_full_host_profiles =
370+
value_or(env_config->correlate_full_host_profiles,
371+
user_config.correlate_full_host_profiles, false);
372+
364373
// Integration name & version
365374
final_config.integration_name = value_or(
366375
env_config->integration_name, user_config.integration_name, "datadog");

0 commit comments

Comments
 (0)