Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Java documentation for cardinality limits #5610

Merged
merged 5 commits into from
Nov 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,4 @@
[submodule "content-modules/opentelemetry-java-examples"]
path = content-modules/opentelemetry-java-examples
url = https://github.com/open-telemetry/opentelemetry-java-examples.git
javaexamples-pin = 0f736ec
javaexamples-pin = f9553ef
2 changes: 1 addition & 1 deletion content-modules/opentelemetry-java-examples
24 changes: 23 additions & 1 deletion content/en/docs/languages/java/sdk.md
Original file line number Diff line number Diff line change
Expand Up @@ -565,6 +565,14 @@ responsible for handling metric telemetry produced by the API.

- [Resource](#resource): The resource metrics are associated with.
- [MetricReader](#metricreader): Reads the aggregated state of metrics.
- Optionally, with
[CardinalityLimitSelector](https://www.javadoc.io/doc/io.opentelemetry/opentelemetry-sdk-metrics/latest/io/opentelemetry/sdk/metrics/export/CardinalityLimitSelector.html)
for overriding cardinality limit by instrument kind. If unset, each
instrument is limited to 2000 unique combinations of attributes per
collection cycle. Cardinality limits are also configurable for individual
instruments via [views](#views). See
[cardinality limits](/docs/specs/otel/metrics/sdk/#cardinality-limits) for
more details.
- [MetricExporter](#metricexporter): Exports metrics out of process (in
conjunction with associated `MetricReader`).
- [Views](#views): Configures metric streams, including dropping unused metrics.
Expand Down Expand Up @@ -592,11 +600,18 @@ public class SdkMeterProviderConfig {
MetricReaderConfig.periodicMetricReader(
MetricExporterConfig.otlpHttpMetricExporter(
"http://localhost:4318/v1/metrics")));
// Uncomment to optionally register metric reader with cardinality limits
// builder.registerMetricReader(
// MetricReaderConfig.periodicMetricReader(
// MetricExporterConfig.otlpHttpMetricExporter("http://localhost:4318/v1/metrics")),
// instrumentType -> 100);

ViewConfig.dropMetricView(builder, "some.custom.metric");
ViewConfig.histogramBucketBoundariesView(
builder, "http.server.request.duration", List.of(1.0, 5.0, 10.0));
ViewConfig.attributeFilterView(
builder, "http.client.request.duration", Set.of("http.request.method"));
ViewConfig.cardinalityLimitsView(builder, "http.server.active_requests", 100);
return builder.build();
}
}
Expand Down Expand Up @@ -872,7 +887,7 @@ public class CustomMetricExporter implements MetricExporter {
[Views](https://www.javadoc.io/doc/io.opentelemetry/opentelemetry-sdk-metrics/latest/io/opentelemetry/sdk/metrics/View.html)
allow metric streams to be customized, including changing metric names, metric
descriptions, metric aggregations (i.e. histogram bucket boundaries), the set of
attribute keys to retain, etc.
attribute keys to retain, cardinality limit, etc.

{{% alert %}} Views have somewhat unintuitive behavior when multiple match a
particular instrument. If one matching view changes the metric name and another
Expand Down Expand Up @@ -920,6 +935,13 @@ public class ViewConfig {
InstrumentSelector.builder().setName(metricName).build(),
View.builder().setAttributeFilter(keysToRetain).build());
}

public static SdkMeterProviderBuilder cardinalityLimitsView(
SdkMeterProviderBuilder builder, String metricName, int cardinalityLimit) {
return builder.registerView(
InstrumentSelector.builder().setName(metricName).build(),
View.builder().setCardinalityLimit(cardinalityLimit).build());
}
}
```
<!-- prettier-ignore-end -->
Expand Down
4 changes: 4 additions & 0 deletions static/refcache.json
Original file line number Diff line number Diff line change
Expand Up @@ -13675,6 +13675,10 @@
"StatusCode": 200,
"LastSeen": "2024-08-05T15:20:09.004763-05:00"
},
"https://www.javadoc.io/doc/io.opentelemetry/opentelemetry-sdk-metrics/latest/io/opentelemetry/sdk/metrics/export/CardinalityLimitSelector.html": {
"StatusCode": 200,
"LastSeen": "2024-11-14T12:48:43.848396-06:00"
},
"https://www.javadoc.io/doc/io.opentelemetry/opentelemetry-sdk-metrics/latest/io/opentelemetry/sdk/metrics/export/MetricExporter.html": {
"StatusCode": 200,
"LastSeen": "2024-08-05T15:20:07.498447-05:00"
Expand Down
2 changes: 1 addition & 1 deletion tools/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ name: otel_io_excerpts
publish_to: none

environment:
sdk: ^3.2.0
sdk: ^3.5.4

dev_dependencies:
build_runner: ^2.4.6
Expand Down