Skip to content

Conversation

@zeitlinger
Copy link
Member

Part of #12804

@zeitlinger zeitlinger requested a review from a team as a code owner February 17, 2025 15:22
@zeitlinger zeitlinger self-assigned this Feb 17, 2025
@github-actions github-actions bot added the test native This label can be applied to PRs to trigger them to run native tests label Feb 17, 2025
@zeitlinger zeitlinger changed the title Db client error type Db client error type for JDBC Feb 17, 2025
@zeitlinger zeitlinger force-pushed the db-client-error-type branch from dfd54d9 to fe0ff1c Compare March 11, 2025 15:20
@zeitlinger
Copy link
Member Author

@laurit addressed/answered everything - can you check again?

@zeitlinger zeitlinger force-pushed the db-client-error-type branch from 38a95f0 to d09a0ae Compare March 13, 2025 12:18
@zeitlinger zeitlinger added this to the v2.14.0 milestone Mar 13, 2025
@zeitlinger zeitlinger force-pushed the db-client-error-type branch from 0cf2546 to ae2e7a7 Compare March 13, 2025 15:41
@trask trask removed this from the v2.14.0 milestone Mar 13, 2025
@trask
Copy link
Member

trask commented Mar 13, 2025

@zeitlinger can you merge in main to fix the CI failures? thanks

@zeitlinger zeitlinger force-pushed the db-client-error-type branch from ae2e7a7 to 31f9b30 Compare March 13, 2025 18:39
@zeitlinger
Copy link
Member Author

@zeitlinger can you merge in main to fix the CI failures? thanks

done

@zeitlinger zeitlinger force-pushed the db-client-error-type branch from d46e639 to b0f00f7 Compare March 17, 2025 10:49
@zeitlinger
Copy link
Member Author

@trask works

Copy link
Member

@trask trask left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks!

@zeitlinger zeitlinger force-pushed the db-client-error-type branch from b0f00f7 to 5cf76cb Compare March 31, 2025 09:04
@zeitlinger
Copy link
Member Author

@trask all done 😄

@trask trask merged commit e2cce4c into open-telemetry:main Mar 31, 2025
87 checks passed
@zeitlinger zeitlinger deleted the db-client-error-type branch March 31, 2025 12:45
public String getResponseStatus(@Nullable Response response, @Nullable Throwable error) {
if (response != null) {
int httpStatus = response.getStatusLine().getStatusCode();
return httpStatus >= 400 && httpStatus < 600 ? Integer.toString(httpStatus) : null;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess the intent here is to only use http status codes that are errors. For the same purpose we use slightly different bounds in

CLIENT {
@Override
boolean isError(int responseStatusCode) {
return responseStatusCode >= 400
||
// invalid status code, does not exists
responseStatusCode < 100;
}
};

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

so should we move this to some internal package to promote consistency?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess it could be extracted into a separate util that could also be used from the db instrumentations. Alternatively we could start from having an internal util class that handles the status code for the db instrumentations that use http statuses that behave the same as this code (providing this behavior make sense for the db instrumentations).

Comment on lines +899 to +904
withErrorType(
"java.lang.IllegalArgumentException",
equalTo(
maybeStable(DB_SYSTEM),
DbIncubatingAttributes.DbSystemIncubatingValues.MEMCACHED),
equalTo(maybeStable(DB_OPERATION), "decr")))));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Another way this cold be approached is using equalTo(ERROR_TYPE, SemconvStability.emitStableDatabaseSemconv() ? "java.lang.IllegalArgumentException" : null)

public String getResponseStatus(@Nullable Void response, @Nullable Throwable error) {
try {
// loaded via reflection, because this class is not available in all versions that we support
Class<?> ex = Class.forName("io.vertx.pgclient.PgException");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Usually we'd do the Class.forName and getMethod only once and cache the result. Secondly postgres is not the only database supported by vert.x where is the handling for other dbs? It seems that at some point they introduced a common DatabaseException base class, imo you should implement support for at least that.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

just adding that.

BTW, one extents the other exception

image

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

BTW, one extents the other exception

DatabaseException was introduced in 4.4.0, we support 4.0.0

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The postgres exception extents Database exception - in later versions of the lib

@zeitlinger zeitlinger mentioned this pull request Apr 2, 2025
@zeitlinger
Copy link
Member Author

@laurit I've created #13640 as a follow up - please add comments there

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

test native This label can be applied to PRs to trigger them to run native tests

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants