Skip to content

Commit

Permalink
Add cardinality limit demonstration (#520)
Browse files Browse the repository at this point in the history
  • Loading branch information
jack-berg authored Nov 14, 2024
1 parent b1ceb4e commit 0eba68f
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 4 deletions.
3 changes: 1 addition & 2 deletions declarative-configuration/otel-sdk-config.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
# See https://github.com/open-telemetry/opentelemetry-configuration for details on schema and examples

# TODO: the current support file format is 0.3, but the opentelemetry-java errantly checks that it is 0.1. This will be fixed in 1.44.0.
file_format: "0.1"
file_format: "0.3"

resource:
attributes:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,18 @@ public static SdkMeterProvider create(Resource resource) {
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")),
// unusedInstrumentType -> 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();
}
}
7 changes: 7 additions & 0 deletions doc-snippets/configuration/src/main/java/otel/ViewConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,11 @@ public static SdkMeterProviderBuilder attributeFilterView(
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());
}
}
3 changes: 1 addition & 2 deletions javaagent/sdk-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,7 @@
# vars defined in https://opentelemetry.io/docs/specs/otel/configuration/sdk-environment-variables/.

# The file format version.
# TODO: the current support file format is 0.3, but the opentelemetry-java errantly checks that it is 0.1. This will be fixed in 1.44.0.
file_format: "0.1"
file_format: "0.3"

# Configure if the SDK is disabled or not. This is not required to be provided to ensure the SDK isn't disabled, the default value when this is not provided is for the SDK to be enabled.
disabled: false
Expand Down

0 comments on commit 0eba68f

Please sign in to comment.