|
12 | 12 |
|
13 | 13 | #include <algorithm> |
14 | 14 | #include <cassert> |
| 15 | +#include <memory> |
15 | 16 |
|
16 | 17 | #include "config_manager.h" |
17 | 18 | #include "datadog_agent.h" |
|
30 | 31 | #include "w3c_propagation.h" |
31 | 32 |
|
32 | 33 | const void* elastic_apm_profiling_correlation_process_storage_v1 = nullptr; |
33 | | -thread_local void* elastic_apm_profiling_correlation_tls_v1 = nullptr; |
| 34 | +thread_local struct datadog::tracing::TLSStorage* |
| 35 | + elastic_apm_profiling_correlation_tls_v1 = nullptr; |
34 | 36 |
|
35 | 37 | namespace datadog { |
36 | 38 | namespace tracing { |
@@ -115,11 +117,25 @@ Tracer::Tracer(const FinalizedTracerConfig& config, |
115 | 117 | store_config(); |
116 | 118 | } |
117 | 119 |
|
118 | | -void Tracer::correlate(const Span&) { |
| 120 | +void Tracer::correlate(const Span& span) { |
119 | 121 | // TODO: update this variablle with data |
120 | 122 | // See Layout: |
121 | 123 | // https://github.com/elastic/apm/blob/149cd3e39a77a58002344270ed2ad35357bdd02d/specs/agents/universal-profiling-integration.md#thread-local-storage-layout |
122 | | - elastic_apm_profiling_correlation_tls_v1 = (char*)"randomdata\n"; |
| 124 | + auto tls_storage_ptr = std::make_unique<struct TLSStorage>(); |
| 125 | + elastic_apm_profiling_correlation_tls_v1 = tls_storage_ptr.get(); |
| 126 | + struct TLSStorage* tls_data = elastic_apm_profiling_correlation_tls_v1; |
| 127 | + tls_data->valid = 0; |
| 128 | + |
| 129 | + tls_data->layout_minor_version = 1; |
| 130 | + tls_data->trace_present = 1; // We are in a span so no errors |
| 131 | + tls_data->trace_flags = 0; // IDK |
| 132 | + auto trace_id = span.trace_id(); |
| 133 | + tls_data->trace_id_low = trace_id.low; |
| 134 | + tls_data->trace_id_high = trace_id.high; |
| 135 | + tls_data->span_id = span.id(); |
| 136 | + tls_data->transaction_id = span.trace_segment().local_root_id(); |
| 137 | + |
| 138 | + tls_data->valid = 1; |
123 | 139 | } |
124 | 140 |
|
125 | 141 | std::string Tracer::config() const { |
|
0 commit comments