-
Notifications
You must be signed in to change notification settings - Fork 904
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
base: main
Are you sure you want to change the base?
Conversation
@Override | ||
public String getResponseStatusFromException(Throwable throwable) { | ||
if (throwable instanceof CouchbaseException) { | ||
// todo |
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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"); |
There was a problem hiding this comment.
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
@Nullable | ||
default String getResponseStatusFromException(Throwable throwable) { | ||
return null; | ||
} | ||
|
||
@Nullable | ||
default String getResponseStatus(RESPONSE response) { | ||
return null; | ||
} |
There was a problem hiding this comment.
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);
@Nullable | ||
default String httpStatusToResponseStatus(int httpStatus) { | ||
int hundreds = httpStatus / 100; | ||
return hundreds == 4 || hundreds == 5 ? Integer.toString(httpStatus) : null; | ||
} |
There was a problem hiding this comment.
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> { |
There was a problem hiding this comment.
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?
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)); | ||
} |
There was a problem hiding this comment.
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?
973784e
to
7454b42
Compare
Part of #12804