|
23 | 23 | import co.elastic.clients.transport.TransportOptions;
|
24 | 24 | import co.elastic.clients.transport.http.TransportHttpClient;
|
25 | 25 |
|
| 26 | +/** |
| 27 | + * Instrumentation for an Elasticsearch client. It allows creating a {@link Instrumentation.Context} for each request, |
| 28 | + * with callbacks for the various stages of request and response processing. |
| 29 | + */ |
26 | 30 | public interface Instrumentation {
|
27 | 31 |
|
| 32 | + /** |
| 33 | + * Create a context for a given request and the corresponding endpoint. |
| 34 | + */ |
28 | 35 | <TRequest> Context newContext(TRequest request, Endpoint<TRequest, ?, ?> endpoint);
|
29 | 36 |
|
| 37 | + /** |
| 38 | + * A context with lifecycle callbacks for the various stages of request and response processing. Must be {@link #close()}d. |
| 39 | + */ |
30 | 40 | interface Context extends AutoCloseable {
|
| 41 | + |
| 42 | + /** |
| 43 | + * Sets this context (or the underlying abstraction) as the current thread's scope, so that neste call can |
| 44 | + * nest child contexts. |
| 45 | + */ |
31 | 46 | ThreadScope makeCurrent();
|
32 | 47 |
|
| 48 | + /** |
| 49 | + * Called once the initial API request has been serialized and the http request has been prepared. |
| 50 | + */ |
33 | 51 | void beforeSendingHttpRequest(TransportHttpClient.Request httpRequest, TransportOptions options);
|
| 52 | + |
| 53 | + /** |
| 54 | + * Called after the http response has been received, and before analyzing it. |
| 55 | + */ |
34 | 56 | void afterReceivingHttpResponse(TransportHttpClient.Response httpResponse);
|
| 57 | + |
| 58 | + /** |
| 59 | + * Called after the http response has been deserialized |
| 60 | + */ |
35 | 61 | <TResponse> void afterDecodingApiResponse(TResponse apiResponse);
|
| 62 | + |
| 63 | + /** |
| 64 | + * Called when any stage of request processing caused a failure. |
| 65 | + */ |
36 | 66 | void recordException(Throwable thr);
|
37 | 67 |
|
38 | 68 | @Override
|
39 | 69 | void close();
|
40 | 70 | }
|
41 | 71 |
|
| 72 | + /** |
| 73 | + * A thread scope. Closing it will detach the scope from the current thread. |
| 74 | + */ |
42 | 75 | interface ThreadScope extends AutoCloseable {
|
43 | 76 | @Override
|
44 | 77 | void close();
|
|
0 commit comments