[client, jdbc] Auto-generate Query ID if absent
Description
Client and JDBC driver should generate Query ID if it is not set.
The main issue here is that API do not provide a good way to access queryId after execution. Also generating query may be useful while tracing - so we need to know it before sending the request.
InsertResponse and QueryResponse classes have #getQueryId() method.
However not every operation returns it.
In case of failure it should be propagated to the logging.
Client does retries. Should queryId be generated each time?
Hey! I just came across this issue as I was wondering why the queryId is not set as an attribute by the ClickHouse OTel Java Instrumentation. Is the instrumentation maintained by the same people as this repo?
Either way, if this is desired behaviour I would be willing to contribute.
Good day, @patschl ! The query ID is generated on server is missing in the request settings. This issue is more about adding query ID whenever it is useful while troubleshooting. For example, add MDC context so logger can use it. Or add it to error messages we produce. I have a PR for that.
Thanks for the fast response @chernser .
I guess this would make the instrumentation quite inconsistent if the query ID is not yet generated on the client side, but would anything else be a reason not to add this to the instrumentation?
So I should rather open a ticket/ask over at otel java instrumentation?
If query reached server then we will get query id in header and will provide in response object. Else query id doesn't make sense because it is not present on server. In this case good client exception should be thrown. However some API do not return response object and it is a problem.
You may use this issue to add requirements.
And sorry, I think, I did not get this part of the question :
but would anything else be a reason not to add this to the instrumentation?
Would you please tell more about what instrumentation are you looking for?
Thanks!
Sorry if my earlier explanation wasn’t clear enough.
I was talking about the OpenTelemetry Java instrumentation for clickhouse, which already exists here. It currently only captures basic attributes like database name, connection URL and the statement, but nothing clickhouse specific (like query ID).
I might have been wrong in the assumption that this was instrumentation was driven by the maintainers of this repository.
no worries, @patschl !
Thank you for pointing out - I was not aware of this. I will review what the project does and see if I can help here. Here is a separate issue https://github.com/ClickHouse/clickhouse-java/issues/2700
Nice. I am also willing to contribute if you can't find the time.
Sorry, one last question; I looked at the open PR for this issue. Do you plan to provide an implementation for the queryIdGenerator when using the JDBC Driver instead of the client?