open-telemetry / opentelemetry-java-instrumentation

OpenTelemetry auto-instrumentation and instrumentation libraries for Java

Home Page:https://opentelemetry.io

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Support Recording request size and response size in database span

pepeshore opened this issue · comments

Is your feature request related to a problem? Please describe.

Slow request problem caused by querying a large amount of data from the database.

Describe the solution you'd like

Slow request is sometimes caused by large queries, which can be addressed by adding the request size and response size to the client span for that request.
has a metric to record this is better

The request size refers to the number of bytes in the database query statement, and the response size refers to the number of bytes in the data returned by the database.

Describe alternatives you've considered

No response

Additional context

No response

When reading the issue title I thought that your ask is about http request and response size which we already have (not all instrumentations fill these). Reading the content it seems that your ask has something to do with databases. Could you clarify what exactly you are looking for. Which database (jdbc, mongo etc.). What do you mean by request and response size? Query length? Number of returned rows etc.

When reading the issue title I thought that your ask is about http request and response size which we already have (not all instrumentations fill these). Reading the content it seems that your ask has something to do with databases. Could you clarify what exactly you are looking for. Which database (jdbc, mongo etc.). What do you mean by request and response size? Query length? Number of returned rows etc.

I have updated my issue

Which database (jdbc, mongo etc.).

All database should support this feature, and I have an idea to instrument java.io.InputStream#read(byte[], int, int) to avoid modify all database instrumentation, how do you think of this idea

All database should support this feature

Then you should strive towards getting this added to the specification. I personally am not convinced that this would make sense for all databases, but could make sense for some. For example there already is db.cosmosdb.request_content_length.

and I have an idea to instrument java.io.InputStream#read(byte[], int, int) to avoid modify all database instrumentation

I suspect that this is going to be a bit more complicated. For many instrumentations we also offer a standalone library instrumentation that can't rely on something like this. For JDBC the full response might not be fetched right away https://docs.oracle.com/javase%2F7%2Fdocs%2Fapi%2F%2F/java/sql/Statement.html#setFetchSize(int) and the full response size may become known only after the result set is fully processed, but by that time our database span has already been ended.

Feel free to prototype this.

Then you should strive towards getting this added to the specification

ok

but by that time our database span has already been ended.

I previously overlooked this point; if that's the case, my idea indeed wouldn't work. I'll think it over again.