diff --git a/include/datadog/telemetry/configuration.h b/include/datadog/telemetry/configuration.h index 50e829b6..1559be6b 100644 --- a/include/datadog/telemetry/configuration.h +++ b/include/datadog/telemetry/configuration.h @@ -9,19 +9,23 @@ namespace datadog::telemetry { struct Configuration { - // Turn on or off telemetry module - // Enabled by default. - // Overwritten by `DD_INSTRUMENTATION_TELEMETRY_ENABLED` env var. + // Enable or disable the telemetry module. + // Default: enabled. + // Can be overriden by the `DD_INSTRUMENTATION_TELEMETRY_ENABLED` environment + // variable. tracing::Optional enabled; - // Turn on or off metrics reporting - // Overwritten by `DD_TELEMETRY_METRICS_ENABLED` env var. + // Enable or disable telemetry metrics. + // Default: enabled. + // Can be overriden by the `DD_TELEMETRY_METRICS_ENABLED` environment + // variable. tracing::Optional report_metrics; - // Interval of metrics payload - // Overwritten by `DD_TELEMETRY_METRICS_INTERVAL_SECONDS` env var. - tracing::Optional metrics_interval_seconds; - // Interval of heartbeat payload - // Overwritten by `DD_TELEMETRY_HEARTBEAT_INTERVAL` env var. - tracing::Optional heartbeat_interval_seconds; + // Interval at which the metrics payload will be sent. + // Can be overriden by `DD_TELEMETRY_METRICS_INTERVAL_SECONDS` environment + // variable. + tracing::Optional metrics_interval_seconds; + // Interval at which the heartbeat payload will be sent. + // Can be overriden by `DD_TELEMETRY_HEARTBEAT_INTERVAL` environment variable. + tracing::Optional heartbeat_interval_seconds; // `integration_name` is the name of the product integrating this library. // Example: "nginx", "envoy" or "istio". tracing::Optional integration_name; diff --git a/src/datadog/telemetry/configuration.cpp b/src/datadog/telemetry/configuration.cpp index d4c9c568..cd71fa30 100644 --- a/src/datadog/telemetry/configuration.cpp +++ b/src/datadog/telemetry/configuration.cpp @@ -1,6 +1,7 @@ #include #include #include +#include #include "parse_util.h" @@ -25,7 +26,7 @@ tracing::Expected load_telemetry_env_config() { if (auto metrics_interval_seconds = lookup(environment::DD_TELEMETRY_METRICS_INTERVAL_SECONDS)) { - auto maybe_value = parse_uint64(*metrics_interval_seconds, 10); + auto maybe_value = parse_double(*metrics_interval_seconds); if (auto error = maybe_value.if_error()) { return *error; } @@ -34,7 +35,7 @@ tracing::Expected load_telemetry_env_config() { if (auto heartbeat_interval_seconds = lookup(environment::DD_TELEMETRY_HEARTBEAT_INTERVAL)) { - auto maybe_value = parse_uint64(*heartbeat_interval_seconds, 10); + auto maybe_value = parse_double(*heartbeat_interval_seconds); if (auto error = maybe_value.if_error()) { return *error; } @@ -81,30 +82,35 @@ tracing::Expected finalize_config( // metrics_interval_seconds auto metrics_interval = pick(env_config->metrics_interval_seconds, user_config.metrics_interval_seconds, 60); - if (metrics_interval.second <= 0) { - // TBD - return Error{}; + if (metrics_interval.second <= 0.) { + return Error{Error::Code::OUT_OF_RANGE_INTEGER, + "Telemetry metrics polling interval must be a positive value"}; } - result.metrics_interval = std::chrono::seconds(metrics_interval.second); + result.metrics_interval = + std::chrono::duration_cast( + std::chrono::duration(metrics_interval.second)); // heartbeat_interval_seconds auto heartbeat_interval = pick(env_config->heartbeat_interval_seconds, user_config.heartbeat_interval_seconds, 10); - if (heartbeat_interval.second <= 0) { - // TBD - return Error{}; + if (heartbeat_interval.second <= 0.) { + return Error{ + Error::Code::OUT_OF_RANGE_INTEGER, + "Telemetry heartbeat polling interval must be a positive value"}; } - result.heartbeat_interval = std::chrono::seconds(heartbeat_interval.second); + result.heartbeat_interval = + std::chrono::duration_cast( + std::chrono::duration(heartbeat_interval.second)); // integration_name std::tie(origin, result.integration_name) = pick(env_config->integration_name, user_config.integration_name, - std::string("")); + std::string("datadog")); // integration_version std::tie(origin, result.integration_version) = pick(env_config->integration_version, user_config.integration_version, - std::string("")); + tracing::tracer_version); return result; } diff --git a/src/datadog/tracer_config.cpp b/src/datadog/tracer_config.cpp index 73aaeff2..be29d2dd 100644 --- a/src/datadog/tracer_config.cpp +++ b/src/datadog/tracer_config.cpp @@ -351,10 +351,11 @@ Expected finalize_config(const TracerConfig &user_config, to_string(final_config.delegate_trace_sampling), origin); // Integration name & version - final_config.integration_name = - value_or(env_config->integration_name, user_config.integration_name, ""); - final_config.integration_version = value_or( - env_config->integration_version, user_config.integration_version, ""); + final_config.integration_name = value_or( + env_config->integration_name, user_config.integration_name, "datadog"); + final_config.integration_version = + value_or(env_config->integration_version, user_config.integration_version, + tracer_version); if (user_config.runtime_id) { final_config.runtime_id = user_config.runtime_id; diff --git a/src/datadog/tracer_telemetry.cpp b/src/datadog/tracer_telemetry.cpp index c7484bea..22066943 100644 --- a/src/datadog/tracer_telemetry.cpp +++ b/src/datadog/tracer_telemetry.cpp @@ -67,9 +67,6 @@ TracerTelemetry::TracerTelemetry( integration_version_(integration_version), user_metrics_(user_metrics) { if (enabled_) { - if (integration_name_.empty()) { - integration_name_ = "datadog"; - } // Register all the metrics that we're tracking by adding them to the // metrics_snapshots_ container. This allows for simpler iteration logic // when using the values in `generate-metrics` messages. diff --git a/test/test_tracer_telemetry.cpp b/test/test_tracer_telemetry.cpp index 87bba73b..6b983fac 100644 --- a/test/test_tracer_telemetry.cpp +++ b/test/test_tracer_telemetry.cpp @@ -54,7 +54,7 @@ TEST_CASE("Tracer telemetry", "[telemetry]") { auto app_started = nlohmann::json::parse(app_started_message); REQUIRE(is_valid_telemetry_payload(app_started) == true); REQUIRE(app_started["request_type"] == "message-batch"); - REQUIRE(app_started["payload"].size() == 2); + REQUIRE(app_started["payload"].size() == 1); auto& app_started_payload = app_started["payload"][0]; CHECK(app_started_payload["request_type"] == "app-started"); @@ -89,7 +89,7 @@ TEST_CASE("Tracer telemetry", "[telemetry]") { REQUIRE(is_valid_telemetry_payload(app_started) == true); REQUIRE(app_started["request_type"] == "message-batch"); REQUIRE(app_started["payload"].is_array()); - REQUIRE(app_started["payload"].size() == 2); + REQUIRE(app_started["payload"].size() == 1); auto& app_started_payload = app_started["payload"][0]; CHECK(app_started_payload["request_type"] == "app-started");