|
| 1 | +package com.newrelic.instrumentation.kotlin.coroutines_17; |
| 2 | + |
| 3 | +import com.newrelic.agent.bridge.AgentBridge; |
| 4 | +import com.newrelic.api.agent.NewRelic; |
| 5 | +import com.newrelic.api.agent.Token; |
| 6 | +import com.newrelic.api.agent.Trace; |
| 7 | + |
| 8 | +import kotlin.coroutines.Continuation; |
| 9 | +import kotlin.coroutines.CoroutineContext; |
| 10 | + |
| 11 | +public class NRContinuationWrapper<T> implements Continuation<T> { |
| 12 | + |
| 13 | + private Continuation<T> delegate = null; |
| 14 | + private String name = null; |
| 15 | + private static boolean isTransformed = false; |
| 16 | + |
| 17 | + public NRContinuationWrapper(Continuation<T> d, String n) { |
| 18 | + delegate = d; |
| 19 | + name = n; |
| 20 | + if(!isTransformed) { |
| 21 | + AgentBridge.instrumentation.retransformUninstrumentedClass(getClass()); |
| 22 | + isTransformed = true; |
| 23 | + } |
| 24 | + } |
| 25 | + |
| 26 | + @Override |
| 27 | + public CoroutineContext getContext() { |
| 28 | + return delegate.getContext(); |
| 29 | + } |
| 30 | + |
| 31 | + @Override |
| 32 | + @Trace(async=true) |
| 33 | + public void resumeWith(Object p0) { |
| 34 | + String contString = Utils.getContinuationString(delegate); |
| 35 | + if(contString != null && !contString.isEmpty()) { |
| 36 | + NewRelic.getAgent().getTracedMethod().setMetricName("Custom","ContinuationWrapper","resumeWith",contString); |
| 37 | + } else if(name != null) { |
| 38 | + NewRelic.getAgent().getTracedMethod().setMetricName("Custom","ContinuationWrapper","resumeWith",name); |
| 39 | + } else { |
| 40 | + NewRelic.getAgent().getTracedMethod().setMetricName("Custom","ContinuationWrapper","resumeWith",p0.getClass().getName()); |
| 41 | + } |
| 42 | + Token t = Utils.getToken(getContext()); |
| 43 | + if(t != null) { |
| 44 | + t.link(); |
| 45 | + } |
| 46 | + if(delegate != null) { |
| 47 | + delegate.resumeWith(p0); |
| 48 | + } |
| 49 | + } |
| 50 | + |
| 51 | +} |
0 commit comments