Skip to content

Commit

Permalink
Move wrapRunnable to Tracer and avoid trace ref recycling
Browse files Browse the repository at this point in the history
  • Loading branch information
eyalkoren committed Dec 18, 2018
1 parent 159f368 commit 4457d4e
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -304,8 +304,8 @@ public void recycle(ErrorCapture error) {
errorPool.recycle(error);
}

public InScopeRunnableWrapper allocateRunnableWrapper() {
return runnableWrapperObjectPool.createInstance();
public Runnable wrapRunnable(Runnable delegate, AbstractSpan<?> span) {
return runnableWrapperObjectPool.createInstance().wrap(delegate, span);
}

public void recycle(InScopeRunnableWrapper wrapper) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,19 +36,15 @@ public class InScopeRunnableWrapper implements Runnable, Recyclable {
private Runnable delegate;
@Nullable
private AbstractSpan<?> span;
@Nullable
private ElasticApmTracer tracer;

private final ElasticApmTracer tracer;

InScopeRunnableWrapper(ElasticApmTracer tracer) {
this.tracer = tracer;
}

public InScopeRunnableWrapper wrap(Runnable delegate) {
public InScopeRunnableWrapper wrap(Runnable delegate, AbstractSpan<?> span) {
this.delegate = delegate;
return this;
}

public InScopeRunnableWrapper withScope(AbstractSpan<?> span) {
this.span = span;
return this;
}
Expand All @@ -75,7 +71,6 @@ public void run() {
if (span != null) {
span.deactivate();
}
//noinspection ConstantConditions
tracer.recycle(this);
} catch (Throwable throwable) {
try {
Expand All @@ -91,6 +86,5 @@ public void run() {
public void resetState() {
delegate = null;
span = null;
tracer = null;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -81,8 +81,6 @@ public Collection<String> getInstrumentationGroupNames() {

public interface AsyncContextAdviceHelper<T> {
void onExitStartAsync(T asyncContext);

Runnable wrapRunnable(Runnable delegate, Transaction transaction);
}

public static class StartAsyncInstrumentation extends AsyncInstrumentation {
Expand Down Expand Up @@ -174,7 +172,7 @@ private static void onEnterAsyncContextStart(@Advice.Argument(value = 0, readOnl
if (tracer != null) {
final Transaction transaction = tracer.currentTransaction();
if (transaction != null && runnable != null && asyncHelper != null) {
runnable = asyncHelper.getForClassLoaderOfClass(AsyncContext.class).wrapRunnable(runnable, transaction);
runnable = tracer.wrapRunnable(runnable, transaction);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,9 +60,4 @@ public void onExitStartAsync(AsyncContext asyncContext) {
asyncContext.getRequest(), asyncContext.getResponse());
}
}

@Override
public Runnable wrapRunnable(Runnable delegate, Transaction transaction) {
return tracer.allocateRunnableWrapper().wrap(delegate).withScope(transaction);
}
}

0 comments on commit 4457d4e

Please sign in to comment.