Skip to content

[part 8] refactor!(telemetry): rework metrics API#206

Merged
dmehala merged 9 commits intomainfrom
dmehala/part-8-metrics-usage
Apr 22, 2025
Merged

[part 8] refactor!(telemetry): rework metrics API#206
dmehala merged 9 commits intomainfrom
dmehala/part-8-metrics-usage

Conversation

@dmehala
Copy link
Copy Markdown
Collaborator

@dmehala dmehala commented Apr 12, 2025

Description

Redesigned the metrics API to eliminate the need for pre-registering a list of metrics.

Previously, the API relied on a pull-based approach where metrics had to be registered during the construction of the telemetry. The module would then periodically retrieve values from the registered metrics. While functional, this design was cumbersome - especially for metrics involving dynamic tags.

This refactoring introduces a push-based mechanism. Calls to rate, counter, or distribution now directly send data to the telemetry instance, removing the need for upfront registration.

This approach simplifies usage and improves flexibility.

@dmehala dmehala requested a review from a team as a code owner April 12, 2025 11:21
@dmehala dmehala requested review from dubloom and removed request for a team April 12, 2025 11:21
@pr-commenter
Copy link
Copy Markdown

pr-commenter bot commented Apr 12, 2025

Benchmarks

Benchmark execution time: 2025-04-21 15:20:12

Comparing candidate commit c6e60dc in PR branch dmehala/part-8-metrics-usage with baseline commit dca35bd in branch main.

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

@dmehala dmehala force-pushed the dmehala/part-8-metrics-usage branch 3 times, most recently from 6bb0603 to 8484803 Compare April 12, 2025 12:28
Redesigned the metrics API to eliminate the need for pre-registering a list
of metrics.

Previously, the API relied on a pull-based approach where metrics had to be
registered during the construction of the telemetry module. The module would
then periodically retrieve values from the registered metrics.
While functional, this design was cumbersome—especially for metrics involving
dynamic tags.

This refactoring introduces a push-based mechanism. Calls to `rate`, `counter`,
or `distribution` now directly send data to the telemetry module, removing
the need for upfront registration.
This approach simplifies usage and improves flexibility.
@codecov-commenter
Copy link
Copy Markdown

codecov-commenter commented Apr 12, 2025

Codecov Report

Attention: Patch coverage is 51.68350% with 287 lines in your changes missing coverage. Please review.

Project coverage is 87.09%. Comparing base (dca35bd) to head (c6e60dc).

Files with missing lines Patch % Lines
src/datadog/common/hash.h 40.60% 117 Missing ⚠️
src/datadog/common/hash.cpp 43.85% 96 Missing ⚠️
src/datadog/telemetry/telemetry.cpp 13.15% 66 Missing ⚠️
src/datadog/telemetry/telemetry_impl.cpp 95.79% 5 Missing ⚠️
src/datadog/tracer.cpp 50.00% 2 Missing ⚠️
src/datadog/datadog_agent.cpp 85.71% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #206      +/-   ##
==========================================
- Coverage   89.67%   87.09%   -2.58%     
==========================================
  Files          80       80              
  Lines        4705     5083     +378     
==========================================
+ Hits         4219     4427     +208     
- Misses        486      656     +170     

☔ 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.


namespace datadog::telemetry {

// This uses a reference_wrapper so references to internal metric values can
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.

nit: not a reference_wrapper anymore

Comment on lines +360 to +361
if (auto distributions_series = encode_distributions(distributions);
!distributions.empty()) {
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.

nit: if I'm understanding correctly, !distributions.empty() will be checked after encode_distributions(distributions) has been run. Is there a reason to not check for emptiness first, and then encode them if necessary?

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.

In the end what matters is the JSON payload. In the unlikely event that encode_distributions returns an empty JSON even if distributions is not empty, this approach ensures that the empty payload is not added. While such a scenario is unlikely, it offers a better guarantee IMO. That said, whether it's written this way or as you suggested, the outcome is effectively the same

Co-authored-by: pablomartinezbernardo <134320516+pablomartinezbernardo@users.noreply.github.com>
@dmehala dmehala merged commit 8f05ef9 into main Apr 22, 2025
22 checks passed
@dmehala dmehala deleted the dmehala/part-8-metrics-usage branch April 22, 2025 17:27
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