-
Notifications
You must be signed in to change notification settings - Fork 987
ClickHouse client v0.8 instrumentation #14501
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
base: main
Are you sure you want to change the base?
Conversation
instrumentation/clickhouse/clickhouse-client-0.8/javaagent/build.gradle.kts
Outdated
Show resolved
Hide resolved
...o/opentelemetry/javaagent/instrumentation/clickhouse/v0_8/ClickHouseClientV2QueryAdvice.java
Outdated
Show resolved
Hide resolved
instrumentation/clickhouse/clickhouse-client-common/javaagent/build.gradle.kts
Outdated
Show resolved
Hide resolved
...io/opentelemetry/javaagent/instrumentation/clickhouse/common/ClickHouseAttributesGetter.java
Show resolved
Hide resolved
import net.bytebuddy.asm.Advice; | ||
|
||
@SuppressWarnings("unused") | ||
public class ClickHouseClientV1ExecuteAndWaitAdvice { |
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.
usually we keep advice classes as nested classes of the instrumentation class
|
||
import io.opentelemetry.instrumentation.api.semconv.network.ServerAttributesGetter; | ||
|
||
final class ClickHouseNetworkAttributesGetter | ||
public final class ClickHouseNetworkAttributesGetter |
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.
is this class used outside of the package it is in?
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 no, ClickHouseNetworkAttributesGetter is only used inside of the package, public accessor is not needed.
String endPoint = client.getEndpoints().stream().findFirst().orElse(null); | ||
String host = null; | ||
int port = 0; | ||
|
||
if (endPoint != null) { | ||
URI uri = URI.create(endPoint); | ||
host = uri.getHost(); | ||
port = uri.getPort(); | ||
} |
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.
Generally the semantic conventions require that attributes correspond to the server that was connected. If the api allows specifying multiple servers you will need to determine the exact server that was used or not fill the attribute at all. Please verify that what you are doing here is correct. Also note that usually we use https://github.com/open-telemetry/opentelemetry-java-instrumentation/blob/main/instrumentation-api-incubator/src/main/java/io/opentelemetry/instrumentation/api/incubator/semconv/net/internal/UrlParser.java to parse urls.
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 The Client class is using the first endpoint of the connected endpoints to send its request. If it would be nice, it's possible to use getNextAliveNode
method of the Client class to get the valid endpoint, but their methods are mostly private, there are no public methods to do that. Instead I emulated its private method to get the endpoint.
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.
https://clickhouse.com/docs/integrations/language-clients/java/client says Currently only one endpoint is supported
You could add a comment about that.
dbName, | ||
host, | ||
port, |
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.
since these are always the same you could have an override for attributeAssertions
that takes the 2 parameters that change and calls the attributeAssertions
that takes 5 parameters
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 If we follow your suggestion, the code would need to be changed as below:
public final class ClickHouseAttributeAssertions {
private static String dbName;
private static String host;
private static int port;
public static void init(String dbName, String host, int port) {
ClickHouseAttributeAssertions.dbName = dbName;
ClickHouseAttributeAssertions.host = host;
ClickHouseAttributeAssertions.port = port;
}
public static List<AttributeAssertion> attributeAssertions(String statement, String operation) {
return attributeAssertions(dbName, host, port, statement, operation);
}
public static List<AttributeAssertion> attributeAssertions(
String dbName, String host, int port, String statement, String operation) {
return ...
}
private ClickHouseAttributeAssertions() {}
}
However, if we write the code like this, we have to call the init
method before the test code starts to set dbName
, host
, and port
into the ClickHouseAttributeAssertions
static variables.
This adds an extra step that must be performed before using attributeAssertions
method, which makes it a bit cumbersome.
instrumentation/clickhouse/clickhouse-clientv2-0.8/javaagent/build.gradle.kts
Outdated
Show resolved
Hide resolved
…uild.gradle.kts Co-authored-by: Jay DeLuca <[email protected]>
Since many variables in
Client
class are private, it wasn’t possible to extract the exact insert query from theinsert
method todb.statement
, so I did not implementinput
method tracing.Since ClickHouse Java Client 0.8, the V2 interface seems to have stabilized, so I assumed support beginning with 0.8.
For the V1, tracing can still be achieved through the existing ClickHouse instrumentation.
resolve #14364