Add preview support for bound instruments #4042
Add preview support for bound instruments #4042lalitb wants to merge 2 commits intoopen-telemetry:mainfrom
Conversation
Codecov Report❌ Patch coverage is Additional details and impacted files@@ Coverage Diff @@
## main #4042 +/- ##
==========================================
- Coverage 82.04% 81.87% -0.16%
==========================================
Files 385 385
Lines 15896 16103 +207
==========================================
+ Hits 13040 13183 +143
- Misses 2856 2920 +64
🚀 New features to boost your workflow:
|
7668547 to
1fc14cf
Compare
1fc14cf to
3690e7e
Compare
| // This macro affects SDK class layout/vtables and MUST match between the SDK | ||
| // library build and consumer translation units. | ||
| #if OPENTELEMETRY_ABI_VERSION_NO >= 2 && defined(ENABLE_METRICS_BOUND_INSTRUMENTS_PREVIEW) | ||
| # define OPENTELEMETRY_HAVE_METRICS_BOUND_INSTRUMENTS_PREVIEW 1 |
There was a problem hiding this comment.
I kept this derived preview macro in version.h so API and SDK headers use one consistent guard for the ABI-v2 + preview-flag combination. This is temporary while bound instruments are experimental; once the API is stabilized, we can remove the preview flag and keep the surface under the normal ABI rules.
|
this is ready for review now. This is preview-only and gated behind ABI v2 plus |
|
I also did a local throwaway stress test on a 64-core test VM to sanity-check the expected performance shape using the stress framework #3241 The result matches the design expectation: bound instruments help most when the workload records repeatedly to stable attribute sets, because the hot path avoids repeated attribute processing and hashmap lookup. The benefit is small when all threads record to the same single series, since the same bound cell becomes the contention point. With many pre-bound series, the bound path scaled much better because contention was spread across many handles. So I would not describe the largest speedup number as a general result, but the trend is encouraging and supports the usefulness of the preview API for high-concurrency, stable-attribute workloads. For example, with 2 attributes per series and 64 threads, the local stress test showed roughly:
|
Summary
Related specs PR - open-telemetry/opentelemetry-specification#5050
Adds experimental bound synchronous metric instruments for metrics ABI v2. Bound instruments let callers bind a fixed attribute set once, then record repeated measurements through a bound handle:
Both bound handles record to the same metric instrument,
http.server.requests, with different pre-bound attribute sets. This avoids repeated per-call attribute processing and hashmap lookup for hot paths that reuse the same attribute set.Scope
This PR intentionally keeps the preview surface narrow:
Not included in this preview:
Those are left as follow-ups while the spec is still being finalized.
Feature Gate
The feature is disabled by default.
CMake:
Bazel:
CMake rejects enabling
WITH_METRICS_BOUND_INSTRUMENTS_PREVIEWwithout ABI v2.Bound code is guarded by:
OPENTELEMETRY_HAVE_METRICS_BOUND_INSTRUMENTS_PREVIEWImplementation Notes
Benchmark
Bound recording is about
18.3xfaster by mean for repeated recordings with the same fixed attribute set.Env: Ubuntu 24.04 · GCC 13.3 · AMD EPYC 9V45 (32C/64T) · 251 GiB RAM.
For significant contributions please make sure you have completed the following items:
CHANGELOG.mdupdated for non-trivial changes