@@ -39,6 +39,33 @@ import okhttp3.Response
3939 * .addInterceptor(SentryOkHttpInterceptor())
4040 * .build()
4141 * ```
42+ *
43+ * ## Delivery of [canceled]
44+ *
45+ * A wrapped [okhttp3.EventListener] is not guaranteed to receive every [canceled] callback.
46+ *
47+ * OkHttp creates its listener in the [okhttp3.Call] constructor and keeps it for the whole lifetime
48+ * of that call, so it may report [canceled] before [callStart] and after [callEnd]/[callFailed]. A
49+ * single [SentryOkHttpEventListener] instead serves every call of the client, so it can only bind a
50+ * wrapped listener to a call between [callStart] and the terminal [callEnd]/[callFailed] event.
51+ *
52+ * What that means for the wrapped listener:
53+ * - A listener passed as a single [okhttp3.EventListener] instance receives every [canceled]
54+ * callback. Such a listener is shared by all calls anyway, the same as OkHttp's own
55+ * `EventListener.asFactory()`, so it exists independently of that window.
56+ * - A listener created by an [okhttp3.EventListener.Factory] receives only the [canceled] callbacks
57+ * that fall between [callStart] and the terminal event. A cancellation reported outside that
58+ * window is not forwarded, because no listener is bound to the call, and creating one would give
59+ * that call a second listener and break the [okhttp3.EventListener.Factory] contract of one
60+ * listener per call.
61+ *
62+ * Cancellation is still observable in the common case: a call that is canceled before it runs fails
63+ * with `IOException("Canceled")`, which is reported through [callFailed]. A call canceled after it
64+ * has completed reports nothing, which matches [okhttp3.Call.cancel] being documented as a no-op
65+ * for a request that is already complete.
66+ *
67+ * Use `OkHttpClient.Builder.eventListenerFactory` with your own listener if you need every
68+ * cancellation, including the ones outside that window.
4269 */
4370@Suppress(" TooManyFunctions" )
4471public open class SentryOkHttpEventListener (
0 commit comments