Skip to content
Open
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
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note: We have to specify the instrumenter explicitly b/c the only startChild() method that permits setting both the start timestamp and SentryOptions requires it. (This doesn't change behavior, as SentryTraced has always started children via Instrumenter.SENTRY under the hood.)

SpanOptions().apply { origin = OP_TRACE_ORIGIN },
)
.run { finish(null, endTimestamp) }
}

private fun recordRenderSpan(
Expand All @@ -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) }
}

/**
Expand Down Expand Up @@ -220,6 +230,7 @@ private class ParentSpans {
startTimestamp,
Instrumenter.SENTRY,
SpanOptions().apply {
origin = OP_TRACE_ORIGIN
isTrimStart = true
isTrimEnd = true
isIdle = true
Expand All @@ -229,8 +240,6 @@ private class ParentSpans {
if (parentSpan.dropsChildSpans) {
return null
}

parentSpan.spanContext.origin = OP_TRACE_ORIGIN
setCached(WeakReference(parentSpan))
return parentSpan
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down Expand Up @@ -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,
)
Expand Down
Loading