Skip to content

Record telemetry metrics through handles with typed tags - #403

Closed
cataphract wants to merge 3 commits into
glopes/telemetry-ddsketchfrom
glopes/telemetry-metric-handles
Closed

cataphract wants to merge 3 commits into
glopes/telemetry-ddsketchfrom
glopes/telemetry-metric-handles

Conversation

@cataphract

@cataphract cataphract commented Nov 13, 2026 •

Copy link
Copy Markdown
Contributor

Overview

Replaces the string-tagged metric functions, such as counter::increment(metric, {"tag:value"}), with metric handles. A handle is created once, with its fixed tags and a struct that describes its other tags. Recording a point then takes that struct and a number. Distributions are now sent as sketches, using the LogBinnedDistr of #401.

Stacked on #401.

Motivation

nginx-datadog will record AppSec metrics on every request. The old API built, copied and hashed a vector of tag strings for each point, under one global lock. A handle instead computes a series id from the tag values and updates its own store. Tag strings are built only when telemetry sends the series.

Additional Notes

  • Three commits: the handle API, not yet used; Telemetry sending the handles; the old API removed and the call sites moved to handles.
  • Tag fields can be an enum (value names from tag_value_names), a bool, an Optional enum (not sent when empty) or a TagString, for values not known in advance. A TagString is interned; after 65535 strings, new ones are sent as other. A static_assert checks that every combination of tag values fits in the 64-bit series id.
  • counter::create, rate::create and distribution::create make the handles. Telemetry holds only weak references to them: a handle that its owner drops is forgotten, so the metric can be created again with other fixed tags. A handle created before telemetry::init records values that are never sent.
  • Breaking change: counter::increment, decrement and set, rate::set and distribution::add are removed.
  • The distributions payload is no longer sent. Distributions go in a sketches payload.
  • The tracer's metrics are in a process-wide TracerMetrics, created on first use. Four metrics that were declared but never recorded are dropped: trace_chunks_enqueued_for_serialization, context_header_truncated, trace_api.ms and telemetry_api.ms.
  • Each commit builds and passes the tests. On the last one, all 156 test cases pass.

References

Jira ticket: APPSEC-70954

Contributor Checklist

  • I am the author of this pull request and I own it.
  • I reviewed every line of this pull request.
  • This pull request follows the Contributing Guidelines.

A metric is registered once with typed tags, so recording a point builds,
copies and hashes no tag strings. Nothing uses the handles yet.
Telemetry owns a registry of handles, created with counter::create,
rate::create and distribution::create. Distributions go out as sketches.
The tracer and telemetry record their metrics through handles, so the old
API, which copied and hashed tag strings on every call, is removed.
@pr-commenter

pr-commenter Bot commented Nov 13, 2026

Copy link
Copy Markdown

Benchmarks

Benchmark execution time: 2026-11-13 23:40:16

Comparing candidate commit 7face92 in PR branch glopes/telemetry-metric-handles with baseline commit 38c49d5 in branch glopes/telemetry-ddsketch.

📊 Benchmarking dashboard

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

Explanation

This is an A/B test comparing a candidate commit's performance against that of a baseline commit. Performance changes are noted in the tables below as:

  • 🟩 = significantly better candidate vs. baseline
  • 🟥 = significantly worse candidate vs. baseline

We compute a confidence interval (CI) over the relative difference of means between metrics from the candidate and baseline commits, considering the baseline as the reference.

If the CI is entirely outside the configured SIGNIFICANT_IMPACT_THRESHOLD (or the deprecated UNCONFIDENCE_THRESHOLD), the change is considered significant.

Feel free to reach out to #apm-benchmarking-platform on Slack if you have any questions.

More details about the CI and significant changes

You can imagine this CI as a range of values that is likely to contain the true difference of means between the candidate and baseline commits.

CIs of the difference of means are often centered around 0%, because often changes are not that big:

---------------------------------(------|---^--------)-------------------------------->
                              -0.6%    0%  0.3%     +1.2%
                                 |          |        |
         lower bound of the CI --'          |        |
sample mean (center of the CI) -------------'        |
         upper bound of the CI ----------------------'

As described above, a change is considered significant if the CI is entirely outside the configured SIGNIFICANT_IMPACT_THRESHOLD (or the deprecated UNCONFIDENCE_THRESHOLD).

For instance, for an execution time metric, this confidence interval indicates a significantly worse performance:

----------------------------------------|---------|---(---------^---------)---------->
                                       0%        1%  1.3%      2.2%      3.1%
                                                  |   |         |         |
       significant impact threshold --------------'   |         |         |
                      lower bound of CI --------------'         |         |
       sample mean (center of the CI) --------------------------'         |
                      upper bound of CI ----------------------------------'

scenario:BM_Hex_uint64

  • 🟩 execution_time [-717.682ns; -677.113ns] or [-2.922%; -2.756%]

@cataphract

Copy link
Copy Markdown
Contributor Author

Closing to split

@cataphract cataphract closed this Nov 14, 2026
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.

1 participant