Skip to content

Commit 29b4976

Browse files
committed
test(async-profiler): Add an end-to-end test of a profiled transaction
ContinuousProfilerEndToEndTest starts a sampled transaction with the TRACE profile lifecycle and checks that its profile chunk reaches MockSentryServer, linked to the transaction by the profiler ID. It ports the profiling part of the console sample's system test. The profiler rejects a traces path with a dot anywhere in its absolute form, so the test puts it in the temp dir. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
1 parent 60de255 commit 29b4976

2 files changed

Lines changed: 49 additions & 0 deletions

File tree

‎sentry-async-profiler/build.gradle.kts‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ dependencies {
3232
// tests
3333
testImplementation(kotlin(Config.kotlinStdLib))
3434
testImplementation(projects.sentryTestSupport)
35+
testImplementation(libs.google.truth)
3536
testImplementation(libs.kotlin.test.junit)
3637
testImplementation(libs.mockito.kotlin)
3738
testImplementation(libs.mockito.core)
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
package io.sentry.asyncprofiler
2+
3+
import com.google.common.truth.Truth.assertThat
4+
import io.sentry.ProfileLifecycle
5+
import io.sentry.Sentry
6+
import io.sentry.test.MockSentryServer
7+
import io.sentry.test.initForTest
8+
import io.sentry.test.profileChunk
9+
import io.sentry.test.transaction
10+
import kotlin.test.AfterTest
11+
import kotlin.test.Test
12+
13+
/** Profiles a transaction with the async profiler and sends both over the real HTTP transport. */
14+
class ContinuousProfilerEndToEndTest {
15+
private val server = MockSentryServer()
16+
17+
@AfterTest
18+
fun teardown() {
19+
Sentry.close()
20+
server.close()
21+
}
22+
23+
@Test
24+
fun `a transaction starts a profile whose chunk reaches Sentry`() {
25+
initForTest {
26+
it.dsn = server.dsn
27+
it.tracesSampleRate = 1.0
28+
it.profileSessionSampleRate = 1.0
29+
it.profileLifecycle = ProfileLifecycle.TRACE
30+
// The profiler rejects a traces path with a dot anywhere in it, which the module's absolute
31+
// path can have.
32+
it.profilingTracesDirPath =
33+
"${System.getProperty("java.io.tmpdir")}/sentry-profiler-end-to-end-test"
34+
}
35+
36+
val transaction = Sentry.startTransaction("transaction name", "op")
37+
val span = transaction.startChild("child")
38+
Thread.sleep(100)
39+
span.finish()
40+
transaction.finish()
41+
42+
val sent =
43+
server.awaitEnvelope { it.transaction()?.transaction == "transaction name" }.transaction()!!
44+
val profilerId = sent.contexts.profile?.profilerId
45+
assertThat(profilerId).isNotNull()
46+
server.awaitEnvelope(timeoutMillis = 30_000) { it.profileChunk()?.profilerId == profilerId }
47+
}
48+
}

0 commit comments

Comments
 (0)