Skip to content
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

WIP: Migrate es-restclient to indy plugin #1356

Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -22,12 +22,11 @@
* under the License.
* #L%
*/
package co.elastic.apm.agent.es.restclient.v5_6;
package co.elastic.apm.agent.esrestclient5_6;

import co.elastic.apm.agent.bci.VisibleForAdvice;
import co.elastic.apm.agent.es.restclient.ElasticsearchRestClientInstrumentation;
import co.elastic.apm.agent.es.restclient.ElasticsearchRestClientInstrumentationHelper;
import co.elastic.apm.agent.impl.ElasticApmTracer;
import co.elastic.apm.agent.esrestclient.ElasticsearchRestClientInstrumentation;
import co.elastic.apm.agent.esrestclient.ElasticsearchRestClientInstrumentationHelper;
import co.elastic.apm.agent.impl.transaction.AbstractSpan;
import co.elastic.apm.agent.impl.transaction.Span;
import co.elastic.apm.agent.sdk.advice.AssignTo;
import co.elastic.apm.agent.sdk.state.GlobalThreadLocal;
@@ -36,7 +35,6 @@
import net.bytebuddy.description.type.TypeDescription;
import net.bytebuddy.matcher.ElementMatcher;
import org.apache.http.HttpEntity;
import org.elasticsearch.client.Response;
import org.elasticsearch.client.ResponseListener;

import javax.annotation.Nullable;
@@ -49,10 +47,6 @@

public class ElasticsearchClientAsyncInstrumentation extends ElasticsearchRestClientInstrumentation {

public ElasticsearchClientAsyncInstrumentation(ElasticApmTracer tracer) {
super(tracer);
}

@Override
public Class<?> getAdviceClass() {
return ElasticsearchRestClientAsyncAdvice.class;
@@ -77,27 +71,25 @@ public ElementMatcher<? super MethodDescription> getMethodMatcher() {


public static class ElasticsearchRestClientAsyncAdvice {
@VisibleForAdvice
public static ElasticsearchRestClientInstrumentationHelper helper = new ElasticsearchRestClientInstrumentationHelper();
public static final GlobalThreadLocal<Span> spanTls = GlobalThreadLocal.get(ElasticsearchRestClientAsyncAdvice.class, "spanTls");

@AssignTo.Argument(5)
@Advice.OnMethodEnter(suppress = Throwable.class)
@Advice.OnMethodEnter(suppress = Throwable.class, inline = false)
public static ResponseListener onBeforeExecute(@Advice.Argument(0) String method,
@Advice.Argument(1) String endpoint,
@Advice.Argument(3) @Nullable HttpEntity entity,
@Advice.Argument(5) ResponseListener responseListener) {

ElasticsearchRestClientInstrumentationHelper<HttpEntity, Response, ResponseListener> helper = esClientInstrHelperManager.getForClassLoaderOfClass(Response.class);
if (helper != null) {
Span span = helper.createClientSpan(method, endpoint, entity);
spanTls.set(span);
if (span != null) {
return helper.<ResponseListener>wrapResponseListener(responseListener, span);
}
AbstractSpan<?> activeSpan = tracer.getActive();
Span span = helper.createClientSpan(activeSpan, method, endpoint, entity);
spanTls.set(span);
if (span != null) {
return helper.<ResponseListener>wrapResponseListener(responseListener, span);
}
return responseListener;
}

@Advice.OnMethodExit(suppress = Throwable.class, onThrowable = Throwable.class)
@Advice.OnMethodExit(suppress = Throwable.class, onThrowable = Throwable.class, inline = false)
public static void onAfterExecute(@Advice.Thrown @Nullable Throwable t) {
final Span span = spanTls.getAndRemove();
if (span != null) {
Original file line number Diff line number Diff line change
@@ -22,19 +22,17 @@
* under the License.
* #L%
*/
package co.elastic.apm.agent.es.restclient.v5_6;
package co.elastic.apm.agent.esrestclient5_6;

import co.elastic.apm.agent.es.restclient.ElasticsearchRestClientInstrumentation;
import co.elastic.apm.agent.es.restclient.ElasticsearchRestClientInstrumentationHelper;
import co.elastic.apm.agent.impl.ElasticApmTracer;
import co.elastic.apm.agent.esrestclient.ElasticsearchRestClientInstrumentation;
import co.elastic.apm.agent.esrestclient.ElasticsearchRestClientInstrumentationHelper;
import co.elastic.apm.agent.impl.transaction.Span;
import net.bytebuddy.asm.Advice;
import net.bytebuddy.description.method.MethodDescription;
import net.bytebuddy.description.type.TypeDescription;
import net.bytebuddy.matcher.ElementMatcher;
import org.apache.http.HttpEntity;
import org.elasticsearch.client.Response;
import org.elasticsearch.client.ResponseListener;

import javax.annotation.Nullable;

@@ -46,31 +44,28 @@

public class ElasticsearchClientSyncInstrumentation extends ElasticsearchRestClientInstrumentation {

public ElasticsearchClientSyncInstrumentation(ElasticApmTracer tracer) {
super(tracer);
@Override
public Class<?> getAdviceClass() {
return ElasticsearchRestClientAdvice.class;
}

public static class ElasticsearchRestClientAdvice {
public static ElasticsearchRestClientInstrumentationHelper helper = new ElasticsearchRestClientInstrumentationHelper();

@Nullable
@Advice.OnMethodEnter(suppress = Throwable.class)
public static Span onBeforeExecute(@Advice.Argument(0) String method,
@Advice.Argument(1) String endpoint,
@Advice.Argument(3) @Nullable HttpEntity entity) {
ElasticsearchRestClientInstrumentationHelper<HttpEntity, Response, ResponseListener> helper =
esClientInstrHelperManager.getForClassLoaderOfClass(Response.class);
if (helper == null) {
return null;
}
return helper.createClientSpan(method, endpoint, entity);
@Advice.OnMethodEnter(suppress = Throwable.class, inline = false)
public static Object onBeforeExecute(@Advice.Argument(0) String method,
@Advice.Argument(1) String endpoint,
@Advice.Argument(3) @Nullable HttpEntity entity) {
return helper.createClientSpan(tracer.getActive(), method, endpoint, entity);
}

@Advice.OnMethodExit(suppress = Throwable.class, onThrowable = Throwable.class)
@Advice.OnMethodExit(suppress = Throwable.class, onThrowable = Throwable.class, inline = false)
public static void onAfterExecute(@Advice.Return @Nullable Response response,
@Advice.Enter @Nullable Span span,
@Advice.Enter @Nullable Object objSpan,
@Advice.Thrown @Nullable Throwable t) {
ElasticsearchRestClientInstrumentationHelper<HttpEntity, Response, ResponseListener> helper =
esClientInstrHelperManager.getForClassLoaderOfClass(Response.class);
if (helper != null && span != null) {
if (objSpan instanceof Span) {
Span span = (Span) objSpan;
try {
helper.finishClientSpan(response, span, t);
} finally {
@@ -80,11 +75,6 @@ public static void onAfterExecute(@Advice.Return @Nullable Response response,
}
}

@Override
public Class<?> getAdviceClass() {
return ElasticsearchRestClientAdvice.class;
}

@Override
public ElementMatcher<? super TypeDescription> getTypeMatcher() {
return named("org.elasticsearch.client.RestClient").
Original file line number Diff line number Diff line change
@@ -23,6 +23,6 @@
* #L%
*/
@NonnullApi
package co.elastic.apm.agent.es.restclient.v6_4;
package co.elastic.apm.agent.esrestclient5_6;

import co.elastic.apm.agent.sdk.NonnullApi;
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
co.elastic.apm.agent.es.restclient.v5_6.ElasticsearchClientSyncInstrumentation
co.elastic.apm.agent.es.restclient.v5_6.ElasticsearchClientAsyncInstrumentation
co.elastic.apm.agent.esrestclient5_6.ElasticsearchClientSyncInstrumentation
co.elastic.apm.agent.esrestclient5_6.ElasticsearchClientAsyncInstrumentation
Original file line number Diff line number Diff line change
@@ -22,9 +22,9 @@
* under the License.
* #L%
*/
package co.elastic.apm.agent.es.restclient.v5_6;
package co.elastic.apm.agent.esrestclient5_6;

import co.elastic.apm.agent.es.restclient.AbstractEsClientInstrumentationTest;
import co.elastic.apm.agent.esrestclient.AbstractEsClientInstrumentationTest;
import co.elastic.apm.agent.impl.transaction.Span;
import org.apache.http.HttpHost;
import org.apache.http.auth.AuthScope;
Original file line number Diff line number Diff line change
@@ -22,22 +22,18 @@
* under the License.
* #L%
*/
package co.elastic.apm.agent.es.restclient.v6_4;
package co.elastic.apm.agent.esrestclient6_4;

import co.elastic.apm.agent.bci.VisibleForAdvice;
import co.elastic.apm.agent.es.restclient.ElasticsearchRestClientInstrumentation;
import co.elastic.apm.agent.es.restclient.ElasticsearchRestClientInstrumentationHelper;
import co.elastic.apm.agent.impl.ElasticApmTracer;
import co.elastic.apm.agent.esrestclient.ElasticsearchRestClientInstrumentation;
import co.elastic.apm.agent.esrestclient.ElasticsearchRestClientInstrumentationHelper;
import co.elastic.apm.agent.impl.transaction.Span;
import co.elastic.apm.agent.sdk.advice.AssignTo;
import co.elastic.apm.agent.sdk.state.GlobalThreadLocal;
import net.bytebuddy.asm.Advice;
import net.bytebuddy.description.method.MethodDescription;
import net.bytebuddy.description.type.TypeDescription;
import net.bytebuddy.matcher.ElementMatcher;
import org.apache.http.HttpEntity;
import org.elasticsearch.client.Request;
import org.elasticsearch.client.Response;
import org.elasticsearch.client.ResponseListener;

import javax.annotation.Nullable;
@@ -48,10 +44,6 @@

public class ElasticsearchClientAsyncInstrumentation extends ElasticsearchRestClientInstrumentation {

public ElasticsearchClientAsyncInstrumentation(ElasticApmTracer tracer) {
super(tracer);
}

@Override
public Class<?> getAdviceClass() {
return ElasticsearchRestClientAsyncAdvice.class;
@@ -71,25 +63,22 @@ public ElementMatcher<? super MethodDescription> getMethodMatcher() {
}

public static class ElasticsearchRestClientAsyncAdvice {
@VisibleForAdvice
public static ElasticsearchRestClientInstrumentationHelper helper = new ElasticsearchRestClientInstrumentationHelper();
public static final GlobalThreadLocal<Span> spanTls = GlobalThreadLocal.get(ElasticsearchRestClientAsyncAdvice.class, "spanTls");

@AssignTo.Argument(1)
@Advice.OnMethodEnter(suppress = Throwable.class)
@Advice.OnMethodEnter(suppress = Throwable.class, inline = false)
public static ResponseListener onBeforeExecute(@Advice.Argument(0) Request request,
@Advice.Argument(1) ResponseListener responseListener) {
ElasticsearchRestClientInstrumentationHelper<HttpEntity, Response, ResponseListener> helper = esClientInstrHelperManager.getForClassLoaderOfClass(Request.class);
if (helper != null) {
Span span = helper.createClientSpan(request.getMethod(), request.getEndpoint(), request.getEntity());
if (span != null) {
spanTls.set(span);
return helper.<ResponseListener>wrapResponseListener(responseListener, span);
}
Span span = helper.createClientSpan(tracer.getActive(), request.getMethod(), request.getEndpoint(), request.getEntity());
if (span != null) {
spanTls.set(span);
return helper.<ResponseListener>wrapResponseListener(responseListener, span);
}
return responseListener;
}

@Advice.OnMethodExit(suppress = Throwable.class, onThrowable = Throwable.class)
@Advice.OnMethodExit(suppress = Throwable.class, onThrowable = Throwable.class, inline = false)
public static void onAfterExecute(@Advice.Thrown @Nullable Throwable t) {
final Span span = spanTls.getAndRemove();
if (span != null) {
Original file line number Diff line number Diff line change
@@ -22,20 +22,17 @@
* under the License.
* #L%
*/
package co.elastic.apm.agent.es.restclient.v6_4;
package co.elastic.apm.agent.esrestclient6_4;

import co.elastic.apm.agent.es.restclient.ElasticsearchRestClientInstrumentation;
import co.elastic.apm.agent.es.restclient.ElasticsearchRestClientInstrumentationHelper;
import co.elastic.apm.agent.impl.ElasticApmTracer;
import co.elastic.apm.agent.esrestclient.ElasticsearchRestClientInstrumentation;
import co.elastic.apm.agent.esrestclient.ElasticsearchRestClientInstrumentationHelper;
import co.elastic.apm.agent.impl.transaction.Span;
import net.bytebuddy.asm.Advice;
import net.bytebuddy.description.method.MethodDescription;
import net.bytebuddy.description.type.TypeDescription;
import net.bytebuddy.matcher.ElementMatcher;
import org.apache.http.HttpEntity;
import org.elasticsearch.client.Request;
import org.elasticsearch.client.Response;
import org.elasticsearch.client.ResponseListener;

import javax.annotation.Nullable;

@@ -45,10 +42,6 @@

public class ElasticsearchClientSyncInstrumentation extends ElasticsearchRestClientInstrumentation {

public ElasticsearchClientSyncInstrumentation(ElasticApmTracer tracer) {
super(tracer);
}

@Override
public Class<?> getAdviceClass() {
return ElasticsearchRestClientSyncAdvice.class;
@@ -67,25 +60,20 @@ public ElementMatcher<? super MethodDescription> getMethodMatcher() {
}

public static class ElasticsearchRestClientSyncAdvice {
@Nullable
@Advice.OnMethodEnter(suppress = Throwable.class)
public static Span onBeforeExecute(@Advice.Argument(0) Request request) {
public static ElasticsearchRestClientInstrumentationHelper helper = new ElasticsearchRestClientInstrumentationHelper();

ElasticsearchRestClientInstrumentationHelper<HttpEntity, Response, ResponseListener> helper =
esClientInstrHelperManager.getForClassLoaderOfClass(Request.class);
if (helper == null) {
return null;
}
return helper.createClientSpan(request.getMethod(), request.getEndpoint(), request.getEntity());
@Nullable
@Advice.OnMethodEnter(suppress = Throwable.class, inline = false)
public static Object onBeforeExecute(@Advice.Argument(0) Request request) {
return helper.createClientSpan(tracer.getActive(), request.getMethod(), request.getEndpoint(), request.getEntity());
}

@Advice.OnMethodExit(suppress = Throwable.class, onThrowable = Throwable.class)
@Advice.OnMethodExit(suppress = Throwable.class, onThrowable = Throwable.class, inline = false)
public static void onAfterExecute(@Advice.Return @Nullable Response response,
@Advice.Enter @Nullable Span span,
@Advice.Enter @Nullable Object spanObj,
@Advice.Thrown @Nullable Throwable t) {
ElasticsearchRestClientInstrumentationHelper<HttpEntity, Response, ResponseListener> helper =
esClientInstrHelperManager.getForClassLoaderOfClass(Request.class);
if (helper != null && span != null) {
if (spanObj instanceof Span) {
Span span = (Span) spanObj;
try {
helper.finishClientSpan(response, span, t);
} finally {
Original file line number Diff line number Diff line change
@@ -23,6 +23,6 @@
* #L%
*/
@NonnullApi
package co.elastic.apm.agent.es.restclient.v5_6;
package co.elastic.apm.agent.esrestclient6_4;

import co.elastic.apm.agent.sdk.NonnullApi;
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
co.elastic.apm.agent.es.restclient.v6_4.ElasticsearchClientSyncInstrumentation
co.elastic.apm.agent.es.restclient.v6_4.ElasticsearchClientAsyncInstrumentation
co.elastic.apm.agent.esrestclient6_4.ElasticsearchClientSyncInstrumentation
co.elastic.apm.agent.esrestclient6_4.ElasticsearchClientAsyncInstrumentation
Original file line number Diff line number Diff line change
@@ -22,9 +22,9 @@
* under the License.
* #L%
*/
package co.elastic.apm.agent.es.restclient.v6_4;
package co.elastic.apm.agent.esrestclient6_4;

import co.elastic.apm.agent.es.restclient.AbstractEsClientInstrumentationTest;
import co.elastic.apm.agent.esrestclient.AbstractEsClientInstrumentationTest;
import co.elastic.apm.agent.impl.transaction.Span;
import org.elasticsearch.ElasticsearchStatusException;
import org.elasticsearch.action.ActionListener;
Original file line number Diff line number Diff line change
@@ -22,7 +22,7 @@
* under the License.
* #L%
*/
package co.elastic.apm.agent.es.restclient.v6_4;
package co.elastic.apm.agent.esrestclient6_4;

import co.elastic.apm.agent.impl.transaction.Span;
import org.apache.http.HttpHost;
Original file line number Diff line number Diff line change
@@ -22,7 +22,7 @@
* under the License.
* #L%
*/
package co.elastic.apm.agent.es.restclient.v6_4;
package co.elastic.apm.agent.esrestclient6_4;

import co.elastic.apm.agent.bci.ElasticApmAgent;
import co.elastic.apm.agent.configuration.SpyConfiguration;
Original file line number Diff line number Diff line change
@@ -22,9 +22,9 @@
* under the License.
* #L%
*/
package co.elastic.apm.agent.es.restclient.v7_1;
package co.elastic.apm.agent.esrestclient7_1;

import co.elastic.apm.agent.es.restclient.v6_4.AbstractEs6_4ClientInstrumentationTest;
import co.elastic.apm.agent.esrestclient6_4.AbstractEs6_4ClientInstrumentationTest;
import co.elastic.apm.agent.impl.transaction.Span;
import org.apache.http.HttpHost;
import org.apache.http.impl.client.BasicCredentialsProvider;
Loading