diff --git a/instrumentation-api/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/http/TemporaryMetricsView.java b/instrumentation-api/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/http/TemporaryMetricsView.java index 7bf7a875ce77..b2df3a6e84c0 100644 --- a/instrumentation-api/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/http/TemporaryMetricsView.java +++ b/instrumentation-api/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/http/TemporaryMetricsView.java @@ -8,6 +8,7 @@ import io.opentelemetry.api.common.AttributeKey; import io.opentelemetry.api.common.Attributes; import io.opentelemetry.api.common.AttributesBuilder; +import io.opentelemetry.instrumentation.api.config.Config; import io.opentelemetry.semconv.trace.attributes.SemanticAttributes; import java.util.HashSet; import java.util.Set; @@ -18,6 +19,14 @@ @SuppressWarnings("rawtypes") final class TemporaryMetricsView { + // TODO (trask) remove this once http.route is captured consistently + // + // this is not enabled by default because it falls back to http.target (which can be high + // cardinality) when http.route is not available + private static final boolean USE_HTTP_TARGET_FALLBACK = + Config.get() + .getBoolean("otel.instrumentation.metrics.experimental.use-http-target-fallback", false); + private static final Set durationAlwaysInclude = buildDurationAlwaysInclude(); private static final Set durationClientView = buildDurationClientView(); private static final Set durationServerView = buildDurationServerView(); @@ -96,7 +105,8 @@ private static boolean containsAttribute( static Attributes applyServerDurationView(Attributes startAttributes, Attributes endAttributes) { Set fullSet = durationServerView; // Use http.target when http.route is not available. - if (!containsAttribute(SemanticAttributes.HTTP_ROUTE, startAttributes, endAttributes)) { + if (USE_HTTP_TARGET_FALLBACK + && !containsAttribute(SemanticAttributes.HTTP_ROUTE, startAttributes, endAttributes)) { fullSet = durationServerFallbackView; } AttributesBuilder filtered = Attributes.builder(); diff --git a/instrumentation-api/src/test/java/io/opentelemetry/instrumentation/api/instrumenter/http/HttpServerMetricsTest.java b/instrumentation-api/src/test/java/io/opentelemetry/instrumentation/api/instrumenter/http/HttpServerMetricsTest.java index 241a4c87817b..2f1979ea11b9 100644 --- a/instrumentation-api/src/test/java/io/opentelemetry/instrumentation/api/instrumenter/http/HttpServerMetricsTest.java +++ b/instrumentation-api/src/test/java/io/opentelemetry/instrumentation/api/instrumenter/http/HttpServerMetricsTest.java @@ -143,7 +143,6 @@ void collectsMetrics() { .containsOnly( attributeEntry("http.scheme", "https"), attributeEntry("http.host", "host"), - attributeEntry("http.target", "/"), attributeEntry("http.method", "GET"), attributeEntry("http.status_code", 200), attributeEntry("http.flavor", "2.0")); diff --git a/instrumentation-api/src/test/java/io/opentelemetry/instrumentation/api/instrumenter/http/TemporaryMetricsViewTest.java b/instrumentation-api/src/test/java/io/opentelemetry/instrumentation/api/instrumenter/http/TemporaryMetricsViewTest.java index fac42cb3195b..92b70ebe82c6 100644 --- a/instrumentation-api/src/test/java/io/opentelemetry/instrumentation/api/instrumenter/http/TemporaryMetricsViewTest.java +++ b/instrumentation-api/src/test/java/io/opentelemetry/instrumentation/api/instrumenter/http/TemporaryMetricsViewTest.java @@ -136,8 +136,6 @@ public void shouldApplyServerDurationView_withTarget() { .containsOnly( attributeEntry(SemanticAttributes.HTTP_SCHEME.getKey(), "https"), attributeEntry(SemanticAttributes.HTTP_HOST.getKey(), "somehost"), - attributeEntry( - SemanticAttributes.HTTP_TARGET.getKey(), "/somehost/high/cardinality/12345"), attributeEntry(SemanticAttributes.HTTP_METHOD.getKey(), "GET"), attributeEntry(SemanticAttributes.HTTP_STATUS_CODE.getKey(), 500)); }