Skip to content

Commit 5bbe694

Browse files
author
elsa
committed
wip(fixup): add ifdef linux
* include/datadog/tracer.h * include/datadog/tracer_signature.h * src/datadog/tracer.cpp
1 parent 595273f commit 5bbe694

File tree

3 files changed

+28
-1
lines changed

3 files changed

+28
-1
lines changed

include/datadog/tracer.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,9 @@
1010
// obtained from a `TracerConfig` via the `finalize_config` function. See
1111
// `tracer_config.h`.
1212

13+
#ifdef __linux__
1314
#include <datadog/tls_storage.h>
15+
#endif
1416

1517
#include <cstddef>
1618
#include <memory>
@@ -25,9 +27,11 @@
2527
#include "tracer_config.h"
2628
#include "tracer_signature.h"
2729

30+
#ifdef __linux__
2831
extern const void* elastic_apm_profiling_correlation_process_storage_v1;
2932
extern thread_local struct datadog::tracing::TLSStorage*
3033
elastic_apm_profiling_correlation_tls_v1;
34+
#endif
3135

3236
namespace datadog {
3337
namespace tracing {
@@ -113,7 +117,9 @@ class Tracer {
113117
std::string config() const;
114118

115119
private:
120+
#ifdef __linux__
116121
void correlate(const Span& span);
122+
#endif
117123
void store_config();
118124
};
119125

include/datadog/tracer_signature.h

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,13 @@
1919
// polling the Datadog Agent. See
2020
// `RemoteConfigurationManager::process_response` in `remote_config.h`.
2121

22+
#ifdef __linux__
2223
#include <cstring>
2324
#include <memory>
24-
#include <string>
2525
#include <vector>
26+
#endif
27+
28+
#include <string>
2629

2730
#include "runtime_id.h"
2831
#include "string_view.h"
@@ -34,6 +37,7 @@
3437
namespace datadog {
3538
namespace tracing {
3639

40+
#ifdef __linux__
3741
namespace {
3842
void write_utf8_string(std::vector<uint8_t>& buffer, const std::string& str) {
3943
uint32_t length = str.length();
@@ -42,6 +46,7 @@ void write_utf8_string(std::vector<uint8_t>& buffer, const std::string& str) {
4246
buffer.insert(buffer.end(), str.begin(), str.end());
4347
}
4448
} // namespace
49+
#endif
4550

4651
struct TracerSignature {
4752
RuntimeID runtime_id;
@@ -60,6 +65,9 @@ struct TracerSignature {
6065
library_language("cpp"),
6166
library_language_version(DD_TRACE_STRINGIFY(__cplusplus), 6) {}
6267

68+
#ifdef __linux__
69+
// The process correlation storage contains information needed to
70+
// correlate traces to profiles generated by dd-otel-host-profiler.
6371
const std::unique_ptr<uint8_t*> generate_process_correlation_storage() {
6472
std::vector<uint8_t> buffer;
6573

@@ -81,6 +89,7 @@ struct TracerSignature {
8189
memcpy(res, buffer.data(), buffer.size());
8290
return std::make_unique<uint8_t*>(res);
8391
}
92+
#endif
8493
};
8594

8695
} // namespace tracing

src/datadog/tracer.cpp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,9 @@
1212

1313
#include <algorithm>
1414
#include <cassert>
15+
#ifdef __linux__
1516
#include <memory>
17+
#endif
1618

1719
#include "config_manager.h"
1820
#include "datadog_agent.h"
@@ -30,11 +32,13 @@
3032
#include "tracer_telemetry.h"
3133
#include "w3c_propagation.h"
3234

35+
#ifdef __linux__
3336
const void* elastic_apm_profiling_correlation_process_storage_v1 = nullptr;
3437
thread_local struct datadog::tracing::TLSStorage*
3538
elastic_apm_profiling_correlation_tls_v1 = nullptr;
3639
thread_local std::unique_ptr<datadog::tracing::TLSStorage> tls_info_holder =
3740
nullptr;
41+
#endif
3842

3943
namespace datadog {
4044
namespace tracing {
@@ -105,10 +109,12 @@ Tracer::Tracer(const FinalizedTracerConfig& config,
105109
}
106110
}
107111

112+
#ifdef __linux__
108113
// TODO: change the way this is done to handle programs that fork.
109114
// TODO: add a flag to disable this by default.
110115
elastic_apm_profiling_correlation_process_storage_v1 =
111116
*signature_.generate_process_correlation_storage();
117+
#endif
112118

113119
if (config.log_on_startup) {
114120
logger_->log_startup([configuration = this->config()](std::ostream& log) {
@@ -119,6 +125,7 @@ Tracer::Tracer(const FinalizedTracerConfig& config,
119125
store_config();
120126
}
121127

128+
#ifdef __linux__
122129
void Tracer::correlate(const Span& span) {
123130
tls_info_holder = std::make_unique<datadog::tracing::TLSStorage>();
124131
elastic_apm_profiling_correlation_tls_v1 = tls_info_holder.get();
@@ -141,6 +148,7 @@ void Tracer::correlate(const Span& span) {
141148

142149
tls_data->valid = 1;
143150
}
151+
#endif
144152

145153
std::string Tracer::config() const {
146154
// clang-format off
@@ -233,7 +241,9 @@ Span Tracer::create_span(const SpanConfig& config) {
233241
Span span{span_data_ptr, segment,
234242
[generator = generator_]() { return generator->span_id(); },
235243
clock_};
244+
#ifdef __linux__
236245
correlate(span);
246+
#endif
237247
return span;
238248
}
239249

@@ -436,7 +446,9 @@ Expected<Span> Tracer::extract_span(const DictReader& reader,
436446
Span span{span_data_ptr, segment,
437447
[generator = generator_]() { return generator->span_id(); },
438448
clock_};
449+
#ifdef __linux__
439450
correlate(span);
451+
#endif
440452
return span;
441453
}
442454

0 commit comments

Comments
 (0)