Skip to content

Commit bc70e5a

Browse files
authored
fix: telemetry support for sub-seconds intervals (#168)
1 parent d49c147 commit bc70e5a

File tree

5 files changed

+40
-32
lines changed

5 files changed

+40
-32
lines changed

include/datadog/telemetry/configuration.h

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -9,19 +9,23 @@
99
namespace datadog::telemetry {
1010

1111
struct Configuration {
12-
// Turn on or off telemetry module
13-
// Enabled by default.
14-
// Overwritten by `DD_INSTRUMENTATION_TELEMETRY_ENABLED` env var.
12+
// Enable or disable the telemetry module.
13+
// Default: enabled.
14+
// Can be overriden by the `DD_INSTRUMENTATION_TELEMETRY_ENABLED` environment
15+
// variable.
1516
tracing::Optional<bool> enabled;
16-
// Turn on or off metrics reporting
17-
// Overwritten by `DD_TELEMETRY_METRICS_ENABLED` env var.
17+
// Enable or disable telemetry metrics.
18+
// Default: enabled.
19+
// Can be overriden by the `DD_TELEMETRY_METRICS_ENABLED` environment
20+
// variable.
1821
tracing::Optional<bool> report_metrics;
19-
// Interval of metrics payload
20-
// Overwritten by `DD_TELEMETRY_METRICS_INTERVAL_SECONDS` env var.
21-
tracing::Optional<int> metrics_interval_seconds;
22-
// Interval of heartbeat payload
23-
// Overwritten by `DD_TELEMETRY_HEARTBEAT_INTERVAL` env var.
24-
tracing::Optional<int> heartbeat_interval_seconds;
22+
// Interval at which the metrics payload will be sent.
23+
// Can be overriden by `DD_TELEMETRY_METRICS_INTERVAL_SECONDS` environment
24+
// variable.
25+
tracing::Optional<double> metrics_interval_seconds;
26+
// Interval at which the heartbeat payload will be sent.
27+
// Can be overriden by `DD_TELEMETRY_HEARTBEAT_INTERVAL` environment variable.
28+
tracing::Optional<double> heartbeat_interval_seconds;
2529
// `integration_name` is the name of the product integrating this library.
2630
// Example: "nginx", "envoy" or "istio".
2731
tracing::Optional<std::string> integration_name;

src/datadog/telemetry/configuration.cpp

Lines changed: 18 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
#include <datadog/config.h>
22
#include <datadog/environment.h>
33
#include <datadog/telemetry/configuration.h>
4+
#include <datadog/version.h>
45

56
#include "parse_util.h"
67

@@ -25,7 +26,7 @@ tracing::Expected<Configuration> load_telemetry_env_config() {
2526

2627
if (auto metrics_interval_seconds =
2728
lookup(environment::DD_TELEMETRY_METRICS_INTERVAL_SECONDS)) {
28-
auto maybe_value = parse_uint64(*metrics_interval_seconds, 10);
29+
auto maybe_value = parse_double(*metrics_interval_seconds);
2930
if (auto error = maybe_value.if_error()) {
3031
return *error;
3132
}
@@ -34,7 +35,7 @@ tracing::Expected<Configuration> load_telemetry_env_config() {
3435

3536
if (auto heartbeat_interval_seconds =
3637
lookup(environment::DD_TELEMETRY_HEARTBEAT_INTERVAL)) {
37-
auto maybe_value = parse_uint64(*heartbeat_interval_seconds, 10);
38+
auto maybe_value = parse_double(*heartbeat_interval_seconds);
3839
if (auto error = maybe_value.if_error()) {
3940
return *error;
4041
}
@@ -81,30 +82,35 @@ tracing::Expected<FinalizedConfiguration> finalize_config(
8182
// metrics_interval_seconds
8283
auto metrics_interval = pick(env_config->metrics_interval_seconds,
8384
user_config.metrics_interval_seconds, 60);
84-
if (metrics_interval.second <= 0) {
85-
// TBD
86-
return Error{};
85+
if (metrics_interval.second <= 0.) {
86+
return Error{Error::Code::OUT_OF_RANGE_INTEGER,
87+
"Telemetry metrics polling interval must be a positive value"};
8788
}
88-
result.metrics_interval = std::chrono::seconds(metrics_interval.second);
89+
result.metrics_interval =
90+
std::chrono::duration_cast<std::chrono::milliseconds>(
91+
std::chrono::duration<double>(metrics_interval.second));
8992

9093
// heartbeat_interval_seconds
9194
auto heartbeat_interval = pick(env_config->heartbeat_interval_seconds,
9295
user_config.heartbeat_interval_seconds, 10);
93-
if (heartbeat_interval.second <= 0) {
94-
// TBD
95-
return Error{};
96+
if (heartbeat_interval.second <= 0.) {
97+
return Error{
98+
Error::Code::OUT_OF_RANGE_INTEGER,
99+
"Telemetry heartbeat polling interval must be a positive value"};
96100
}
97-
result.heartbeat_interval = std::chrono::seconds(heartbeat_interval.second);
101+
result.heartbeat_interval =
102+
std::chrono::duration_cast<std::chrono::milliseconds>(
103+
std::chrono::duration<double>(heartbeat_interval.second));
98104

99105
// integration_name
100106
std::tie(origin, result.integration_name) =
101107
pick(env_config->integration_name, user_config.integration_name,
102-
std::string(""));
108+
std::string("datadog"));
103109

104110
// integration_version
105111
std::tie(origin, result.integration_version) =
106112
pick(env_config->integration_version, user_config.integration_version,
107-
std::string(""));
113+
tracing::tracer_version);
108114

109115
return result;
110116
}

src/datadog/tracer_config.cpp

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -351,10 +351,11 @@ Expected<FinalizedTracerConfig> finalize_config(const TracerConfig &user_config,
351351
to_string(final_config.delegate_trace_sampling), origin);
352352

353353
// Integration name & version
354-
final_config.integration_name =
355-
value_or(env_config->integration_name, user_config.integration_name, "");
356-
final_config.integration_version = value_or(
357-
env_config->integration_version, user_config.integration_version, "");
354+
final_config.integration_name = value_or(
355+
env_config->integration_name, user_config.integration_name, "datadog");
356+
final_config.integration_version =
357+
value_or(env_config->integration_version, user_config.integration_version,
358+
tracer_version);
358359

359360
if (user_config.runtime_id) {
360361
final_config.runtime_id = user_config.runtime_id;

src/datadog/tracer_telemetry.cpp

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -67,9 +67,6 @@ TracerTelemetry::TracerTelemetry(
6767
integration_version_(integration_version),
6868
user_metrics_(user_metrics) {
6969
if (enabled_) {
70-
if (integration_name_.empty()) {
71-
integration_name_ = "datadog";
72-
}
7370
// Register all the metrics that we're tracking by adding them to the
7471
// metrics_snapshots_ container. This allows for simpler iteration logic
7572
// when using the values in `generate-metrics` messages.

test/test_tracer_telemetry.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ TEST_CASE("Tracer telemetry", "[telemetry]") {
5454
auto app_started = nlohmann::json::parse(app_started_message);
5555
REQUIRE(is_valid_telemetry_payload(app_started) == true);
5656
REQUIRE(app_started["request_type"] == "message-batch");
57-
REQUIRE(app_started["payload"].size() == 2);
57+
REQUIRE(app_started["payload"].size() == 1);
5858

5959
auto& app_started_payload = app_started["payload"][0];
6060
CHECK(app_started_payload["request_type"] == "app-started");
@@ -89,7 +89,7 @@ TEST_CASE("Tracer telemetry", "[telemetry]") {
8989
REQUIRE(is_valid_telemetry_payload(app_started) == true);
9090
REQUIRE(app_started["request_type"] == "message-batch");
9191
REQUIRE(app_started["payload"].is_array());
92-
REQUIRE(app_started["payload"].size() == 2);
92+
REQUIRE(app_started["payload"].size() == 1);
9393

9494
auto& app_started_payload = app_started["payload"][0];
9595
CHECK(app_started_payload["request_type"] == "app-started");

0 commit comments

Comments
 (0)