Skip to content

Commit 971b171

Browse files
committed
Fix was not finishing span when it was dropped
1 parent 9f185cb commit 971b171

4 files changed

Lines changed: 8 additions & 6 deletions

File tree

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,7 @@ val transaction = Sentry.startTransaction("name", "op", TransactionOptions().app
9494
- This prevents issues when using the SDK on older AGP versions (< 4.x.x)
9595
- Reduce main thread work on init ([#3036](https://github.com/getsentry/sentry-java/pull/3036))
9696
- Move Integrations registration to background on init ([#3043](https://github.com/getsentry/sentry-java/pull/3043))
97+
- Fix `SentryOkHttpInterceptor.BeforeSpanCallback` was not finishing span when it was dropped ([#2958](https://github.com/getsentry/sentry-java/pull/2958))
9798

9899
## 6.34.0
99100

sentry-android-okhttp/src/main/java/io/sentry/android/okhttp/SentryOkHttpInterceptor.kt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,8 @@ class SentryOkHttpInterceptor(
4141
) : Interceptor by io.sentry.okhttp.SentryOkHttpInterceptor(
4242
hub,
4343
{ span, request, response ->
44-
beforeSpan?.execute(span, request, response)
44+
beforeSpan ?: return@SentryOkHttpInterceptor span
45+
beforeSpan.execute(span, request, response)
4546
},
4647
captureFailedRequests,
4748
failedRequestStatusCodes,

sentry-okhttp/src/main/java/io/sentry/okhttp/SentryOkHttpInterceptor.kt

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -169,11 +169,10 @@ public open class SentryOkHttpInterceptor(
169169
if (result == null) {
170170
// span is dropped
171171
span.spanContext.sampled = false
172-
} else {
173-
// The SentryOkHttpEventListener will finish the span itself if used for this call
174-
if (!isFromEventListener) {
175-
span.finish()
176-
}
172+
}
173+
// The SentryOkHttpEventListener will finish the span itself if used for this call
174+
if (!isFromEventListener) {
175+
span.finish()
177176
}
178177
} else {
179178
// The SentryOkHttpEventListener will finish the span itself if used for this call

sentry-okhttp/src/test/java/io/sentry/okhttp/SentryOkHttpInterceptorTest.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -371,6 +371,7 @@ class SentryOkHttpInterceptorTest {
371371
)
372372
sut.newCall(getRequest()).execute()
373373
val httpClientSpan = fixture.sentryTracer.children.first()
374+
assertTrue(httpClientSpan.isFinished)
374375
assertNotNull(httpClientSpan.spanContext.sampled) {
375376
assertFalse(it)
376377
}

0 commit comments

Comments
 (0)