Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Db client error type for JDBC #13331

Open
wants to merge 15 commits into
base: main
Choose a base branch
from

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
@Override
public String getResponseStatusFromException(Throwable throwable) {
if (throwable instanceof CouchbaseException) {
// todo
Copy link
Member Author

Choose a reason for hiding this comment

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

@laurit can you provide a hint how I could get details of a newer library version?

Should this be in one of the other couchbase modules? Is there an example?

@Nullable
@Override
public String getResponseStatusFromException(Throwable throwable) {
// todo
Copy link
Member Author

Choose a reason for hiding this comment

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

@laurit can you help here as well?

Copy link
Contributor

Choose a reason for hiding this comment

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

In our test the exception is of type io.vertx.pgclient.PgException https://github.com/eclipse-vertx/vertx-sql-client/blob/4.0.0/vertx-pg-client/src/main/java/io/vertx/pgclient/PgException.java you could extract the error from there. Probably the other vetx database drivers provide similar exceptions. You may need to use reflection to extract it.

@@ -29,6 +29,9 @@ abstract class DbClientCommonAttributesExtractor<
private static final AttributeKey<String> DB_USER = AttributeKey.stringKey("db.user");
private static final AttributeKey<String> DB_CONNECTION_STRING =
AttributeKey.stringKey("db.connection_string");
private static final AttributeKey<String> ERROR_TYPE = AttributeKey.stringKey("error.type");
Copy link
Contributor

Choose a reason for hiding this comment

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

you should use ErrorAttributes.ERROR_TYPE since it is a stable attribute

Comment on lines +48 to +56
@Nullable
default String getResponseStatusFromException(Throwable throwable) {
return null;
}

@Nullable
default String getResponseStatus(RESPONSE response) {
return null;
}
Copy link
Contributor

Choose a reason for hiding this comment

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

HttpCommonAttributesGetter has Integer getHttpResponseStatusCode(REQUEST request, RESPONSE response, @Nullable Throwable error);

Comment on lines +58 to +62
@Nullable
default String httpStatusToResponseStatus(int httpStatus) {
int hundreds = httpStatus / 100;
return hundreds == 4 || hundreds == 5 ? 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.

To me this method feels out of place here. Secondly I believe it would be more conventional to use httpStatus >= 400 && httpStatus< 600. Thirdly https://opentelemetry.io/docs/specs/semconv/database/database-spans/ says that

The status code returned by the database. Usually it represents an error code, but may also represent partial success, warning, or differentiate between various types of successful outcomes. Semantic conventions for individual database systems SHOULD document what db.response.status_code means in the context of that system.

Using the http status here already feels obscure enough that we may need to start documenting this along with the instrumentation. I'm not sure end users will be easily able to figure this out.

@@ -8,7 +8,7 @@
import javax.annotation.Nullable;

/** An interface for getting attributes common to database clients. */
public interface DbClientCommonAttributesGetter<REQUEST> {
public interface DbClientCommonAttributesGetter<REQUEST, RESPONSE> {
Copy link
Contributor

Choose a reason for hiding this comment

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

Adding a type parameter is a breaking change. @trask is this fine or do you have suggestions?

Comment on lines +67 to +74
if (error != null) {
internalSet(attributes, ERROR_TYPE, error.getClass().getName());
internalSet(
attributes, DB_RESPONSE_STATUS_CODE, getter.getResponseStatusFromException(error));
}
if (response != null) {
internalSet(attributes, DB_RESPONSE_STATUS_CODE, getter.getResponseStatus(response));
}
Copy link
Contributor

Choose a reason for hiding this comment

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

should there be a stable semconv check?

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.

2 participants