From cb02a992db889645b1c260cee1141d10441e70db Mon Sep 17 00:00:00 2001 From: Damien MEHALA Date: Wed, 30 Oct 2024 17:50:55 +0100 Subject: [PATCH] fix: telemetry refactoring part 1 Keep a reference to user metrics to avoid dereferencing them when they are not alive anymore. --- src/datadog/tracer_telemetry.cpp | 5 +++-- src/datadog/tracer_telemetry.h | 2 ++ 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/src/datadog/tracer_telemetry.cpp b/src/datadog/tracer_telemetry.cpp index 120ea561..01131cb8 100644 --- a/src/datadog/tracer_telemetry.cpp +++ b/src/datadog/tracer_telemetry.cpp @@ -64,7 +64,8 @@ TracerTelemetry::TracerTelemetry( host_info_(get_host_info()), tracer_signature_(tracer_signature), integration_name_(integration_name), - integration_version_(integration_version) { +integration_version_(integration_version), + user_metrics_(user_metrics_){ if (enabled_) { if (integration_name_.empty()) { integration_name_ = "datadog"; @@ -101,7 +102,7 @@ TracerTelemetry::TracerTelemetry( metrics_snapshots_.emplace_back(metrics_.trace_api.errors_status_code, MetricSnapshot{}); - for (auto& m : user_metrics) { + for (auto& m : user_metrics_) { metrics_snapshots_.emplace_back(*m, MetricSnapshot{}); } } diff --git a/src/datadog/tracer_telemetry.h b/src/datadog/tracer_telemetry.h index 1ed24e01..aa81ea7b 100644 --- a/src/datadog/tracer_telemetry.h +++ b/src/datadog/tracer_telemetry.h @@ -118,6 +118,8 @@ class TracerTelemetry { nlohmann::json generate_configuration_field( const ConfigMetadata& config_metadata); + std::vector> user_metrics_; + public: TracerTelemetry( bool enabled, const Clock& clock, const std::shared_ptr& logger,