-
Notifications
You must be signed in to change notification settings - Fork 791
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
Replace cassandra session wrapper with jdk proxy #8041
Conversation
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.
Other than a few nitpicky readability comments, looks good!
if (method.getParameterTypes()[0] == String.class) { | ||
String query = (String) args[0]; | ||
return execute(session, query); | ||
} else if (method.getParameterTypes()[0] == Statement.class) { |
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.
I don't know the datastax class tree well enough to say if this matters, but would method.getParameterTypes()[0].isAssignableFrom(Statement.class)
be a little safer or future-proof?
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.
Not really. If in the future there is a method that accepts a subclass of Statement
there must be a reason why this method was created, some kind of behavioural difference from the one that just accepts Statement
. If we'd accept subclasses of Statement
here we would risk loosing this behavioural difference as our instrumentation delegates to the method that accepts plain Statement
.
...c/main/java/io/opentelemetry/javaagent/instrumentation/cassandra/v4_0/TracingCqlSession.java
Outdated
Show resolved
Hide resolved
...library/src/main/java/io/opentelemetry/instrumentation/cassandra/v4_4/TracingCqlSession.java
Outdated
Show resolved
Hide resolved
session.getClass().getClassLoader(), | ||
interfaces.toArray(new Class<?>[0]), | ||
(proxy, method, args) -> { | ||
if ("execute".equals(method.getName()) && method.getParameterCount() == 1) { |
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.
The getParameterCount() == 1
check is duplicated in each if
. If you pulled those up and returned early it could simplify a little bit.
Then, knowing that you've guarded against multiple or zero params, you can pull the method.getParameterTypes()[0]
into a local variable to further simplify.
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.
I think you should view the fact that we instrument only methods that take a single parameter as a coincidence. For example the methods that we instrument delegate to https://docs.datastax.com/en/drivers/java/4.0/com/datastax/oss/driver/api/core/session/Session.html#execute-RequestT-com.datastax.oss.driver.api.core.type.reflect.GenericType- that we don't instrument, but probably should for completeness.
Resolves #8026