diff --git a/instrumentation-api-semconv/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/http/HttpCommonAttributesExtractor.java b/instrumentation-api-semconv/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/http/HttpCommonAttributesExtractor.java index 142b203569c6..ab72f719346f 100644 --- a/instrumentation-api-semconv/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/http/HttpCommonAttributesExtractor.java +++ b/instrumentation-api-semconv/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/http/HttpCommonAttributesExtractor.java @@ -121,9 +121,11 @@ public void onEnd( } if (SemconvStability.emitStableHttpSemconv()) { - String errorType; - if (statusCode != null && statusCodeConverter.isError(statusCode)) { - errorType = statusCode.toString(); + String errorType = null; + if (statusCode != null && statusCode > 0) { + if (statusCodeConverter.isError(statusCode)) { + errorType = statusCode.toString(); + } } else { errorType = getter.getErrorType(request, response, error); // fall back to exception class name & _OTHER diff --git a/instrumentation-api-semconv/src/test/java/io/opentelemetry/instrumentation/api/instrumenter/http/HttpStatusCodeConverterServerTest.java b/instrumentation-api-semconv/src/test/java/io/opentelemetry/instrumentation/api/instrumenter/http/HttpStatusCodeConverterServerTest.java index fb6750ca9b64..59d58fe2afbb 100644 --- a/instrumentation-api-semconv/src/test/java/io/opentelemetry/instrumentation/api/instrumenter/http/HttpStatusCodeConverterServerTest.java +++ b/instrumentation-api-semconv/src/test/java/io/opentelemetry/instrumentation/api/instrumenter/http/HttpStatusCodeConverterServerTest.java @@ -74,20 +74,20 @@ static Stream spanStatusCodes() { Arguments.of(429, false), Arguments.of(431, false), Arguments.of(451, false), - Arguments.of(500, false), - Arguments.of(501, false), - Arguments.of(502, false), - Arguments.of(503, false), - Arguments.of(504, false), - Arguments.of(505, false), - Arguments.of(506, false), - Arguments.of(507, false), - Arguments.of(508, false), - Arguments.of(510, false), - Arguments.of(511, false), + Arguments.of(500, true), + Arguments.of(501, true), + Arguments.of(502, true), + Arguments.of(503, true), + Arguments.of(504, true), + Arguments.of(505, true), + Arguments.of(506, true), + Arguments.of(507, true), + Arguments.of(508, true), + Arguments.of(510, true), + Arguments.of(511, true), // Don't exist - Arguments.of(99, false), - Arguments.of(600, false)); + Arguments.of(99, true), + Arguments.of(600, true)); } } diff --git a/testing-common/src/main/java/io/opentelemetry/instrumentation/testing/junit/http/AbstractHttpClientTest.java b/testing-common/src/main/java/io/opentelemetry/instrumentation/testing/junit/http/AbstractHttpClientTest.java index 82b5681ed8a3..672eff61478b 100644 --- a/testing-common/src/main/java/io/opentelemetry/instrumentation/testing/junit/http/AbstractHttpClientTest.java +++ b/testing-common/src/main/java/io/opentelemetry/instrumentation/testing/junit/http/AbstractHttpClientTest.java @@ -18,6 +18,7 @@ import io.opentelemetry.api.common.AttributeKey; import io.opentelemetry.api.trace.Span; import io.opentelemetry.api.trace.SpanKind; +import io.opentelemetry.instrumentation.api.instrumenter.http.internal.HttpAttributes; import io.opentelemetry.instrumentation.api.internal.HttpConstants; import io.opentelemetry.instrumentation.api.internal.SemconvStability; import io.opentelemetry.instrumentation.test.utils.PortUtils; diff --git a/testing-common/src/main/java/io/opentelemetry/instrumentation/testing/junit/http/AbstractHttpServerTest.java b/testing-common/src/main/java/io/opentelemetry/instrumentation/testing/junit/http/AbstractHttpServerTest.java index b2c58ad10085..fe9ab4b12580 100644 --- a/testing-common/src/main/java/io/opentelemetry/instrumentation/testing/junit/http/AbstractHttpServerTest.java +++ b/testing-common/src/main/java/io/opentelemetry/instrumentation/testing/junit/http/AbstractHttpServerTest.java @@ -27,6 +27,7 @@ import io.opentelemetry.context.Context; import io.opentelemetry.context.propagation.TextMapPropagator; import io.opentelemetry.context.propagation.TextMapSetter; +import io.opentelemetry.instrumentation.api.instrumenter.http.internal.HttpAttributes; import io.opentelemetry.instrumentation.api.internal.HttpConstants; import io.opentelemetry.instrumentation.api.internal.SemconvStability; import io.opentelemetry.instrumentation.testing.GlobalTraceUtil;