Skip to content

Commit 03e7a5b

Browse files
jack-bergchalin
andauthored
Java documentation for cardinality limits (open-telemetry#5610)
Co-authored-by: Patrice Chalin <[email protected]>
1 parent 736ae99 commit 03e7a5b

File tree

5 files changed

+30
-4
lines changed

5 files changed

+30
-4
lines changed

.gitmodules

+1-1
Original file line numberDiff line numberDiff line change
@@ -31,4 +31,4 @@
3131
[submodule "content-modules/opentelemetry-java-examples"]
3232
path = content-modules/opentelemetry-java-examples
3333
url = https://github.com/open-telemetry/opentelemetry-java-examples.git
34-
javaexamples-pin = 0f736ec
34+
javaexamples-pin = f9553ef

content/en/docs/languages/java/sdk.md

+23-1
Original file line numberDiff line numberDiff line change
@@ -565,6 +565,14 @@ responsible for handling metric telemetry produced by the API.
565565

566566
- [Resource](#resource): The resource metrics are associated with.
567567
- [MetricReader](#metricreader): Reads the aggregated state of metrics.
568+
- Optionally, with
569+
[CardinalityLimitSelector](https://www.javadoc.io/doc/io.opentelemetry/opentelemetry-sdk-metrics/latest/io/opentelemetry/sdk/metrics/export/CardinalityLimitSelector.html)
570+
for overriding cardinality limit by instrument kind. If unset, each
571+
instrument is limited to 2000 unique combinations of attributes per
572+
collection cycle. Cardinality limits are also configurable for individual
573+
instruments via [views](#views). See
574+
[cardinality limits](/docs/specs/otel/metrics/sdk/#cardinality-limits) for
575+
more details.
568576
- [MetricExporter](#metricexporter): Exports metrics out of process (in
569577
conjunction with associated `MetricReader`).
570578
- [Views](#views): Configures metric streams, including dropping unused metrics.
@@ -592,11 +600,18 @@ public class SdkMeterProviderConfig {
592600
MetricReaderConfig.periodicMetricReader(
593601
MetricExporterConfig.otlpHttpMetricExporter(
594602
"http://localhost:4318/v1/metrics")));
603+
// Uncomment to optionally register metric reader with cardinality limits
604+
// builder.registerMetricReader(
605+
// MetricReaderConfig.periodicMetricReader(
606+
// MetricExporterConfig.otlpHttpMetricExporter("http://localhost:4318/v1/metrics")),
607+
// instrumentType -> 100);
608+
595609
ViewConfig.dropMetricView(builder, "some.custom.metric");
596610
ViewConfig.histogramBucketBoundariesView(
597611
builder, "http.server.request.duration", List.of(1.0, 5.0, 10.0));
598612
ViewConfig.attributeFilterView(
599613
builder, "http.client.request.duration", Set.of("http.request.method"));
614+
ViewConfig.cardinalityLimitsView(builder, "http.server.active_requests", 100);
600615
return builder.build();
601616
}
602617
}
@@ -872,7 +887,7 @@ public class CustomMetricExporter implements MetricExporter {
872887
[Views](https://www.javadoc.io/doc/io.opentelemetry/opentelemetry-sdk-metrics/latest/io/opentelemetry/sdk/metrics/View.html)
873888
allow metric streams to be customized, including changing metric names, metric
874889
descriptions, metric aggregations (i.e. histogram bucket boundaries), the set of
875-
attribute keys to retain, etc.
890+
attribute keys to retain, cardinality limit, etc.
876891

877892
{{% alert %}} Views have somewhat unintuitive behavior when multiple match a
878893
particular instrument. If one matching view changes the metric name and another
@@ -920,6 +935,13 @@ public class ViewConfig {
920935
InstrumentSelector.builder().setName(metricName).build(),
921936
View.builder().setAttributeFilter(keysToRetain).build());
922937
}
938+
939+
public static SdkMeterProviderBuilder cardinalityLimitsView(
940+
SdkMeterProviderBuilder builder, String metricName, int cardinalityLimit) {
941+
return builder.registerView(
942+
InstrumentSelector.builder().setName(metricName).build(),
943+
View.builder().setCardinalityLimit(cardinalityLimit).build());
944+
}
923945
}
924946
```
925947
<!-- prettier-ignore-end -->

static/refcache.json

+4
Original file line numberDiff line numberDiff line change
@@ -13767,6 +13767,10 @@
1376713767
"StatusCode": 200,
1376813768
"LastSeen": "2024-08-05T15:20:09.004763-05:00"
1376913769
},
13770+
"https://www.javadoc.io/doc/io.opentelemetry/opentelemetry-sdk-metrics/latest/io/opentelemetry/sdk/metrics/export/CardinalityLimitSelector.html": {
13771+
"StatusCode": 200,
13772+
"LastSeen": "2024-11-14T12:48:43.848396-06:00"
13773+
},
1377013774
"https://www.javadoc.io/doc/io.opentelemetry/opentelemetry-sdk-metrics/latest/io/opentelemetry/sdk/metrics/export/MetricExporter.html": {
1377113775
"StatusCode": 200,
1377213776
"LastSeen": "2024-08-05T15:20:07.498447-05:00"

tools/pubspec.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ name: otel_io_excerpts
22
publish_to: none
33

44
environment:
5-
sdk: ^3.2.0
5+
sdk: ^3.5.4
66

77
dev_dependencies:
88
build_runner: ^2.4.6

0 commit comments

Comments
 (0)