1919// polling the Datadog Agent. See
2020// `RemoteConfigurationManager::process_response` in `remote_config.h`.
2121
22+ #ifdef __linux__
23+ #include < cstring>
24+ #include < vector>
25+ extern " C" {
26+ #include < customlabels/customlabels.h>
27+ }
28+ #endif
29+
2230#include < string>
2331
2432#include " runtime_id.h"
3139namespace datadog {
3240namespace tracing {
3341
42+ #ifdef __linux__
43+ namespace {
44+ void write_utf8_string (std::vector<uint8_t >& buffer, const std::string& str) {
45+ uint32_t length = str.length ();
46+ buffer.insert (buffer.end (), reinterpret_cast <uint8_t *>(&length),
47+ reinterpret_cast <uint8_t *>(&length) + sizeof (length));
48+ buffer.insert (buffer.end (), str.begin (), str.end ());
49+ }
50+ } // namespace
51+ #endif
52+
3453struct TracerSignature {
3554 RuntimeID runtime_id;
3655 std::string default_service;
@@ -47,6 +66,30 @@ struct TracerSignature {
4766 library_version(tracer_version),
4867 library_language(" cpp" ),
4968 library_language_version(DD_TRACE_STRINGIFY(__cplusplus), 6) {}
69+
70+ #ifdef __linux__
71+ // The process correlation storage contains information needed to
72+ // correlate traces to profiles generated by dd-otel-host-profiler.
73+ void generate_process_correlation_storage () {
74+ std::vector<uint8_t > buffer;
75+
76+ // Currently, layout minor version is 2 to differ from Elastic's
77+ // version which includes a socket path.
78+ // Layout:
79+ // https://github.com/elastic/apm/blob/149cd3e39a77a58002344270ed2ad35357bdd02d/specs/agents/universal-profiling-integration.md#process-storage-layout
80+ uint16_t layout_minor_version = 2 ;
81+ buffer.insert (buffer.end (),
82+ reinterpret_cast <uint8_t *>(&layout_minor_version),
83+ reinterpret_cast <uint8_t *>(&layout_minor_version) +
84+ sizeof (layout_minor_version));
85+
86+ write_utf8_string (buffer, default_service);
87+ write_utf8_string (buffer, default_environment);
88+ write_utf8_string (buffer, runtime_id.string ());
89+
90+ proc_storage_set (buffer.data (), buffer.size ());
91+ }
92+ #endif
5093};
5194
5295} // namespace tracing
0 commit comments