Skip to content

[part 6] refactor!(telemetry): remove dependency on TracerTelemetry#204

Merged
dmehala merged 5 commits intomainfrom
dmehala/telemetry/part-6-nuke-tracer-telemetry
Apr 8, 2025
Merged

[part 6] refactor!(telemetry): remove dependency on TracerTelemetry#204
dmehala merged 5 commits intomainfrom
dmehala/telemetry/part-6-nuke-tracer-telemetry

Conversation

@dmehala
Copy link
Copy Markdown
Collaborator

@dmehala dmehala commented Apr 7, 2025

Description

Moves the TracerTelemetry logic directly into Telemetry, eliminating the need for a separate TracerTelemetry object.

dmehala added 2 commits April 5, 2025 13:21
Previously, telemetry metrics were collected every 10 seconds and
heartbeats were sent every 60 seconds, matching the default configuration.
However, these intervals can be customized via environment variables or code.

This commit updates the telemetry logic to use the configured intervals—whether
set through environment variables or directly in the code—ensuring that metrics
, heartbeat and logs messages are sent accordingly.
Moves the TracerTelemetry logic directly into Telemetry, eliminating
the need for a separate `TracerTelemetry` object.
@dmehala dmehala requested a review from a team as a code owner April 7, 2025 07:21
@dmehala dmehala requested review from dubloom, pablomartinezbernardo and zacharycmontoya and removed request for a team April 7, 2025 07:21
@pr-commenter
Copy link
Copy Markdown

pr-commenter bot commented Apr 7, 2025

Benchmarks

Benchmark execution time: 2025-04-08 11:06:29

Comparing candidate commit baafa6e in PR branch dmehala/telemetry/part-6-nuke-tracer-telemetry with baseline commit e777070 in branch main.

Found 0 performance improvements and 0 performance regressions! Performance is the same for 1 metrics, 0 unstable metrics.

@codecov-commenter
Copy link
Copy Markdown

codecov-commenter commented Apr 7, 2025

Codecov Report

Attention: Patch coverage is 61.89189% with 141 lines in your changes missing coverage. Please review.

Project coverage is 90.21%. Comparing base (e777070) to head (baafa6e).

Files with missing lines Patch % Lines
src/datadog/telemetry/telemetry_impl.cpp 61.89% 141 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #204      +/-   ##
==========================================
- Coverage   90.81%   90.21%   -0.60%     
==========================================
  Files          81       79       -2     
  Lines        4649     4672      +23     
==========================================
- Hits         4222     4215       -7     
- Misses        427      457      +30     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Comment on lines +108 to +142
// 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.
metrics_snapshots_.emplace_back(metrics_.tracer.spans_created,
MetricSnapshot{});
metrics_snapshots_.emplace_back(metrics_.tracer.spans_finished,
MetricSnapshot{});
metrics_snapshots_.emplace_back(metrics_.tracer.trace_segments_created_new,
MetricSnapshot{});
metrics_snapshots_.emplace_back(
metrics_.tracer.trace_segments_created_continued, MetricSnapshot{});
metrics_snapshots_.emplace_back(metrics_.tracer.trace_segments_closed,
MetricSnapshot{});
metrics_snapshots_.emplace_back(metrics_.trace_api.requests,
MetricSnapshot{});
metrics_snapshots_.emplace_back(metrics_.trace_api.responses_1xx,
MetricSnapshot{});
metrics_snapshots_.emplace_back(metrics_.trace_api.responses_2xx,
MetricSnapshot{});
metrics_snapshots_.emplace_back(metrics_.trace_api.responses_3xx,
MetricSnapshot{});
metrics_snapshots_.emplace_back(metrics_.trace_api.responses_4xx,
MetricSnapshot{});
metrics_snapshots_.emplace_back(metrics_.trace_api.responses_5xx,
MetricSnapshot{});
metrics_snapshots_.emplace_back(metrics_.trace_api.errors_timeout,
MetricSnapshot{});
metrics_snapshots_.emplace_back(metrics_.trace_api.errors_network,
MetricSnapshot{});
metrics_snapshots_.emplace_back(metrics_.trace_api.errors_status_code,
MetricSnapshot{});

for (auto& m : user_metrics_) {
metrics_snapshots_.emplace_back(*m, MetricSnapshot{});
}
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we create a helper method for this?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is temporary and is expected to be removed in an upcoming PR.

Comment on lines +424 to +427
for (const auto& log : logs_) {
auto encoded = encode_log(log);
encoded_logs.emplace_back(std::move(encoded));
}
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should logs_ be cleared after this?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Indeed it should. Thanks.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same for metrics, no ?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, that's correctly handled by metrics

std::shared_ptr<tracing::Logger> logger,
std::shared_ptr<tracing::HTTPClient> client,
std::vector<std::shared_ptr<Metric>> metrics,
std::vector<std::shared_ptr<Metric>> user_metrics_,
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should change to user_metrics and initialize the member variable

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

addressed in baafa6e

Base automatically changed from dmehala/telemetry/part-5-heartbeat to main April 7, 2025 17:58
Copy link
Copy Markdown
Contributor

@dubloom dubloom left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM except few comments

}
}

void Telemetry::log(std::string message, telemetry::LogLevel level,
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Out of curiosity, why did you remove the inline ?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The main reason for this is that the definition is now in the .cpp file. If the question is why has it move in the .cpp, then, it's mainly to have all definitions in one place rather than scattered across the .h and .cpp. Do that answer your question?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yep, thank you

Comment on lines +424 to +427
for (const auto& log : logs_) {
auto encoded = encode_log(log);
encoded_logs.emplace_back(std::move(encoded));
}
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same for metrics, no ?

for (const auto& log : logs_) {
auto encoded = encode_log(log);
encoded_logs.emplace_back(std::move(encoded));
}
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This function body looks very similar to the above function body. Would it be worth to refactor that ?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's planned but not now.

@dmehala dmehala merged commit c85660b into main Apr 8, 2025
22 checks passed
@dmehala dmehala deleted the dmehala/telemetry/part-6-nuke-tracer-telemetry branch April 8, 2025 12:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants