elastic / elastic/apm-agent-java
Get user in ElasticSearch REST client instrumentation
- Dominant language
- Java
- Stars
- 594
- Forks
- 338
- Avg merge
- 1d 13h
- Merged PRs (30d)
- 25
Description
The way I found to do that is through looking into some Apache HTTP internals. This info is stored at `org.apache.http.impl.nio.client.InternalHttpAsyncClient#credentialsProvider`.
One way to get it is in our current instrumentation of `org.elasticsearch.client.RestClient#performRequest(org.elasticsearch.client.Request)` through the `client` field (that needs to be casted to a specific Apache HTTP implementation):
The problem with this approach is that we will need to add very specific dependency on Apache HTTP client code to an ES client instrumentation. This means we need to take extra caution measures to make sure user code using ES client is not failing linkage because ES client changed HTTP client implementation (for example if while instrumenting the user class, ByteBuddy added a reference to a non-existing Apache HTTP client class to the constant pool).
Another option is to add a second instrumentation specific to Apache HTTP client (possibly at `org.apache.http.impl.nio.client.InternalHttpAsyncClient#execute()`) that will be invoked within the existing and active ES client span, to get the active span and just set the user:
This approach is probably much safer, we just need to see that it works out properly with async client requests as well (#263)
Contributor guide
Assessment
This issue has not been assessed yet.