Repository navigation
[API/SDK] Add Enabled() to synchronous instruments - #4721
Conversation
- Instruments report disabled when their meter is disabled or every matching view drops them - The check is a single read, also on MSVC - No-op instruments always report disabled (ABI v2 only).
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #4721 +/- ##
==========================================
+ Coverage 86.51% 86.61% +0.11%
==========================================
Files 530 530
Lines 21136 21165 +29
==========================================
+ Hits 18284 18331 +47
+ Misses 2852 2834 -18
🚀 New features to boost your workflow:
|
mateenali66
left a comment
There was a problem hiding this comment.
checked the lifetime first. each sdk instrument holds the shared_ptr<MeterEnabledState> that owns its flag, so Enabled() stays valid after the provider is destroyed or the global provider is swapped. asan is clean on both, and on a dropped instrument. tsan is clean with 6 threads calling Enabled() and Add() while the configurator flips 4000 times. abi v1 layouts and vtables are unchanged, v2 only grows SynchronousInstrument by the pointer.
one optional thing. an instrument created from a meter whose provider is already gone has no storage and logs a warning on every Add(), but Enabled() returns true. storage == nullptr || storage->Empty() in GetInstrumentEnabledState would match what the Meter constructor already does without a context.
needs a rebase, only CHANGELOG conflicts. 1.30.0 shipped, so the entry moves under the new Unreleased.
|
@adityabavadekar - Could you also include the enabled case in the benchmark, comparing |
lalitb
left a comment
There was a problem hiding this comment.
LGTM overall. Could you add the enabled-case benchmark before merging, so we can see the overhead when metrics are being recorded normally?
- Give each instrument a disabled flag, keep copies pointing at the correct one - Treat instruments without storage as disabled - Benchmark Enabled() both when the meter is on and when it is off
|
@lalitb Added both cases to Ran a release build and took the median of 5 runs.
Enabled: negligible overhead. Disabled: checking |
|
@mateenali66 Fixed, instruments without storage are now treated as disabled, with a test. Also merged main and moved the CHANGELOG entry to under Unreleased. |
Co-authored-by: Marc Alff <marc.alff@oracle.com>
Adds
Enabled()to synchronous instruments, allowing callers to skip expensive work, such as building attributes, when nothing will be recorded. Follow-up to #4313, similar toTracer::Enabled()(#3357). SpecFixes #4719
Changes
Enabled()toSynchronousInstrument(ABI v2 only).false.OPENTELEMETRY_ATOMIC_READ_RELAXED_8, sinceOPENTELEMETRY_ATOMIC_READ_8locks the cache line on MSVC.Benchmarks
Prototypes of each design with meter disabled, all threads sharing one counter. Each call checks
Enabled()before building attributes and callingAdd(), while 8 background threads export spans over OTLP. GCC 16.2-O3, i7-1360P, median of 3 runs.Reading the meter's enabled flag through a pointer is around ~3× faster than a virtual
Enabled()call.A per-instrument flag is similarly fast to read, but configuration updates cost O(n) instead of O(1). With 65,536 instruments, updates took 665 µs versus 11.5 ns with the pointer.
Enabled()(build attributes, thenAdd)Enabled()For significant contributions please make sure you have completed the following items:
CHANGELOG.mdupdated for non-trivial changes