Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@

### Fixes

- Prevent asynchronous scope propagation from retaining unbounded chains of historical scopes ([#6637](https://github.com/getsentry/sentry-java/pull/6637))
- Add opt-in support for matching GraphQL ignored error types against classification specifications via `sentry.graphql.enable-specification-error-type-filtering` ([#6092](https://github.com/getsentry/sentry-java/pull/6092))
- Session Replay: Fix `SentryOkHttpInterceptor` hanging forever on responses whose body has no known length, such as Server-Sent Events or a gzipped response, when network details are enabled for the URL ([#6231](https://github.com/getsentry/sentry-java/pull/6231))
- Session Replay: `SentryOkHttpInterceptor` now captures network request and response details only while Session Replay is recording or buffering ([#6486](https://github.com/getsentry/sentry-java/pull/6486))
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,31 @@
package io.sentry.opentelemetry

import com.google.common.truth.Truth.assertThat
import io.opentelemetry.api.trace.Span
import io.opentelemetry.api.trace.SpanContext
import io.opentelemetry.api.trace.TraceFlags
import io.opentelemetry.api.trace.TraceState
import io.opentelemetry.context.Context
import io.sentry.Scope
import io.sentry.Scopes
import io.sentry.Sentry
import io.sentry.SentryOptions
import io.sentry.opentelemetry.SentryOtelKeys.SENTRY_SCOPES_KEY
import junit.framework.TestCase.assertNull
import junit.framework.TestCase.assertTrue
import kotlin.test.AfterTest
import kotlin.test.Test
import org.mockito.kotlin.mock
import org.mockito.kotlin.whenever

class SentryContextWrapperTest {

@AfterTest
fun tearDown() {
SentryWeakSpanStorage.getInstance().clear()
Sentry.close()
}

@Test
fun `ensure noop scopes are not stored on Context`() {
val context = Context.root()
Expand All @@ -17,4 +34,34 @@ class SentryContextWrapperTest {
val wrappedContext = SentryContextWrapper.wrap(context)
assertNull(wrappedContext.get(SENTRY_SCOPES_KEY))
}

@Test
fun `uses span scopes when context scopes are the live weak parent`() {
val options = SentryOptions().apply { dsn = "https://key@sentry.io/proj" }
val rootScopes = Scopes(Scope(options), Scope(options), Scope(options), "root")
val contextScopes = rootScopes.forkedCurrentScope("context")
contextScopes.scope.setTag("source", "context")
val spanScopes = contextScopes.forkedCurrentScope("span")
spanScopes.scope.setTag("source", "span")

val spanContext =
SpanContext.create(
"f9118105af4a2d42b4124532cd1065ff",
"424cffc8f94feeee",
TraceFlags.getSampled(),
TraceState.getDefault(),
)
val span = Span.wrap(spanContext)
val sentrySpan = mock<IOtelSpanWrapper>()
whenever(sentrySpan.scopes).thenReturn(spanScopes)
SentryWeakSpanStorage.getInstance().storeSentrySpan(spanContext, sentrySpan)
val context = Context.root().with(SENTRY_SCOPES_KEY, contextScopes).with(span)

System.gc()
val wrappedContext = SentryContextWrapper.wrap(context)
val selectedScopes = wrappedContext.get(SENTRY_SCOPES_KEY)

assertThat(selectedScopes).isNotNull()
assertThat(selectedScopes!!.scope.tags["source"]).isEqualTo("span")
}
}
Original file line number Diff line number Diff line change
@@ -1,19 +1,31 @@
package io.sentry.spring7

import io.sentry.IScopes
import io.sentry.Sentry
import io.sentry.test.initForTest
import java.lang.ref.WeakReference
import java.util.concurrent.ExecutorService
import java.util.concurrent.Executors
import java.util.concurrent.TimeUnit
import kotlin.test.AfterTest
import kotlin.test.BeforeTest
import kotlin.test.Test
import kotlin.test.assertEquals
import kotlin.test.assertNotEquals
import kotlin.test.assertNull
import org.awaitility.kotlin.await

class SentryTaskDecoratorTest {
private val dsn = "http://key@localhost/proj"
private lateinit var executor: ExecutorService

private fun decorateFromChildScopes(): Pair<Runnable, WeakReference<IScopes>> {
val childScopes = Sentry.getCurrentScopes().forkedCurrentScope("child")
val decoratedRunnable =
childScopes.makeCurrent().use { SentryTaskDecorator().decorate(Runnable {}) }
return decoratedRunnable to WeakReference(childScopes)
}

@BeforeTest
fun beforeTest() {
executor = Executors.newSingleThreadExecutor()
Expand All @@ -25,6 +37,20 @@ class SentryTaskDecoratorTest {
executor.shutdown()
}

@Test
fun `decorated task does not strongly retain scheduling scopes`() {
initForTest { it.dsn = dsn }
val (decoratedRunnable, childReference) = decorateFromChildScopes()

await.atMost(5, TimeUnit.SECONDS).untilAsserted {
System.gc()
System.runFinalization()
assertNull(childReference.get())
}

decoratedRunnable.run()
}

@Test
fun `scopes is reset to its state within the thread after decoration is done`() {
initForTest { it.dsn = dsn }
Expand Down
Original file line number Diff line number Diff line change
@@ -1,21 +1,32 @@
package io.sentry.spring7.webflux

import io.sentry.IScopes
import io.sentry.Sentry
import io.sentry.test.initForTest
import java.lang.ref.WeakReference
import java.util.concurrent.ExecutorService
import java.util.concurrent.Executors
import java.util.concurrent.TimeUnit
import kotlin.test.AfterTest
import kotlin.test.BeforeTest
import kotlin.test.Test
import kotlin.test.assertEquals
import kotlin.test.assertFalse
import kotlin.test.assertNotEquals
import kotlin.test.assertNull
import kotlin.test.assertTrue
import org.awaitility.kotlin.await

class SentryScheduleHookTest {
private val dsn = "http://key@localhost/proj"
private lateinit var executor: ExecutorService

private fun applyHookFromChildScopes(): Pair<Runnable, WeakReference<IScopes>> {
val childScopes = Sentry.getCurrentScopes().forkedCurrentScope("child")
val wrappedRunnable = childScopes.makeCurrent().use { SentryScheduleHook().apply(Runnable {}) }
return wrappedRunnable to WeakReference(childScopes)
}

@BeforeTest
fun beforeTest() {
executor = Executors.newSingleThreadExecutor()
Expand Down Expand Up @@ -58,6 +69,20 @@ class SentryScheduleHookTest {
.get()
}

@Test
fun `wrapped task does not strongly retain scheduling scopes`() {
initForTest { it.dsn = dsn }
val (wrappedRunnable, childReference) = applyHookFromChildScopes()

await.atMost(5, TimeUnit.SECONDS).untilAsserted {
System.gc()
System.runFinalization()
assertNull(childReference.get())
}

wrappedRunnable.run()
}

@Test
fun `known maintenance runnable class names are excluded`() {
val classNames =
Expand Down
Original file line number Diff line number Diff line change
@@ -1,19 +1,31 @@
package io.sentry.spring.jakarta

import io.sentry.IScopes
import io.sentry.Sentry
import io.sentry.test.initForTest
import java.lang.ref.WeakReference
import java.util.concurrent.ExecutorService
import java.util.concurrent.Executors
import java.util.concurrent.TimeUnit
import kotlin.test.AfterTest
import kotlin.test.BeforeTest
import kotlin.test.Test
import kotlin.test.assertEquals
import kotlin.test.assertNotEquals
import kotlin.test.assertNull
import org.awaitility.kotlin.await

class SentryTaskDecoratorTest {
private val dsn = "http://key@localhost/proj"
private lateinit var executor: ExecutorService

private fun decorateFromChildScopes(): Pair<Runnable, WeakReference<IScopes>> {
val childScopes = Sentry.getCurrentScopes().forkedCurrentScope("child")
val decoratedRunnable =
childScopes.makeCurrent().use { SentryTaskDecorator().decorate(Runnable {}) }
return decoratedRunnable to WeakReference(childScopes)
}

@BeforeTest
fun beforeTest() {
executor = Executors.newSingleThreadExecutor()
Expand All @@ -25,6 +37,20 @@ class SentryTaskDecoratorTest {
executor.shutdown()
}

@Test
fun `decorated task does not strongly retain scheduling scopes`() {
initForTest { it.dsn = dsn }
val (decoratedRunnable, childReference) = decorateFromChildScopes()

await.atMost(5, TimeUnit.SECONDS).untilAsserted {
System.gc()
System.runFinalization()
assertNull(childReference.get())
}

decoratedRunnable.run()
}

@Test
fun `scopes is reset to its state within the thread after decoration is done`() {
initForTest { it.dsn = dsn }
Expand Down
Original file line number Diff line number Diff line change
@@ -1,21 +1,32 @@
package io.sentry.spring.jakarta.webflux

import io.sentry.IScopes
import io.sentry.Sentry
import io.sentry.test.initForTest
import java.lang.ref.WeakReference
import java.util.concurrent.ExecutorService
import java.util.concurrent.Executors
import java.util.concurrent.TimeUnit
import kotlin.test.AfterTest
import kotlin.test.BeforeTest
import kotlin.test.Test
import kotlin.test.assertEquals
import kotlin.test.assertFalse
import kotlin.test.assertNotEquals
import kotlin.test.assertNull
import kotlin.test.assertTrue
import org.awaitility.kotlin.await

class SentryScheduleHookTest {
private val dsn = "http://key@localhost/proj"
private lateinit var executor: ExecutorService

private fun applyHookFromChildScopes(): Pair<Runnable, WeakReference<IScopes>> {
val childScopes = Sentry.getCurrentScopes().forkedCurrentScope("child")
val wrappedRunnable = childScopes.makeCurrent().use { SentryScheduleHook().apply(Runnable {}) }
return wrappedRunnable to WeakReference(childScopes)
}

@BeforeTest
fun beforeTest() {
executor = Executors.newSingleThreadExecutor()
Expand Down Expand Up @@ -58,6 +69,20 @@ class SentryScheduleHookTest {
.get()
}

@Test
fun `wrapped task does not strongly retain scheduling scopes`() {
initForTest { it.dsn = dsn }
val (wrappedRunnable, childReference) = applyHookFromChildScopes()

await.atMost(5, TimeUnit.SECONDS).untilAsserted {
System.gc()
System.runFinalization()
assertNull(childReference.get())
}

wrappedRunnable.run()
}

@Test
fun `known maintenance runnable class names are excluded`() {
val classNames =
Expand Down
Original file line number Diff line number Diff line change
@@ -1,19 +1,31 @@
package io.sentry.spring

import io.sentry.IScopes
import io.sentry.Sentry
import io.sentry.test.initForTest
import java.lang.ref.WeakReference
import java.util.concurrent.ExecutorService
import java.util.concurrent.Executors
import java.util.concurrent.TimeUnit
import kotlin.test.AfterTest
import kotlin.test.BeforeTest
import kotlin.test.Test
import kotlin.test.assertEquals
import kotlin.test.assertNotEquals
import kotlin.test.assertNull
import org.awaitility.kotlin.await

class SentryTaskDecoratorTest {
private val dsn = "http://key@localhost/proj"
private lateinit var executor: ExecutorService

private fun decorateFromChildScopes(): Pair<Runnable, WeakReference<IScopes>> {
val childScopes = Sentry.getCurrentScopes().forkedCurrentScope("child")
val decoratedRunnable =
childScopes.makeCurrent().use { SentryTaskDecorator().decorate(Runnable {}) }
return decoratedRunnable to WeakReference(childScopes)
}

@BeforeTest
fun beforeTest() {
executor = Executors.newSingleThreadExecutor()
Expand All @@ -25,6 +37,20 @@ class SentryTaskDecoratorTest {
executor.shutdown()
}

@Test
fun `decorated task does not strongly retain scheduling scopes`() {
initForTest { it.dsn = dsn }
val (decoratedRunnable, childReference) = decorateFromChildScopes()

await.atMost(5, TimeUnit.SECONDS).untilAsserted {
System.gc()
System.runFinalization()
assertNull(childReference.get())
}

decoratedRunnable.run()
}

@Test
fun `scopes is reset to its state within the thread after decoration is done`() {
initForTest { it.dsn = dsn }
Expand Down
Original file line number Diff line number Diff line change
@@ -1,21 +1,32 @@
package io.sentry.spring.webflux

import io.sentry.IScopes
import io.sentry.Sentry
import io.sentry.test.initForTest
import java.lang.ref.WeakReference
import java.util.concurrent.ExecutorService
import java.util.concurrent.Executors
import java.util.concurrent.TimeUnit
import kotlin.test.AfterTest
import kotlin.test.BeforeTest
import kotlin.test.Test
import kotlin.test.assertEquals
import kotlin.test.assertFalse
import kotlin.test.assertNotEquals
import kotlin.test.assertNull
import kotlin.test.assertTrue
import org.awaitility.kotlin.await

class SentryScheduleHookTest {
private val dsn = "http://key@localhost/proj"
private lateinit var executor: ExecutorService

private fun applyHookFromChildScopes(): Pair<Runnable, WeakReference<IScopes>> {
val childScopes = Sentry.getCurrentScopes().forkedCurrentScope("child")
val wrappedRunnable = childScopes.makeCurrent().use { SentryScheduleHook().apply(Runnable {}) }
return wrappedRunnable to WeakReference(childScopes)
}

@BeforeTest
fun beforeTest() {
executor = Executors.newSingleThreadExecutor()
Expand Down Expand Up @@ -58,6 +69,20 @@ class SentryScheduleHookTest {
.get()
}

@Test
fun `wrapped task does not strongly retain scheduling scopes`() {
initForTest { it.dsn = dsn }
val (wrappedRunnable, childReference) = applyHookFromChildScopes()

await.atMost(5, TimeUnit.SECONDS).untilAsserted {
System.gc()
System.runFinalization()
assertNull(childReference.get())
}

wrappedRunnable.run()
}

@Test
fun `known maintenance runnable class names are excluded`() {
val classNames =
Expand Down
Loading
Loading