Skip to content

Commit

Permalink
error.type and db.response.status_code for jdbc
Browse files Browse the repository at this point in the history
  • Loading branch information
zeitlinger committed Feb 19, 2025
1 parent 9956b7b commit 5b75894
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -54,4 +54,10 @@ default String getResponseStatusFromException(Throwable throwable) {
default String getResponseStatus(RESPONSE response) {
return null;
}

@Nullable
default String httpStatusToResponseStatus(int httpStatus) {
int hundreds = httpStatus / 100;
return hundreds == 4 || hundreds == 5 ? Integer.toString(httpStatus) : null;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,6 @@ public String getDbOperationName(ElasticsearchRestRequest request) {

@Override
public String getResponseStatus(Response response) {
return String.valueOf(response.getStatusLine().getStatusCode());
return httpStatusToResponseStatus(response.getStatusLine().getStatusCode());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import static io.opentelemetry.api.common.AttributeKey.booleanKey;
import static io.opentelemetry.instrumentation.testing.junit.db.SemconvStabilityUtil.maybeStable;
import static io.opentelemetry.sdk.testing.assertj.OpenTelemetryAssertions.equalTo;
import static io.opentelemetry.semconv.ErrorAttributes.ERROR_TYPE;
import static io.opentelemetry.semconv.ServerAttributes.SERVER_ADDRESS;
import static io.opentelemetry.semconv.ServerAttributes.SERVER_PORT;
import static io.opentelemetry.semconv.incubating.DbIncubatingAttributes.DB_OPERATION;
Expand Down Expand Up @@ -422,7 +423,9 @@ void testCommandCompletesExceptionally() {
.hasException(new IllegalStateException("TestException"))
.hasAttributesSatisfyingExactly(
equalTo(maybeStable(DB_SYSTEM), "redis"),
equalTo(maybeStable(DB_OPERATION), "DEL"))));
equalTo(maybeStable(DB_OPERATION), "DEL"),
equalTo(maybeStable(ERROR_TYPE), "java.lang.IllegalStateException")
)));
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,6 @@ public String getDbOperationName(OpenSearchRestRequest request) {

@Override
public String getResponseStatus(Response response) {
return String.valueOf(response.getStatusLine().getStatusCode());
return httpStatusToResponseStatus(response.getStatusLine().getStatusCode());
}
}

0 comments on commit 5b75894

Please sign in to comment.