If you've ever chased a mysterious 401 through a stack of five OkHttp interceptors, you know the pain: HttpLoggingInterceptor shows you the final request — but not which interceptor added, removed, or overwrote that header.
OkTrace fixes exactly that. It logs a diff at every step of the interceptor chain.
What you get
- 🔍 Per-interceptor diffs — headers added / removed / changed, URL rewrites, method changes, body changes
- ⏱️ Timings for each step plus total duration
- 📦 Programmatic access to traces via
OkTrace.store.entries - ⚙️ Configurable:
OkTrace.enabled,OkTrace.logTag,TraceStore.maxEntries
Diff legend:
| Symbol | Meaning |
|---|---|
+ | header added |
- | header removed |
~ | header / URL / body changed |
[pass-through] | interceptor changed nothing |
Example output
[1] AuthInterceptor · 2ms + Authorization: Bearer •••• [2] HeaderInterceptor · 0ms ~ User-Agent: okhttp → app/2.1 - X-Debug [3] RetryInterceptor · 0ms [pass-through] ← 200 OK · total 184ms Now you know instantly that HeaderInterceptor is the one stripping X-Debug.
Installation
Add JitPack in settings.gradle.kts:
maven { url = uri("https://jitpack.io") } Then the dependency:
implementation("com.github.NarendraKumar-2259:OkTrace:1.0.0") Usage
Put OkTrace.interceptor() first, then wrap each of your interceptors with observe():
val client = OkHttpClient.Builder() .addInterceptor(OkTrace.interceptor()) .addInterceptor(OkTrace.observe(AuthInterceptor())) .addInterceptor(OkTrace.observe(HeaderInterceptor())) .build() Enable it only for debug builds:
OkTrace.enabled = BuildConfig.DEBUG ⚠️ OkTrace logs request data (including auth headers), so keep it debug-only — never ship it enabled in production.
Try it & contribute
OkTrace is open source under Apache 2.0. If it saves you a debugging session, drop a ⭐ on the repo, open an issue, or send a PR:
👉 https://github.com/NarendraKumar-2259/OkTrace
What's the nastiest interceptor bug you've hunted down? Share it in the comments 👇

