[part 6] refactor!(telemetry): remove dependency on TracerTelemetry#204
[part 6] refactor!(telemetry): remove dependency on TracerTelemetry#204
TracerTelemetry#204Conversation
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.
BenchmarksBenchmark execution time: 2025-04-08 11:06:29 Comparing candidate commit baafa6e in PR branch Found 0 performance improvements and 0 performance regressions! Performance is the same for 1 metrics, 0 unstable metrics. |
Codecov ReportAttention: Patch coverage is
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. 🚀 New features to boost your workflow:
|
| // 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{}); | ||
| } |
There was a problem hiding this comment.
Can we create a helper method for this?
There was a problem hiding this comment.
This is temporary and is expected to be removed in an upcoming PR.
| for (const auto& log : logs_) { | ||
| auto encoded = encode_log(log); | ||
| encoded_logs.emplace_back(std::move(encoded)); | ||
| } |
There was a problem hiding this comment.
Should logs_ be cleared after this?
There was a problem hiding this comment.
Indeed it should. Thanks.
There was a problem hiding this comment.
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_, |
There was a problem hiding this comment.
We should change to user_metrics and initialize the member variable
dubloom
left a comment
There was a problem hiding this comment.
LGTM except few comments
| } | ||
| } | ||
|
|
||
| void Telemetry::log(std::string message, telemetry::LogLevel level, |
There was a problem hiding this comment.
Out of curiosity, why did you remove the inline ?
There was a problem hiding this comment.
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?
| for (const auto& log : logs_) { | ||
| auto encoded = encode_log(log); | ||
| encoded_logs.emplace_back(std::move(encoded)); | ||
| } |
| for (const auto& log : logs_) { | ||
| auto encoded = encode_log(log); | ||
| encoded_logs.emplace_back(std::move(encoded)); | ||
| } |
There was a problem hiding this comment.
This function body looks very similar to the above function body. Would it be worth to refactor that ?
There was a problem hiding this comment.
That's planned but not now.
Description
Moves the TracerTelemetry logic directly into Telemetry, eliminating the need for a separate
TracerTelemetryobject.