Skip to content

Commit 475ab08

Browse files
elsaelsakeirouz
authored andcommitted
wip(fixup): add ifdef linux
* include/datadog/tracer.h * include/datadog/tracer_signature.h * src/datadog/tracer.cpp
1 parent bd137be commit 475ab08

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 {
@@ -111,7 +115,9 @@ class Tracer {
111115
std::string config() const;
112116

113117
private:
118+
#ifdef __linux__
114119
void correlate(const Span& span);
120+
#endif
115121
void store_config();
116122
};
117123

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
@@ -13,7 +13,9 @@
1313

1414
#include <algorithm>
1515
#include <cassert>
16+
#ifdef __linux__
1617
#include <memory>
18+
#endif
1719

1820
#include "config_manager.h"
1921
#include "datadog_agent.h"
@@ -30,11 +32,13 @@
3032
#include "trace_sampler.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 {
@@ -101,10 +105,12 @@ Tracer::Tracer(const FinalizedTracerConfig& config,
101105
}
102106
}
103107

108+
#ifdef __linux__
104109
// TODO: change the way this is done to handle programs that fork.
105110
// TODO: add a flag to disable this by default.
106111
elastic_apm_profiling_correlation_process_storage_v1 =
107112
*signature_.generate_process_correlation_storage();
113+
#endif
108114

109115
if (config.log_on_startup) {
110116
logger_->log_startup([configuration = this->config()](std::ostream& log) {
@@ -115,6 +121,7 @@ Tracer::Tracer(const FinalizedTracerConfig& config,
115121
store_config();
116122
}
117123

124+
#ifdef __linux__
118125
void Tracer::correlate(const Span& span) {
119126
tls_info_holder = std::make_unique<datadog::tracing::TLSStorage>();
120127
elastic_apm_profiling_correlation_tls_v1 = tls_info_holder.get();
@@ -137,6 +144,7 @@ void Tracer::correlate(const Span& span) {
137144

138145
tls_data->valid = 1;
139146
}
147+
#endif
140148

141149
std::string Tracer::config() const {
142150
// clang-format off
@@ -228,7 +236,9 @@ Span Tracer::create_span(const SpanConfig& config) {
228236
Span span{span_data_ptr, segment,
229237
[generator = generator_]() { return generator->span_id(); },
230238
clock_};
239+
#ifdef __linux__
231240
correlate(span);
241+
#endif
232242
return span;
233243
}
234244

@@ -431,7 +441,9 @@ Expected<Span> Tracer::extract_span(const DictReader& reader,
431441
Span span{span_data_ptr, segment,
432442
[generator = generator_]() { return generator->span_id(); },
433443
clock_};
444+
#ifdef __linux__
434445
correlate(span);
446+
#endif
435447
return span;
436448
}
437449

0 commit comments

Comments
 (0)