-
Notifications
You must be signed in to change notification settings - Fork 28
Description
Hi!
I'm playing with kamon-http4s again and I'm trying to wrap the blaze client with the middleware. Unfortunately, my context gets lost at the point Blaze creates a connection. I tracked it down to here:
//ClientChannelFactory.scala, blaze-core 0.14.11
def connect(
remoteAddress: SocketAddress,
bufferSize: Int = bufferSize): Future[HeadStage[ByteBuffer]] = {
val p = Promise[HeadStage[ByteBuffer]]
try {
val ch = AsynchronousSocketChannel.open(group.orNull)
val onTimeout = //...
val scheduledTimeout = scheduler.schedule(onTimeout, connectTimeout)
val completionHandler = new CompletionHandler[Void, Null] {
//...
def completed(result: Void, attachment: Null): Unit = {
channelOptions.applyToChannel(ch)
p.trySuccess(new ByteBufferHead(ch, bufferSize = bufferSize))
scheduledTimeout.cancel()
}
}
try {
ch.connect(remoteAddress, null: Null, completionHandler)
} catch {
//...
}
} catch { case NonFatal(t) => p.tryFailure(t) }
p.future
}As far as I understand, the context should somehow be passed to the completion handler at instantiation time and restored in def completed, before completing the promise (then the further transformations on the future would also have the context, which they don't - so even though all the tracing information is in the request thanks to the middleware, the Kamon context has no span after any client call).
Can this be done somehow through the configuration of the agent, or would it require special treatment in blaze (e.g. being able to inject a method that creates the completion handler)?