Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/main' into kw/fix-handling-hybri…
Browse files Browse the repository at this point in the history
…d-unhandled-exceptions
  • Loading branch information
krystofwoldrich committed Jun 27, 2024
2 parents e944901 + cb9b3f6 commit 6de823e
Show file tree
Hide file tree
Showing 8 changed files with 83 additions and 5 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/agp-matrix.yml
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ jobs:
**/build/outputs/mapping/release/*
- name: Test Report
uses: phoenix-actions/test-reporting@41efe7ebebe7ef156ef46f6b0acf50ec0f10315b # pin@v12
uses: phoenix-actions/test-reporting@f957cd93fc2d848d556fa0d03c57bc79127b6b5e # pin@v15
if: always()
with:
name: JUnit AGP ${{ matrix.agp }} - Integrations ${{ matrix.integrations }}
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ jobs:
**/build/reports/*
- name: Test Report
uses: phoenix-actions/test-reporting@41efe7ebebe7ef156ef46f6b0acf50ec0f10315b # pin@v12
uses: phoenix-actions/test-reporting@f957cd93fc2d848d556fa0d03c57bc79127b6b5e # pin@v15
if: always()
with:
name: JUnit Build
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/system-tests-backend.yml
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ jobs:
spring-server.txt
- name: Test Report
uses: phoenix-actions/test-reporting@41efe7ebebe7ef156ef46f6b0acf50ec0f10315b # pin@v12
uses: phoenix-actions/test-reporting@f957cd93fc2d848d556fa0d03c57bc79127b6b5e # pin@v15
if: always()
with:
name: JUnit System Tests ${{ matrix.sample }}
Expand Down
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
- Properly reset metric flush flag on metric emission ([#3493](https://github.com/getsentry/sentry-java/pull/3493))
- Use SecureRandom in favor of Random for Metrics ([#3495](https://github.com/getsentry/sentry-java/pull/3495))
- Fix UncaughtExceptionHandlerIntegration Memory Leak ([#3398](https://github.com/getsentry/sentry-java/pull/3398))
- Fix duplicated http spans ([#3526](https://github.com/getsentry/sentry-java/pull/3526))
- When capturing unhandled hybrid exception session should be ended and new start if need ([#3480](https://github.com/getsentry/sentry-java/pull/3480))

### Dependencies
Expand Down
4 changes: 3 additions & 1 deletion sentry-android-okhttp/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,9 @@ android {

buildTypes {
getByName("debug")
getByName("release")
getByName("release") {
consumerProguardFiles("proguard-rules.pro")
}
}

kotlinOptions {
Expand Down
2 changes: 2 additions & 0 deletions sentry-android-okhttp/proguard-rules.pro
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,5 @@
# https://raw.githubusercontent.com/square/okhttp/master/okhttp/src/jvmMain/resources/META-INF/proguard/okhttp3.pro

##---------------End: proguard configuration for OkHttp ----------
# We keep this name to avoid the sentry-okttp module to call the old listener multiple times
-keepnames class io.sentry.android.okhttp.SentryOkHttpEventListener
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
package io.sentry.android.okhttp

import io.sentry.IHub
import io.sentry.SentryOptions
import io.sentry.SentryTracer
import io.sentry.TransactionContext
import okhttp3.EventListener
import okhttp3.OkHttpClient
import okhttp3.Request
import okhttp3.mockwebserver.MockResponse
import okhttp3.mockwebserver.MockWebServer
import okhttp3.mockwebserver.SocketPolicy
import org.mockito.kotlin.mock
import org.mockito.kotlin.whenever
import kotlin.test.Test
import kotlin.test.assertEquals

@SuppressWarnings("Deprecated")
class SentryOkHttpEventListenerTest {

class Fixture {
val hub = mock<IHub>()
val server = MockWebServer()
lateinit var sentryTracer: SentryTracer

@SuppressWarnings("LongParameterList")
fun getSut(
eventListener: EventListener? = null
): OkHttpClient {
val options = SentryOptions().apply {
dsn = "https://key@sentry.io/proj"
}
whenever(hub.options).thenReturn(options)

sentryTracer = SentryTracer(TransactionContext("name", "op"), hub)
whenever(hub.span).thenReturn(sentryTracer)
server.enqueue(
MockResponse()
.setBody("responseBody")
.setSocketPolicy(SocketPolicy.KEEP_OPEN)
.setResponseCode(200)
)

val builder = OkHttpClient.Builder().addInterceptor(SentryOkHttpInterceptor(hub))
val sentryOkHttpEventListener = when {
eventListener != null -> SentryOkHttpEventListener(hub, eventListener)
else -> SentryOkHttpEventListener(hub)
}
return builder.eventListener(sentryOkHttpEventListener).build()
}
}

private val fixture = Fixture()

private fun getRequest(url: String = "/hello"): Request {
return Request.Builder()
.addHeader("myHeader", "myValue")
.get()
.url(fixture.server.url(url))
.build()
}

@Test
fun `when there are multiple SentryOkHttpEventListeners, they don't duplicate spans`() {
val sut = fixture.getSut(eventListener = SentryOkHttpEventListener(fixture.hub))
val call = sut.newCall(getRequest())
call.execute().close()
assertEquals(8, fixture.sentryTracer.children.size)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -406,6 +406,9 @@ public open class SentryOkHttpEventListener(

private fun canCreateEventSpan(): Boolean {
// If the wrapped EventListener is ours, we shouldn't create spans, as the originalEventListener already did it
return originalEventListener !is SentryOkHttpEventListener
// In case SentryOkHttpEventListener from sentry-android-okhttp is used, the is check won't work so we check
// for the class name as well.
return originalEventListener !is SentryOkHttpEventListener &&
"io.sentry.android.okhttp.SentryOkHttpEventListener" != originalEventListener?.javaClass?.name
}
}

0 comments on commit 6de823e

Please sign in to comment.