Skip to content

Commit 089ce37

Browse files
committed
nit
1 parent 5896c13 commit 089ce37

File tree

1 file changed

+32
-26
lines changed

1 file changed

+32
-26
lines changed

docs/metrics.md

Lines changed: 32 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -76,11 +76,11 @@ let meter = global::meter("my_company.my_product.my_library");
7676
| [UpDownCounter](https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/metrics/api.md#updowncounter) | [`UpDownCounter`](https://docs.rs/opentelemetry/latest/opentelemetry/metrics/struct.UpDownCounter.html) |
7777

7878
:stop_sign: You should avoid creating instruments (e.g. `Counter`) too
79-
frequently. Instruments are fairly expensive and meant to be reused.
80-
For most applications, instruments can be created once and
81-
re-used. Instruments can also be cloned to create multiple handles to the same
82-
instrument, but the cloning should not be on hot path, but instead the cloned
83-
instance should be stored and re-used.
79+
frequently. Instruments are fairly expensive and meant to be reused. For most
80+
applications, instruments can be created once and re-used. Instruments can also
81+
be cloned to create multiple handles to the same instrument, but the cloning
82+
should not be on hot path, but instead the cloned instance should be stored and
83+
re-used.
8484

8585
:stop_sign: You should avoid invalid instrument names.
8686

@@ -245,9 +245,8 @@ follows while implementing the metrics aggregation logic:
245245
limits](https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/metrics/sdk.md#cardinality-limits),
246246
so the SDK does not use indefinite amount of memory when there is cardinality
247247
explosion.
248-
3. [**Memory Preallocation**](#memory-preallocation): the memory used by
249-
aggregation logic is allocated during the SDK initialization (wherever feasible),
250-
so the SDK does not have to allocate memory on-the-fly.
248+
3. [**Memory Preallocation**](#memory-preallocation): SDK tries to pre-allocate
249+
the memory it needs at each instrument creation time.
251250

252251
### Example
253252

@@ -301,8 +300,8 @@ Temporality](https://github.com/open-telemetry/opentelemetry-specification/blob/
301300
* attributes: {name = `apple`, color = `green`}, count: `2`
302301
* attributes: {verb = `lemon`, color = `yellow`}, count: `10`
303302

304-
Note that the start time is advanced after each export, and only the delta
305-
since last export is exported, allowing SDK to "forget" previous state.
303+
Note that the start time is advanced after each export, and only the delta since
304+
last export is exported, allowing SDK to "forget" previous state.
306305

307306
### Pre-Aggregation
308307

@@ -333,10 +332,15 @@ metrics backend.
333332

334333
Pre-aggregation offers several advantages:
335334

336-
1. **Reduced Data Volume**: Summarizes measurements before export, minimizing network overhead and improving efficiency.
337-
2. **Predictable Resource Usage**: Ensures consistent resource consumption by applying [cardinality limits](#cardinality-limits) and [memory preallocation](#memory-preallocation) during SDK initialization. In other words, metrics storage/network needs remains
338-
fixed, irrespective of growing volume or changing traffic patterns.
339-
3. **Improved Performance**: Reduces computational load on downstream systems, enabling them to focus on analysis and storage.
335+
1. **Reduced Data Volume**: Summarizes measurements before export, minimizing
336+
network overhead and improving efficiency.
337+
2. **Predictable Resource Usage**: Ensures consistent resource consumption by
338+
applying [cardinality limits](#cardinality-limits) and [memory
339+
preallocation](#memory-preallocation) during SDK initialization. In other words,
340+
metrics storage/network needs remains fixed, irrespective of growing volume or
341+
changing traffic patterns.
342+
3. **Improved Performance**: Reduces computational load on downstream systems,
343+
enabling them to focus on analysis and storage.
340344

341345
> [!NOTE] There is no ability to export raw measurement events instead of using
342346
pre-aggregation.
@@ -346,8 +350,8 @@ pre-aggregation.
346350
The number of unique combinations of attributes is called cardinality. Taking
347351
the [fruit example](#example), if we know that we can only have apple/lemon as
348352
the name, red/yellow/green as the color, then we can say the cardinality is 6.
349-
No matter how many fruits we sell, we can always use the following
350-
table to summarize the total number of fruits based on the name and color.
353+
No matter how many fruits we sell, we can always use the following table to
354+
summarize the total number of fruits based on the name and color.
351355

352356
| Name | Color | Count |
353357
| ----- | ------ | ----- |
@@ -398,7 +402,8 @@ see much higher cardinality due to:
398402
is only applicable to Delta temporality)
399403

400404
Therefore, the actual cardinality in your metrics backend can be orders of
401-
magnitude higher than what any single OTel SDK process handles in an export cycle.
405+
magnitude higher than what any single OTel SDK process handles in an export
406+
cycle.
402407

403408
#### Cardinality Limit - Implications
404409

@@ -484,8 +489,9 @@ important:
484489
that triggered overflow.
485490

486491
OpenTelemetry's cardinality capping is only applied to attributes provided
487-
when reporting measurements via the [Metrics API](#metrics-api). In other words, attributes used to create
488-
`Meter` or `Resource` attributes are not subject to this cap.
492+
when reporting measurements via the [Metrics API](#metrics-api). In other
493+
words, attributes used to create `Meter` or `Resource` attributes are not
494+
subject to this cap.
489495

490496
:heavy_check_mark: Use `Meter` attributes or `Resource` attributes as
491497
appropriate, see [modelling attributes](#modelling-metric-attributes) for
@@ -494,13 +500,13 @@ important:
494500
Resource - this is not only efficient, but reduced the cardinality capping
495501
possibility as well.
496502

503+
// TODO: Document how to pick cardinality limit.
504+
497505
### Memory Preallocation
498506

499507
OpenTelemetry Rust SDK aims to avoid memory allocation on the hot code path.
500508
When this is combined with [proper use of Metrics API](#metrics-api), heap
501-
allocation can be avoided on the hot code path. Refer to the [metrics benchmark
502-
results](../opentelemetry-sdk/benches/metrics_counter.rs) to learn the
503-
benchmarks.
509+
allocation can be avoided on the hot code path.
504510

505511
## Metrics Correlation
506512

@@ -532,9 +538,8 @@ dimensions can come from different sources:
532538
[`meter_with_scope`](https://docs.rs/opentelemetry/latest/opentelemetry/metrics/trait.MeterProvider.html#tymethod.meter_with_scope).
533539
* [Resources](https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/resource/sdk.md)
534540
configured at the `MeterProvider` level.
535-
* Additional attributes provided by the exporter or collector. For example,
536-
[jobs and instances](https://prometheus.io/docs/concepts/jobs_instances/) in
537-
Prometheus.
541+
* Additional attributes provided by the collector. For example, [jobs and
542+
instances](https://prometheus.io/docs/concepts/jobs_instances/) in Prometheus.
538543

539544
Here is the rule of thumb when modeling the dimensions:
540545

@@ -548,7 +553,8 @@ Here is the rule of thumb when modeling the dimensions:
548553
* If the dimension applies to a subset of metrics (e.g. the version of a
549554
client library), model it as meter level attributes.
550555
* If the dimension value is dynamic, report it via the [Metrics
551-
API](#metrics-api).
556+
API](#metrics-api). Be aware that [cardinality limits](#cardinality-limits)
557+
are applied to these attributes.
552558

553559
## Common issues that lead to missing metrics
554560

0 commit comments

Comments
 (0)