-
Notifications
You must be signed in to change notification settings - Fork 327
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Attempt to handle the Dispatcher case
- Loading branch information
Showing
6 changed files
with
397 additions
and
27 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
35 changes: 35 additions & 0 deletions
35
...on-cats-io-3/src/main/java/kamon/instrumentation/cats3/CleanSchedulerContextAdvice35.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
package kamon.instrumentation.cats3; | ||
|
||
import kamon.Kamon; | ||
import kamon.context.Context; | ||
import kamon.context.Storage; | ||
import kanela.agent.libs.net.bytebuddy.asm.Advice; | ||
import scala.Function1; | ||
import scala.runtime.BoxedUnit; | ||
import scala.runtime.Nothing$; | ||
import scala.util.Right; | ||
|
||
public class CleanSchedulerContextAdvice35 { | ||
@Advice.OnMethodEnter | ||
public static void enter(@Advice.Argument(value = 1, readOnly = false) Function1<Right<Nothing$, BoxedUnit>, BoxedUnit> callback) { | ||
callback = new CleanSchedulerContextAdvice35.ContextCleaningWrapper(callback, Kamon.currentContext()); | ||
} | ||
|
||
|
||
public static class ContextCleaningWrapper implements Function1<Right<Nothing$, BoxedUnit>, BoxedUnit> { | ||
private final Function1<Right<Nothing$, BoxedUnit>, BoxedUnit> runnable; | ||
private final Context context; | ||
|
||
public ContextCleaningWrapper(Function1<Right<Nothing$, BoxedUnit>, BoxedUnit> runnable, Context context) { | ||
this.runnable = runnable; | ||
this.context = context; | ||
} | ||
|
||
@Override | ||
public BoxedUnit apply(Right<Nothing$, BoxedUnit> v1) { | ||
try (Storage.Scope ignored = Kamon.storeContext(context)) { | ||
return runnable.apply(v1); | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
41 changes: 41 additions & 0 deletions
41
instrumentation/kamon-cats-io-3/src/main/scala/cats/effect/kamonCats/PackageAccessor.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
package cats.effect.kamonCats | ||
|
||
import org.slf4j.LoggerFactory | ||
|
||
/** | ||
* Utility class to make accessing some internals from Kamon, more accessible. | ||
* | ||
*/ | ||
object PackageAccessor { | ||
|
||
private val LOG = LoggerFactory.getLogger(getClass) | ||
|
||
/** | ||
* This uses reflection to get the objectState, which acts like a stack | ||
* of effects so we can determine something about the lineage of a particular fiber. | ||
* | ||
* @param fiber A runnable or IOFiber | ||
* @return | ||
*/ | ||
def fiberObjectStackBuffer(fiber: Any): Array[AnyRef] = { | ||
try { | ||
val field = fiber.getClass.getDeclaredField("objectState") | ||
field.setAccessible(true) | ||
field.get(fiber).asInstanceOf[cats.effect.ArrayStack[AnyRef]].unsafeBuffer() | ||
} catch { | ||
case _: Exception => | ||
if (LOG.isWarnEnabled) | ||
LOG.warn("Unable to get the object stack buffer.") | ||
Array.empty | ||
} | ||
|
||
} | ||
|
||
/** This frankly kinda isn't great, but I couldn't figure out how to do this */ | ||
def isDispatcherWorker(obj: AnyRef): Boolean = { | ||
if (obj != null) | ||
obj.getClass.getName.contains("Dispatcher$Worker") | ||
else false | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.