diff --git a/CHANGELOG.md b/CHANGELOG.md index a55390674d..ae5959c27b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,7 +4,8 @@ ### Fixes -`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)) +- 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)) ## 8.55.0 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 5a96551271..e37a04592b 100644 --- a/sentry-compose/src/androidMain/kotlin/io/sentry/compose/SentryComposeTracing.kt +++ b/sentry-compose/src/androidMain/kotlin/io/sentry/compose/SentryComposeTracing.kt @@ -117,10 +117,15 @@ private fun recordCompositionSpan( ) { val parentSpan = ParentSpans.getOrCreateCompositionSpan(ownerSpan, startTimestamp) ?: return - parentSpan.startChild(OP_COMPOSITION_CHILD, tag, startTimestamp).apply { - spanContext.origin = OP_TRACE_ORIGIN - finish(null, endTimestamp) - } + parentSpan + .startChild( + OP_COMPOSITION_CHILD, + tag, + startTimestamp, + Instrumenter.SENTRY, + SpanOptions().apply { origin = OP_TRACE_ORIGIN }, + ) + .run { finish(null, endTimestamp) } } private fun recordRenderSpan( @@ -131,10 +136,15 @@ private fun recordRenderSpan( ) { val parentSpan = ParentSpans.getOrCreateRenderSpan(ownerSpan, startTimestamp) ?: return - parentSpan.startChild(OP_RENDER_CHILD, tag, startTimestamp).apply { - spanContext.origin = OP_TRACE_ORIGIN - finish(null, endTimestamp) - } + parentSpan + .startChild( + OP_RENDER_CHILD, + tag, + startTimestamp, + Instrumenter.SENTRY, + SpanOptions().apply { origin = OP_TRACE_ORIGIN }, + ) + .run { finish(null, endTimestamp) } } /** @@ -220,6 +230,7 @@ private class ParentSpans { startTimestamp, Instrumenter.SENTRY, SpanOptions().apply { + origin = OP_TRACE_ORIGIN isTrimStart = true isTrimEnd = true isIdle = true @@ -229,8 +240,6 @@ private class ParentSpans { if (parentSpan.dropsChildSpans) { return null } - - parentSpan.spanContext.origin = OP_TRACE_ORIGIN setCached(WeakReference(parentSpan)) return parentSpan } 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, )