diff --git a/CHANGELOG.md b/CHANGELOG.md index c4ef4c0bac..ae4b065228 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,7 @@ ### Fixes +- Update `SentryTraced` so that it now honors `options.setIgnoredSpanOrigins` ([#6058](https://github.com/getsentry/sentry-java/pull/6058)) - `SentryTraced` now checks for its owning transaction dynamically rather than once per app process. The latter caused `SentryTraced` spans to be dropped process-wide once the original transaction finished ([#6057](https://github.com/getsentry/sentry-java/pull/6057)) - Fix typos in Spring GraphQL integration names (`GrahQL` to `GraphQL`) ([#6061](https://github.com/getsentry/sentry-java/pull/6061)) diff --git a/sentry-compose/src/androidMain/kotlin/io/sentry/compose/SentryComposeTracing.kt b/sentry-compose/src/androidMain/kotlin/io/sentry/compose/SentryComposeTracing.kt index 95ed5425cf..ff2cc0e80f 100644 --- a/sentry-compose/src/androidMain/kotlin/io/sentry/compose/SentryComposeTracing.kt +++ b/sentry-compose/src/androidMain/kotlin/io/sentry/compose/SentryComposeTracing.kt @@ -125,10 +125,15 @@ private fun recordCompositionSpan( ) { val bucketSpan = BucketSpans.getOrCreateCompositionSpan(ownerSpan, startTimestamp) ?: return - bucketSpan.startChild(OP_COMPOSITION_SPAN, tag, startTimestamp).apply { - spanContext.origin = OP_TRACE_ORIGIN - finish(null, endTimestamp) - } + bucketSpan + .startChild( + OP_COMPOSITION_SPAN, + tag, + startTimestamp, + Instrumenter.SENTRY, + SpanOptions().apply { origin = OP_TRACE_ORIGIN }, + ) + .run { finish(null, endTimestamp) } } /** @@ -145,10 +150,15 @@ private fun recordRenderSpan( ) { val bucketSpan = BucketSpans.getOrCreateRenderSpan(ownerSpan, startTimestamp) ?: return - bucketSpan.startChild(OP_RENDER_SPAN, tag, startTimestamp).apply { - spanContext.origin = OP_TRACE_ORIGIN - finish(null, endTimestamp) - } + bucketSpan + .startChild( + OP_RENDER_SPAN, + tag, + startTimestamp, + Instrumenter.SENTRY, + SpanOptions().apply { origin = OP_TRACE_ORIGIN }, + ) + .run { finish(null, endTimestamp) } } /** @@ -237,6 +247,7 @@ private class BucketSpans { startTimestamp, Instrumenter.SENTRY, SpanOptions().apply { + origin = OP_TRACE_ORIGIN isTrimStart = true isTrimEnd = true isIdle = true @@ -246,8 +257,6 @@ private class BucketSpans { if (bucketSpan.dropsChildSpans) { return null } - - bucketSpan.spanContext.origin = OP_TRACE_ORIGIN setCached(WeakReference(bucketSpan)) return bucketSpan } diff --git a/sentry-compose/src/androidUnitTest/kotlin/io/sentry/compose/SentryTracedTest.kt b/sentry-compose/src/androidUnitTest/kotlin/io/sentry/compose/SentryTracedTest.kt index 1d2464d958..c56e8c0361 100644 --- a/sentry-compose/src/androidUnitTest/kotlin/io/sentry/compose/SentryTracedTest.kt +++ b/sentry-compose/src/androidUnitTest/kotlin/io/sentry/compose/SentryTracedTest.kt @@ -128,6 +128,26 @@ class SentryTracedTest { assertThat(tx.countSpans(OP_RENDER)).isEqualTo(0) } + @Test + fun `does not create spans when origin is ignored`() { + val tx = + initSentryAndStartTransaction("tx") { options -> + options.setIgnoredSpanOrigins(listOf(OP_TRACE_ORIGIN)) + } + + rule.setContent { + SentryTraced(tag = "product_info") { Box(Modifier.size(1.dp).testTag("content")) } + } + rule.waitForIdle() + drawContent() + + rule.onNodeWithTag("content").assertExists() + assertThat(tx.countSpans(OP_PARENT_COMPOSITION)).isEqualTo(0) + assertThat(tx.countSpans(OP_COMPOSE)).isEqualTo(0) + assertThat(tx.countSpans(OP_PARENT_RENDER)).isEqualTo(0) + assertThat(tx.countSpans(OP_RENDER)).isEqualTo(0) + } + @Test fun `sibling traced composables with the same owner share the composition parent`() { val tx = initSentryAndStartTransaction("tx") @@ -381,13 +401,17 @@ class SentryTracedTest { assertThat(renderingTx.countSpans(OP_RENDER)).isEqualTo(0) } - private fun initSentryAndStartTransaction(name: String): ITransaction { + private fun initSentryAndStartTransaction( + name: String, + configureOptions: (SentryOptions) -> Unit = {}, + ): ITransaction { lateinit var tx: ITransaction rule.runOnUiThread { Sentry.init( { options: SentryOptions -> options.dsn = "https://key@sentry.io/proj" options.tracesSampleRate = 1.0 + configureOptions(options) }, true, )