Skip to content

Commit 0005e65

Browse files
committed
Refactor runtime_id into span defaults, available to tracer telemetry
1 parent 9e432cb commit 0005e65

File tree

4 files changed

+8
-9
lines changed

4 files changed

+8
-9
lines changed

src/datadog/span_defaults.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ nlohmann::json to_json(const SpanDefaults& defaults) {
2222
TO_JSON(version);
2323
TO_JSON(name);
2424
TO_JSON(tags);
25+
TO_JSON(runtime_id);
2526
#undef TO_JSON
2627
return result;
2728
}

src/datadog/span_defaults.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
#include <unordered_map>
99

1010
#include "json_fwd.hpp"
11+
#include "random.h"
1112

1213
namespace datadog {
1314
namespace tracing {
@@ -19,6 +20,7 @@ struct SpanDefaults {
1920
std::string version = "";
2021
std::string name = "";
2122
std::unordered_map<std::string, std::string> tags;
23+
std::string runtime_id = uuid();
2224
};
2325

2426
nlohmann::json to_json(const SpanDefaults&);

src/datadog/trace_segment.cpp

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
#include "platform_util.h"
1717
#include "random.h"
1818
#include "span_data.h"
19+
#include "span_defaults.h"
1920
#include "span_sampler.h"
2021
#include "tag_propagation.h"
2122
#include "tags.h"
@@ -28,12 +29,8 @@ namespace {
2829

2930
struct Cache {
3031
static int process_id;
31-
static std::string runtime_id;
3232

33-
static void recalculate_values() {
34-
process_id = get_process_id();
35-
runtime_id = uuid();
36-
}
33+
static void recalculate_values() { process_id = get_process_id(); }
3734

3835
Cache() {
3936
recalculate_values();
@@ -42,7 +39,6 @@ struct Cache {
4239
};
4340

4441
int Cache::process_id;
45-
std::string Cache::runtime_id;
4642

4743
// `cache_singleton` exists solely to invoke `Cache`'s constructor.
4844
// All data members are static, so use e.g. `Cache::process_id` instead of
@@ -218,7 +214,7 @@ void TraceSegment::span_finished() {
218214
}
219215
span.numeric_tags[tags::internal::process_id] = Cache::process_id;
220216
span.tags[tags::internal::language] = "cpp";
221-
span.tags[tags::internal::runtime_id] = Cache::runtime_id;
217+
span.tags[tags::internal::runtime_id] = defaults_->runtime_id;
222218
}
223219

224220
const auto result = collector_->send(std::move(spans_), trace_sampler_);

src/datadog/tracer_telemetry.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ std::string TracerTelemetry::app_started(nlohmann::json&& tracer_config) {
5959
{"seq_id", seq_id},
6060
{"request_type", "app-started"},
6161
{"tracer_time", tracer_time},
62-
{"runtime_id", "0524398a-11e2-4375-a637-619eb9148e8f"},
62+
{"runtime_id", span_defaults_->runtime_id},
6363
{"debug", true},
6464
{"application",
6565
nlohmann::json::object({
@@ -149,7 +149,7 @@ std::string TracerTelemetry::heartbeat_and_telemetry() {
149149
{"seq_id", seq_id},
150150
{"request_type", "message-batch"},
151151
{"tracer_time", tracer_time},
152-
{"runtime_id", "0524398a-11e2-4375-a637-619eb9148e8f"},
152+
{"runtime_id", span_defaults_->runtime_id},
153153
{"debug", true},
154154
{"application",
155155
nlohmann::json::object({

0 commit comments

Comments
 (0)