Skip to content

Commit ae6ec68

Browse files
committed
revert non-working OkHttp detection, and finish addressing Seer
1 parent 2aae940 commit ae6ec68

File tree

2 files changed

+4
-41
lines changed

2 files changed

+4
-41
lines changed

sentry-ktor-client/src/main/java/io/sentry/ktorClient/SentryKtorClientPlugin.kt

Lines changed: 3 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
package io.sentry.ktorClient
22

33
import io.ktor.client.HttpClient
4-
import io.ktor.client.engine.okhttp.OkHttpConfig
54
import io.ktor.client.plugins.api.*
65
import io.ktor.client.plugins.api.ClientPlugin
76
import io.ktor.client.request.*
@@ -79,17 +78,6 @@ internal const val TRACE_ORIGIN = "auto.http.ktor-client"
7978
*/
8079
public val SentryKtorClientPlugin: ClientPlugin<SentryKtorClientPluginConfig> =
8180
createClientPlugin(SENTRY_KTOR_CLIENT_PLUGIN_KEY, ::SentryKtorClientPluginConfig) {
82-
// If the engine is OkHttp and the OkHttp client is configured to use the SentryOkHttpInterceptor, any functionality of this plugin is disabled
83-
// Without this check, all HTTP requests would be doubly instrumented
84-
if (client.engine.config is OkHttpConfig) {
85-
val config = client.engine.config as OkHttpConfig
86-
var interceptors = config.preconfigured?.interceptors ?: emptyList()
87-
config.config { interceptors += this@config.interceptors() }
88-
if (interceptors.any { it.toString().contains("SentryOkHttpInterceptor") }) {
89-
return@createClientPlugin
90-
}
91-
}
92-
9381
// Init
9482
SentryIntegrationPackageStorage.getInstance()
9583
.addPackage("maven:io.sentry:sentry-ktor-client", BuildConfig.VERSION_NAME)
@@ -112,7 +100,7 @@ public val SentryKtorClientPlugin: ClientPlugin<SentryKtorClientPluginConfig> =
112100
onRequest { request, _ ->
113101
request.attributes.put(
114102
requestStartTimestampKey,
115-
Sentry.getCurrentScopes().options.dateProvider.now(),
103+
(if (forceScopes) scopes else Sentry.getCurrentScopes()).options.dateProvider.now(),
116104
)
117105

118106
val parentSpan: ISpan? =
@@ -168,7 +156,8 @@ public val SentryKtorClientPlugin: ClientPlugin<SentryKtorClientPluginConfig> =
168156
onResponse { response ->
169157
val request = response.request
170158
val startTimestamp = response.call.attributes.getOrNull(requestStartTimestampKey)
171-
val endTimestamp = Sentry.getCurrentScopes().options.dateProvider.now()
159+
val endTimestamp =
160+
(if (forceScopes) scopes else Sentry.getCurrentScopes()).options.dateProvider.now()
172161

173162
if (
174163
captureFailedRequests &&

sentry-ktor-client/src/test/java/io/sentry/ktorClient/SentryKtorClientPluginTest.kt

Lines changed: 1 addition & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,8 @@
11
package io.sentry.ktorClient
22

33
import io.ktor.client.HttpClient
4-
import io.ktor.client.HttpClientConfig
54
import io.ktor.client.engine.HttpClientEngine
65
import io.ktor.client.engine.java.Java
7-
import io.ktor.client.engine.okhttp.OkHttp
8-
import io.ktor.client.engine.okhttp.OkHttpConfig
9-
import io.ktor.client.engine.okhttp.OkHttpEngine
10-
import io.ktor.client.plugins.plugin
116
import io.ktor.client.request.get
127
import io.ktor.client.request.post
138
import io.ktor.client.request.setBody
@@ -31,10 +26,8 @@ import io.sentry.SpanStatus
3126
import io.sentry.TransactionContext
3227
import io.sentry.exception.SentryHttpClientException
3328
import io.sentry.mockServerRequestTimeoutMillis
34-
import io.sentry.okhttp.SentryOkHttpInterceptor
3529
import java.util.concurrent.TimeUnit
3630
import kotlin.test.Test
37-
import okhttp3.OkHttpClient
3831
import kotlin.test.assertEquals
3932
import kotlin.test.assertNotNull
4033
import kotlin.test.assertNull
@@ -378,7 +371,7 @@ class SentryKtorClientPluginTest {
378371
isSpanActive = false,
379372
optionsConfiguration = { options ->
380373
options.setIgnoredSpanOrigins(listOf("auto.http.ktor-client"))
381-
}
374+
},
382375
)
383376
sut.get(fixture.server.url("/hello").toString())
384377

@@ -432,23 +425,4 @@ class SentryKtorClientPluginTest {
432425
assertTrue(baggageHeaderValues[0].contains("sentry-transaction=name"))
433426
assertTrue(baggageHeaderValues[0].contains("sentry-trace_id"))
434427
}
435-
436-
@Test
437-
fun `is disabled when using OkHttp client with Sentry interceptor added to builder`() {
438-
val okHttpClient = OkHttpClient.Builder()
439-
.addInterceptor(SentryOkHttpInterceptor())
440-
.build()
441-
val engine = OkHttpEngine(OkHttpConfig().apply {
442-
preconfigured = okHttpClient
443-
})
444-
445-
val client = fixture.getSut(httpClientEngine = engine)
446-
val plugin = client.plugin(SentryKtorClientPlugin)
447-
}
448-
449-
@Test
450-
fun `is disabled when using preconfigured OkHttp client with Sentry interceptor`() {
451-
val engine = OkHttpEngine(OkHttpConfig())
452-
val client = fixture.getSut(httpClientEngine = engine)
453-
}
454428
}

0 commit comments

Comments
 (0)