Skip to content

Commit

Permalink
fixes after rebase
Browse files Browse the repository at this point in the history
  • Loading branch information
Mateusz Rzeszutek committed Sep 20, 2023
1 parent 303159e commit 86ae291
Show file tree
Hide file tree
Showing 6 changed files with 25 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import io.opentelemetry.api.common.AttributesBuilder;
import io.opentelemetry.context.Context;
import io.opentelemetry.instrumentation.api.instrumenter.AttributesExtractor;
import io.opentelemetry.instrumentation.api.instrumenter.http.internal.HttpAttributes;
import io.opentelemetry.instrumentation.api.internal.SemconvStability;
import io.opentelemetry.semconv.SemanticAttributes;
import java.util.HashSet;
Expand Down Expand Up @@ -120,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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,20 +74,20 @@ static Stream<Arguments> 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));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import io.opentelemetry.api.common.AttributesBuilder;
import io.opentelemetry.context.Context;
import io.opentelemetry.instrumentation.api.instrumenter.AttributesExtractor;
import io.opentelemetry.instrumentation.api.instrumenter.http.internal.HttpAttributes;
import io.opentelemetry.instrumentation.api.internal.HttpConstants;
import io.opentelemetry.semconv.SemanticAttributes;
import java.net.ConnectException;
Expand Down Expand Up @@ -331,7 +332,7 @@ void shouldExtractErrorType_httpStatusCode() {
extractor.onEnd(attributes, Context.root(), emptyMap(), response, null);

assertThat(attributes.build())
.containsEntry(HttpAttributes.HTTP_RESPONSE_STATUS_CODE, 400)
.containsEntry(SemanticAttributes.HTTP_RESPONSE_STATUS_CODE, 400)
.containsEntry(HttpAttributes.ERROR_TYPE, "400");
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import io.opentelemetry.api.common.AttributesBuilder;
import io.opentelemetry.context.Context;
import io.opentelemetry.instrumentation.api.instrumenter.AttributesExtractor;
import io.opentelemetry.instrumentation.api.instrumenter.http.internal.HttpAttributes;
import io.opentelemetry.instrumentation.api.internal.HttpConstants;
import io.opentelemetry.semconv.SemanticAttributes;
import java.net.ConnectException;
Expand Down Expand Up @@ -372,7 +373,7 @@ void shouldExtractErrorType_httpStatusCode() {
extractor.onEnd(attributes, Context.root(), emptyMap(), response, null);

assertThat(attributes.build())
.containsEntry(HttpAttributes.HTTP_RESPONSE_STATUS_CODE, 500)
.containsEntry(SemanticAttributes.HTTP_RESPONSE_STATUS_CODE, 500)
.containsEntry(HttpAttributes.ERROR_TYPE, "500");
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit 86ae291

Please sign in to comment.