Skip to content

Instantly share code, notes, and snippets.

@danmurphycp
danmurphycp / UseTransactionIdCapturingDispatcher.kt
Created February 16, 2022 21:15
Example implementation of useTransactionIdCapturingDispatcher to configure transaction id forwarding
import okhttp3.Dispatcher
import okhttp3.OkHttpClient
import org.slf4j.MDC
import java.util.concurrent.ExecutorService
import java.util.concurrent.Executors
public fun OkHttpClient.Builder.useTransactionIdCapturingDispatcher(
executorService: ExecutorService = Executors.newCachedThreadPool()
): OkHttpClient.Builder = dispatcher(
Dispatcher(TransactionContextCapturingExecutorService(executorService))