Skip to content

Commit

Permalink
Fix downstream kamon instrumentation (#1489)
Browse files Browse the repository at this point in the history
* add @noinline annotation to MessageBuffer.Node.apply

* add @noinline annotation to Envelope.copy

* add overriding defn of copy with @noinline annotation to ThreadPoolConfig

* add comments
  • Loading branch information
hughsimpson authored Sep 21, 2024
1 parent 6ceb59b commit c3999a0
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ import com.typesafe.config.Config

final case class Envelope private (message: Any, sender: ActorRef) {

@noinline // not inlined to permit downstream bytecode instrumentation to attach context information to the Envelope
def copy(message: Any = message, sender: ActorRef = sender) = {
Envelope(message, sender)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,19 @@ final case class ThreadPoolConfig(
queueFactory: ThreadPoolConfig.QueueFactory = ThreadPoolConfig.linkedBlockingQueue(),
rejectionPolicy: RejectedExecutionHandler = ThreadPoolConfig.defaultRejectionPolicy)
extends ExecutorServiceFactoryProvider {
// Written explicitly to permit non-inlined defn; this is necessary for downstream instrumentation that stores extra
// context information on the config
@noinline
def copy(
allowCorePoolTimeout: Boolean = allowCorePoolTimeout,
corePoolSize: Int = corePoolSize,
maxPoolSize: Int = maxPoolSize,
threadTimeout: Duration = threadTimeout,
queueFactory: ThreadPoolConfig.QueueFactory = queueFactory,
rejectionPolicy: RejectedExecutionHandler = rejectionPolicy
): ThreadPoolConfig =
ThreadPoolConfig(allowCorePoolTimeout, corePoolSize, maxPoolSize, threadTimeout, queueFactory, rejectionPolicy)

class ThreadPoolExecutorServiceFactory(val threadFactory: ThreadFactory) extends ExecutorServiceFactory {
def createExecutorService: ExecutorService = {
val service: ThreadPoolExecutor = new ThreadPoolExecutor(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,7 @@ final class MessageBuffer private (private var _head: MessageBuffer.Node, privat

object MessageBuffer {
private final class Node(var next: Node, val message: Any, val ref: ActorRef) {
@noinline // not inlined to permit downstream bytecode instrumentation to apply context information on the Node to the message
def apply(f: (Any, ActorRef) => Unit): Unit = {
f(message, ref)
}
Expand Down

0 comments on commit c3999a0

Please sign in to comment.