Skip to content

Commit 122039b

Browse files
committed
use single method for status code
1 parent 8254fa2 commit 122039b

File tree

9 files changed

+31
-31
lines changed

9 files changed

+31
-31
lines changed

instrumentation-api-incubator/src/main/java/io/opentelemetry/instrumentation/api/incubator/semconv/db/DbClientCommonAttributesExtractor.java

+2-4
Original file line numberDiff line numberDiff line change
@@ -66,11 +66,9 @@ public final void onEnd(
6666
@Nullable Throwable error) {
6767
if (error != null) {
6868
internalSet(attributes, ERROR_TYPE, error.getClass().getName());
69-
internalSet(
70-
attributes, DB_RESPONSE_STATUS_CODE, getter.getResponseStatusFromException(error));
7169
}
72-
if (response != null) {
73-
internalSet(attributes, DB_RESPONSE_STATUS_CODE, getter.getResponseStatus(response));
70+
if (error != null || response != null) {
71+
internalSet(attributes, DB_RESPONSE_STATUS_CODE, getter.getResponseStatus(response, error));
7472
}
7573
}
7674

instrumentation-api-incubator/src/main/java/io/opentelemetry/instrumentation/api/incubator/semconv/db/DbClientCommonAttributesGetter.java

+1-6
Original file line numberDiff line numberDiff line change
@@ -46,12 +46,7 @@ default String getDbNamespace(REQUEST request) {
4646
String getConnectionString(REQUEST request);
4747

4848
@Nullable
49-
default String getResponseStatusFromException(Throwable throwable) {
50-
return null;
51-
}
52-
53-
@Nullable
54-
default String getResponseStatus(RESPONSE response) {
49+
default String getResponseStatus(@Nullable RESPONSE response, @Nullable Throwable error) {
5550
return null;
5651
}
5752
}

instrumentation/clickhouse-client-0.5/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/clickhouse/ClickHouseAttributesGetter.java

+3-3
Original file line numberDiff line numberDiff line change
@@ -63,9 +63,9 @@ public String getConnectionString(ClickHouseDbRequest request) {
6363

6464
@Nullable
6565
@Override
66-
public String getResponseStatusFromException(Throwable throwable) {
67-
if (throwable instanceof ClickHouseException) {
68-
return Integer.toString(((ClickHouseException) throwable).getErrorCode());
66+
public String getResponseStatus(@Nullable Void response, @Nullable Throwable error) {
67+
if (error instanceof ClickHouseException) {
68+
return Integer.toString(((ClickHouseException) error).getErrorCode());
6969
}
7070
return null;
7171
}

instrumentation/elasticsearch/elasticsearch-rest-common-5.0/library/src/main/java/io/opentelemetry/instrumentation/elasticsearch/rest/common/v5_0/internal/ElasticsearchDbAttributesGetter.java

+6-3
Original file line numberDiff line numberDiff line change
@@ -94,9 +94,12 @@ public String getDbOperationName(ElasticsearchRestRequest request) {
9494
return endpointDefinition != null ? endpointDefinition.getEndpointName() : null;
9595
}
9696

97+
@Nullable
9798
@Override
98-
public String getResponseStatus(Response response) {
99-
return DbResponseStatusUtil.httpStatusToResponseStatus(
100-
response.getStatusLine().getStatusCode());
99+
public String getResponseStatus(@Nullable Response response, @Nullable Throwable error) {
100+
if (response != null) {
101+
return DbResponseStatusUtil.httpStatusToResponseStatus(
102+
response.getStatusLine().getStatusCode());
103+
}
101104
}
102105
}

instrumentation/jdbc/library/src/main/java/io/opentelemetry/instrumentation/jdbc/internal/JdbcAttributesGetter.java

+4-3
Original file line numberDiff line numberDiff line change
@@ -54,10 +54,11 @@ public Long getBatchSize(DbRequest request) {
5454
return request.getBatchSize();
5555
}
5656

57+
@Nullable
5758
@Override
58-
public String getResponseStatusFromException(Throwable throwable) {
59-
if (throwable instanceof SQLException) {
60-
return Integer.toString(((SQLException) throwable).getErrorCode());
59+
public String getResponseStatus(@Nullable Void response, @Nullable Throwable error) {
60+
if (error instanceof SQLException) {
61+
return Integer.toString(((SQLException) error).getErrorCode());
6162
}
6263
return null;
6364
}

instrumentation/mongo/mongo-3.1/library/src/main/java/io/opentelemetry/instrumentation/mongo/v3_1/MongoDbAttributesGetter.java

+3-3
Original file line numberDiff line numberDiff line change
@@ -100,9 +100,9 @@ public String getDbOperationName(CommandStartedEvent event) {
100100

101101
@Nullable
102102
@Override
103-
public String getResponseStatusFromException(Throwable throwable) {
104-
if (throwable instanceof MongoException) {
105-
return Integer.toString(((MongoException) throwable).getCode());
103+
public String getResponseStatus(@Nullable Void response, @Nullable Throwable error) {
104+
if (error instanceof MongoException) {
105+
return Integer.toString(((MongoException) error).getCode());
106106
}
107107
return null;
108108
}

instrumentation/opensearch/opensearch-rest-common/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/opensearch/rest/OpenSearchRestAttributesGetter.java

+6-3
Original file line numberDiff line numberDiff line change
@@ -52,9 +52,12 @@ public String getDbOperationName(OpenSearchRestRequest request) {
5252
return request.getMethod();
5353
}
5454

55+
@Nullable
5556
@Override
56-
public String getResponseStatus(Response response) {
57-
return DbResponseStatusUtil.httpStatusToResponseStatus(
58-
response.getStatusLine().getStatusCode());
57+
public String getResponseStatus(@Nullable Response response, @Nullable Throwable error) {
58+
if (response != null) {
59+
return DbResponseStatusUtil.httpStatusToResponseStatus(
60+
response.getStatusLine().getStatusCode());
61+
}
5962
}
6063
}

instrumentation/r2dbc-1.0/library/src/main/java/io/opentelemetry/instrumentation/r2dbc/v1_0/internal/R2dbcSqlAttributesGetter.java

+3-3
Original file line numberDiff line numberDiff line change
@@ -51,9 +51,9 @@ public Collection<String> getRawQueryTexts(DbExecution request) {
5151

5252
@Nullable
5353
@Override
54-
public String getResponseStatusFromException(Throwable throwable) {
55-
if (throwable instanceof R2dbcException) {
56-
return ((R2dbcException) throwable).getSqlState();
54+
public String getResponseStatus(@Nullable Void response, @Nullable Throwable error) {
55+
if (error instanceof R2dbcException) {
56+
return ((R2dbcException) error).getSqlState();
5757
}
5858
return null;
5959
}

instrumentation/vertx/vertx-sql-client-4.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/vertx/v4_0/sql/VertxSqlClientAttributesGetter.java

+3-3
Original file line numberDiff line numberDiff line change
@@ -48,11 +48,11 @@ public Collection<String> getRawQueryTexts(VertxSqlClientRequest request) {
4848

4949
@Nullable
5050
@Override
51-
public String getResponseStatusFromException(Throwable throwable) {
51+
public String getResponseStatus(@Nullable Void response, @Nullable Throwable error) {
5252
try {
5353
Class<?> ex = Class.forName("io.vertx.pgclient.PgException");
54-
if (ex.isInstance(throwable)) {
55-
return (String) ex.getMethod("getCode").invoke(throwable);
54+
if (ex.isInstance(error)) {
55+
return (String) ex.getMethod("getCode").invoke(error);
5656
}
5757
} catch (ClassNotFoundException
5858
| NoSuchMethodException

0 commit comments

Comments
 (0)