Commit db67867
authored
feat: Cache OpenTelemetry metric instruments (#256)
## Summary
This change introduces caching for OpenTelemetry metric instruments
(Gauge, Counter, Histogram, UpDownCounter) within the
`InstrumentationManager`.
Previously, a new instrument was built for every metric recording call
(`recordMetric`, `recordCount`, etc.), which is inefficient. Now,
instruments are created once per metric name and reused for subsequent
calls, improving performance.
## How did you test this change?
--
## Are there any deployment considerations?
No
<!-- CURSOR_SUMMARY -->
---
> [!NOTE]
> Caches OTEL metric instruments in `InstrumentationManager` and reuses
them per metric name instead of rebuilding on each call.
>
> - **Metrics caching in
`sdk/@launchdarkly/observability-android/.../InstrumentationManager.kt`**:
> - Add caches for instruments: `gaugeCache`, `counterCache`,
`histogramCache`, `upDownCounterCache` using `ConcurrentHashMap`.
> - Import instrument types (`DoubleGauge`, `LongCounter`,
`DoubleHistogram`, `LongUpDownCounter`) and `ConcurrentHashMap`.
> - Update `recordMetric`, `recordCount`, `recordIncr`,
`recordHistogram`, `recordUpDownCounter` to `getOrPut` and reuse
instruments by name.
>
> <sup>Written by [Cursor
Bugbot](https://cursor.com/dashboard?tab=bugbot) for commit
6888028. This will update automatically
on new commits. Configure
[here](https://cursor.com/dashboard?tab=bugbot).</sup>
<!-- /CURSOR_SUMMARY -->1 parent 9a9ebe2 commit db67867
File tree
1 file changed
+29
-11
lines changed- sdk/@launchdarkly/observability-android/lib/src/main/kotlin/com/launchdarkly/observability/client
1 file changed
+29
-11
lines changedLines changed: 29 additions & 11 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
18 | 18 | | |
19 | 19 | | |
20 | 20 | | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
21 | 25 | | |
22 | 26 | | |
23 | 27 | | |
| |||
43 | 47 | | |
44 | 48 | | |
45 | 49 | | |
| 50 | + | |
46 | 51 | | |
47 | 52 | | |
48 | 53 | | |
| |||
87 | 92 | | |
88 | 93 | | |
89 | 94 | | |
90 | | - | |
91 | 95 | | |
92 | 96 | | |
93 | 97 | | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
94 | 102 | | |
95 | 103 | | |
96 | 104 | | |
| |||
275 | 283 | | |
276 | 284 | | |
277 | 285 | | |
278 | | - | |
279 | | - | |
| 286 | + | |
| 287 | + | |
| 288 | + | |
| 289 | + | |
280 | 290 | | |
281 | 291 | | |
282 | 292 | | |
283 | 293 | | |
284 | | - | |
285 | | - | |
| 294 | + | |
| 295 | + | |
| 296 | + | |
| 297 | + | |
286 | 298 | | |
287 | 299 | | |
288 | 300 | | |
289 | | - | |
290 | | - | |
| 301 | + | |
| 302 | + | |
| 303 | + | |
| 304 | + | |
291 | 305 | | |
292 | 306 | | |
293 | 307 | | |
294 | | - | |
295 | | - | |
| 308 | + | |
| 309 | + | |
| 310 | + | |
| 311 | + | |
296 | 312 | | |
297 | 313 | | |
298 | 314 | | |
299 | | - | |
300 | | - | |
| 315 | + | |
| 316 | + | |
| 317 | + | |
| 318 | + | |
301 | 319 | | |
302 | 320 | | |
303 | 321 | | |
| |||
0 commit comments