MetricsView created with SdkMeterProviderUtil.appendFilteredBaggageAttributes adds high-cardinality attributes from http-server-metrics-state
Maintainers usually reply within 3 days
Nobody has claimed this yet.
Assessment
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Newbie friendliness
- 35/100
- Issue type
- Bug
- Clarity
- Mostly clear
- Activity status
- Stale
- Tech stack
- java
- Domain
- observability-sre
Research direction
Start by inspecting sdk/metrics/src/main/java/io/opentelemetry/sdk/metrics/internal/view/AttributesProcessor.java around line 200 and trace how Context's http-server-metrics-state attributes reach the view. Reproduce with the listed agent versions and verify that the filtered view retains only the matching baggage attribute, without the reported high-cardinality HTTP attributes.
Written by the indexing model from the issue text.
Description
Describe the bug
I'm creating an OTel Agent extension, and I want to include a low-cardinality Baggage Entry into some metrics (http.server.request.duration and others).
I followed this example https://github.com/open-telemetry/opentelemetry-java-instrumentation/discussions/7704#discussioncomment-4949461
In my agent extension, I have autoconfiguration code like:
private SdkMeterProviderBuilder configureSdkMeterProvider(SdkMeterProviderBuilder meterProviderBuilder, ConfigProperties config) {
ViewBuilder tenancyAttrBuilder = View.builder();
SdkMeterProviderUtil.appendFilteredBaggageAttributes(
tenancyAttrBuilder,
name -> name.equals("my-tenancy-attribute");
View tenancyAttrView = tenancyAttrBuilder.build();
for (String metricName: ImmutableList.of("http.server.request.duration", "http.server.active_requests") {
meterProviderBuilder.registerView(
InstrumentSelector.builder().setName(metricName).build(),
tenancyAttrView
);
}
return meterProviderBuilder;
}
What did you expect to see?
I expected the only new attribute that'd be added to the metrics would be "my-tenancy-attribute" from Baggage.
What did you see instead?
The attribute from baggage is added, but also added are a handful of high-cardinality attributes.
None of which match the predicate supplied to the View.
Stepping through the code, it seems like they get added on this line: https://github.com/open-telemetry/opentelemetry-java/blob/37969926d13f7f62cf4fa9b2f46794c01d0cfb3a/sdk/metrics/src/main/java/io/opentelemetry/sdk/metrics/internal/view/AttributesProcessor.java#L200
Incoming is a collection of the attributes from Context's http-server-metrics-state
With either jetty or undertow autoinstrumentation, this results in a cardinality explosion due to entries being added for the following attributes:
- url.query
- url.path
- user_agent.original
- network.peer.port
- network.peer.address
- client.address
Messages are logged from the otel agent like:
[otel.javaagent 2025-02-21 03:53:44:316 +0000] [XNIO-1 task-18] WARN io.opentelemetry.sdk.metrics.internal.state.DefaultSynchronousMetricStorage - Instrument http.server.request.duration has exceeded the maximum allowed cardinality (1999).
What version and what artifacts are you using?
Artifacts: opentelemetry-java, opentelemetry-java-instrumentation. otel agent + my extension. otlp exporters.
Version: 1.47.0 of otel java, 2.13.1 of otel-java-instrumentation
How did you reference these artifacts?
root pom
<properties>
<opentelemetry-instrumentation-bom.version>2.13.1</opentelemetry-instrumentation-bom.version>
</properties>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>io.opentelemetry.instrumentation</groupId>
<artifactId>opentelemetry-instrumentation-bom-alpha</artifactId>
<version>${opentelemetry-instrumentation-bom.version}-alpha</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
agent extension pom:
<dependencies>
<dependency>
<groupId>io.opentelemetry</groupId>
<artifactId>opentelemetry-api</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>io.opentelemetry.semconv</groupId>
<artifactId>opentelemetry-semconv</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>io.opentelemetry.semconv</groupId>
<artifactId>opentelemetry-semconv-incubating</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>io.opentelemetry</groupId>
<artifactId>opentelemetry-sdk-extension-autoconfigure-spi</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>io.opentelemetry.instrumentation</groupId>
<artifactId>opentelemetry-instrumentation-api</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>io.opentelemetry.javaagent</groupId>
<artifactId>opentelemetry-javaagent-extension-api</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>io.opentelemetry.javaagent</groupId>
<artifactId>opentelemetry-javaagent-tooling</artifactId>
<scope>provided</scope>
</dependency>
</dependencies>
Environment
Compiler: (e.g., "Temurin 17.0.7")
OS: (e.g., "Ubuntu 20.04")
Runtime (if different from JDK above): (e.g., "Oracle JRE 8u251")
OS (if different from OS compiled on): (e.g., "Windows Server 2019")
❯ java -version
openjdk version "1.8.0_372"
OpenJDK Runtime Environment (Zulu 8.70.0.23-CA-macos-aarch64) (build 1.8.0_372-b07)
OpenJDK 64-Bit Server VM (Zulu 8.70.0.23-CA-macos-aarch64) (build 25.372-b07, mixed mode)
Additional context
Add any other context about the problem here.
- Dominant language
- Java
- Stars
- 2.5k
- Forks
- 1.1k
- Avg merge
- 5d 11h
- Merged PRs (30d)
- 41
Getting set up
- No Dockerfile or Docker Compose file
- No pull request template
- Read the contributing guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from open-telemetry/opentelemetry-java
-
`B3PropagatorExtractorMultipleHeaders` allocates when headers are missingPossibly taken @Eliot5566 claimed this today. OpenBug
Difficulty 2/5 1-3 hours Newbie friendliness 82/100
open-telemetry/opentelemetry-java#9065 ·
Maintainers usually reply within 3 days
-
[incubator] ComposableProbabilitySampler does not validate ratio rangePossibly taken @eminfikret claimed this 4 days ago. Open
Difficulty 2/5 1-3 hours Newbie friendliness 76/100
open-telemetry/opentelemetry-java#9046 · 2 comments · 1 assignee ·
Maintainers usually reply within 3 days
-
PrometheusComponentProvider promotes all resource attributes when resource_constant_labels is empty ({})Possibly taken @rooks-ns claimed this 19 days ago. Open
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
open-telemetry/opentelemetry-java#9014 · 1 comment ·
Maintainers usually reply within 3 days
-
Fix `otel.sdk.log.created` counting semanticsPossibly taken @anuraaga claimed this 112 days ago. Open
Difficulty 2/5 1-3 hours Newbie friendliness 76/100
open-telemetry/opentelemetry-java#8688 ·
Maintainers usually reply within 3 days
-
SdkSpanBuilder drops invalid parent TraceState when IdGenerator.generatesRandomTraceIds() is truePossibly taken @Eliot5566 claimed this today. OpenBug SDK
Difficulty 4/5 3-5 days Newbie friendliness 48/100
open-telemetry/opentelemetry-java#9062 · 1 comment ·
Maintainers usually reply within 3 days
All issues in open-telemetry/opentelemetry-java
Similar issues
-
Difficulty 2/5 1-3 hours Newbie friendliness 79/100
micronaut-projects/micronaut-core#14585 ·
Maintainers usually reply within 1 day
-
Mend: dependency security vulnerability untriaged
Difficulty 1/5 Under an hour Newbie friendliness 78/100
opensearch-project/cross-cluster-replication#1805 ·
Maintainers usually reply within 1 day
-
feature request needs triage
Difficulty 1/5 Under an hour Newbie friendliness 66/100
TeamNewPipe/NewPipe#14083 ·
Maintainers usually reply within 1 day
-
Difficulty 1/5 Under an hour Newbie friendliness 68/100
PCL-Community/PCL-CE#3907 ·
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 73/100
Maintainers usually reply within 2 days