Skip to content

Commit

Permalink
fix: telemetry refactoring part 1 (#167)
Browse files Browse the repository at this point in the history
Keep a reference to user metrics to avoid dereferencing them when they
are not alive anymore.
  • Loading branch information
dmehala authored Nov 4, 2024
1 parent 963f78b commit d49c147
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 2 deletions.
5 changes: 3 additions & 2 deletions src/datadog/tracer_telemetry.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down Expand Up @@ -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{});
}
}
Expand Down
2 changes: 2 additions & 0 deletions src/datadog/tracer_telemetry.h
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,8 @@ class TracerTelemetry {
nlohmann::json generate_configuration_field(
const ConfigMetadata& config_metadata);

std::vector<std::shared_ptr<telemetry::Metric>> user_metrics_;

public:
TracerTelemetry(
bool enabled, const Clock& clock, const std::shared_ptr<Logger>& logger,
Expand Down

0 comments on commit d49c147

Please sign in to comment.