Skip to content

Commit 485764c

Browse files
authored
Merge 606ea66 into 2be62a1
2 parents 2be62a1 + 606ea66 commit 485764c

20 files changed

Lines changed: 290 additions & 184 deletions

File tree

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@
22

33
## Unreleased
44

5+
### Features
6+
7+
- Add captureProfile method to hub and client ([#2290](https://github.com/getsentry/sentry-java/pull/2290))
8+
59
### Fixes
610

711
- Remove verbose FrameMetricsAggregator failure logging ([#2293](https://github.com/getsentry/sentry-java/pull/2293))

sentry-android-core/src/test/java/io/sentry/android/core/ActivityLifecycleIntegrationTest.kt

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -377,7 +377,6 @@ class ActivityLifecycleIntegrationTest {
377377
assertEquals(SpanStatus.OK, it.status)
378378
},
379379
anyOrNull<TraceContext>(),
380-
anyOrNull(),
381380
anyOrNull()
382381
)
383382
}
@@ -400,7 +399,6 @@ class ActivityLifecycleIntegrationTest {
400399
assertEquals(SpanStatus.UNKNOWN_ERROR, it.status)
401400
},
402401
anyOrNull<TraceContext>(),
403-
anyOrNull(),
404402
anyOrNull()
405403
)
406404
}
@@ -416,7 +414,7 @@ class ActivityLifecycleIntegrationTest {
416414
sut.onActivityCreated(activity, fixture.bundle)
417415
sut.onActivityPostResumed(activity)
418416

419-
verify(fixture.hub, never()).captureTransaction(any(), anyOrNull<TraceContext>(), anyOrNull(), anyOrNull())
417+
verify(fixture.hub, never()).captureTransaction(any(), anyOrNull<TraceContext>(), anyOrNull())
420418
}
421419

422420
@Test
@@ -427,7 +425,7 @@ class ActivityLifecycleIntegrationTest {
427425
val activity = mock<Activity>()
428426
sut.onActivityPostResumed(activity)
429427

430-
verify(fixture.hub, never()).captureTransaction(any(), anyOrNull<TraceContext>(), anyOrNull(), anyOrNull())
428+
verify(fixture.hub, never()).captureTransaction(any(), anyOrNull<TraceContext>(), anyOrNull())
431429
}
432430

433431
@Test
@@ -440,7 +438,7 @@ class ActivityLifecycleIntegrationTest {
440438
sut.onActivityCreated(activity, fixture.bundle)
441439
sut.onActivityDestroyed(activity)
442440

443-
verify(fixture.hub).captureTransaction(any(), anyOrNull<TraceContext>(), anyOrNull(), anyOrNull())
441+
verify(fixture.hub).captureTransaction(any(), anyOrNull<TraceContext>(), anyOrNull())
444442
}
445443

446444
@Test
@@ -509,7 +507,7 @@ class ActivityLifecycleIntegrationTest {
509507
sut.onActivityCreated(mock(), mock())
510508

511509
sut.onActivityCreated(mock(), fixture.bundle)
512-
verify(fixture.hub).captureTransaction(any(), anyOrNull<TraceContext>(), anyOrNull(), anyOrNull())
510+
verify(fixture.hub).captureTransaction(any(), anyOrNull<TraceContext>(), anyOrNull())
513511
}
514512

515513
@Test
@@ -549,7 +547,7 @@ class ActivityLifecycleIntegrationTest {
549547
sut.onActivityCreated(activity, mock())
550548
sut.onActivityResumed(activity)
551549

552-
verify(fixture.hub).captureTransaction(any(), anyOrNull<TraceContext>(), anyOrNull(), anyOrNull())
550+
verify(fixture.hub).captureTransaction(any(), anyOrNull<TraceContext>(), anyOrNull())
553551
}
554552

555553
@Test

sentry-android-integration-tests/sentry-uitest-android/src/androidTest/java/io/sentry/uitest/android/EnvelopeTests.kt

Lines changed: 34 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@ import io.sentry.protocol.SentryTransaction
1515
import org.junit.runner.RunWith
1616
import java.io.File
1717
import kotlin.test.Test
18-
import kotlin.test.assertContains
1918
import kotlin.test.assertEquals
19+
import kotlin.test.assertFails
2020
import kotlin.test.assertFalse
2121
import kotlin.test.assertNotNull
2222
import kotlin.test.assertTrue
@@ -50,25 +50,29 @@ class EnvelopeTests : BaseUiTest() {
5050
options.profilesSampleRate = 1.0
5151
}
5252
relayIdlingResource.increment()
53+
relayIdlingResource.increment()
5354
val transaction = Sentry.startTransaction("e2etests", "test1")
5455

5556
transaction.finish()
5657
relay.assert {
5758
assertEnvelope {
58-
val transactionItem: SentryTransaction = it.assertItem()
5959
val profilingTraceData: ProfilingTraceData = it.assertItem()
6060
it.assertNoOtherItems()
61-
assertTrue(transactionItem.transaction == "e2etests")
62-
assertEquals(profilingTraceData.transactionId, transactionItem.eventId.toString())
63-
assertTrue(profilingTraceData.transactionName == "e2etests")
61+
assertEquals(profilingTraceData.transactionId, transaction.eventId.toString())
62+
assertEquals("e2etests", profilingTraceData.transactionName)
6463
assertTrue(profilingTraceData.environment.isNotEmpty())
6564
assertTrue(profilingTraceData.cpuArchitecture.isNotEmpty())
6665
assertTrue(profilingTraceData.transactions.isNotEmpty())
6766
// We should find the transaction id that started the profiling in the list of transactions
6867
val transactionData = profilingTraceData.transactions
69-
.firstOrNull { t -> t.id == transactionItem.eventId.toString() }
68+
.firstOrNull { t -> t.id == transaction.eventId.toString() }
7069
assertNotNull(transactionData)
7170
}
71+
assertEnvelope {
72+
val transactionItem: SentryTransaction = it.assertItem()
73+
it.assertNoOtherItems()
74+
assertEquals("e2etests", transactionItem.transaction)
75+
}
7276
assertNoOtherEnvelopes()
7377
assertNoOtherRequests()
7478
}
@@ -84,6 +88,7 @@ class EnvelopeTests : BaseUiTest() {
8488
relayIdlingResource.increment()
8589
relayIdlingResource.increment()
8690
relayIdlingResource.increment()
91+
relayIdlingResource.increment()
8792

8893
val transaction = Sentry.startTransaction("e2etests", "test1")
8994
val transaction2 = Sentry.startTransaction("e2etests1", "test2")
@@ -105,19 +110,15 @@ class EnvelopeTests : BaseUiTest() {
105110
}
106111
// The profile is sent only in the last transaction envelope
107112
assertEnvelope {
108-
val transactionItem: SentryTransaction = it.assertItem()
109113
val profilingTraceData: ProfilingTraceData = it.assertItem()
110114
it.assertNoOtherItems()
111-
assertEquals(transaction3.eventId.toString(), transactionItem.eventId.toString())
112-
assertEquals(profilingTraceData.transactionId, transactionItem.eventId.toString())
113-
assertTrue(profilingTraceData.transactionName == "e2etests2")
114-
assertTrue(profilingTraceData.truncationReason == "normal")
115+
assertEquals("e2etests2", profilingTraceData.transactionName)
116+
assertEquals("normal", profilingTraceData.truncationReason)
115117

116118
// The transaction list is not ordered, since it's stored using a map to be able to quickly check the
117119
// existence of a certain id. So we order the list to make more meaningful checks on timestamps.
118120
val transactions = profilingTraceData.transactions.sortedBy { it.relativeStartNs }
119-
assertContains(transactions.map { t -> t.id }, transactionItem.eventId.toString())
120-
assertEquals(transactions.last().id, transactionItem.eventId.toString())
121+
assertEquals(transactions.last().id, transaction3.eventId.toString())
121122
val startTimes = transactions.map { t -> t.relativeStartNs }
122123
val endTimes = transactions.mapNotNull { t -> t.relativeEndNs }
123124
val startCpuTimes = transactions.map { t -> t.relativeStartCpuMs }
@@ -141,6 +142,12 @@ class EnvelopeTests : BaseUiTest() {
141142
// The first and last transactions should be aligned to the start/stop of profile
142143
assertEquals(endTimes.last() - startTimes.first(), profilingTraceData.durationNs.toLong())
143144
}
145+
// The profile is sent only in the last transaction envelope
146+
assertEnvelope {
147+
val transactionItem: SentryTransaction = it.assertItem()
148+
it.assertNoOtherItems()
149+
assertEquals(transaction3.eventId.toString(), transactionItem.eventId.toString())
150+
}
144151
assertNoOtherEnvelopes()
145152
assertNoOtherRequests()
146153
}
@@ -154,14 +161,24 @@ class EnvelopeTests : BaseUiTest() {
154161
options.profilesSampleRate = 1.0
155162
}
156163
relayIdlingResource.increment()
164+
relayIdlingResource.increment()
165+
val profilesDirPath = Sentry.getCurrentHub().options.profilingTracesDirPath
157166
val transaction = Sentry.startTransaction("e2etests", "test empty")
167+
168+
var finished = false
169+
Thread {
170+
while (!finished) {
171+
// Let's modify the trace file to be empty, so that the profile will actually be empty.
172+
val origProfileFile = File(profilesDirPath!!).listFiles()?.maxByOrNull { f -> f.lastModified() }
173+
origProfileFile?.writeBytes(ByteArray(0))
174+
}
175+
}.start()
158176
transaction.finish()
159-
// Let's modify the trace file to be empty, so that the profile will actually be empty.
160-
val profilesDirPath = Sentry.getCurrentHub().options.profilingTracesDirPath
161-
val origProfileFile = File(profilesDirPath!!).listFiles()?.maxByOrNull { f -> f.lastModified() }
162-
origProfileFile?.writeBytes(ByteArray(0))
177+
finished = true
163178

164179
relay.assert {
180+
// The profile failed to be sent. Trying to read the envelope from the data transmitted throws an exception
181+
assertFails { assertEnvelope {} }
165182
assertEnvelope {
166183
it.assertItem<SentryTransaction>()
167184
// Since the profile is empty, it is discarded and not sent to Sentry

sentry-apollo-3/src/test/java/io/sentry/apollo3/SentryApollo3InterceptorTest.kt

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,6 @@ class SentryApollo3InterceptorTest {
102102
assertEquals(SpanStatus.OK, it.spans.first().status)
103103
},
104104
anyOrNull<TraceContext>(),
105-
anyOrNull(),
106105
anyOrNull()
107106
)
108107
}
@@ -117,7 +116,6 @@ class SentryApollo3InterceptorTest {
117116
assertEquals(SpanStatus.PERMISSION_DENIED, it.spans.first().status)
118117
},
119118
anyOrNull<TraceContext>(),
120-
anyOrNull(),
121119
anyOrNull()
122120
)
123121
}
@@ -132,7 +130,6 @@ class SentryApollo3InterceptorTest {
132130
assertEquals(SpanStatus.INTERNAL_ERROR, it.spans.first().status)
133131
},
134132
anyOrNull<TraceContext>(),
135-
anyOrNull(),
136133
anyOrNull()
137134
)
138135
}
@@ -188,7 +185,6 @@ class SentryApollo3InterceptorTest {
188185
assertEquals("overwritten description", httpClientSpan.description)
189186
},
190187
anyOrNull<TraceContext>(),
191-
anyOrNull(),
192188
anyOrNull()
193189
)
194190
}
@@ -206,7 +202,6 @@ class SentryApollo3InterceptorTest {
206202
assertEquals(0, it.spans.size)
207203
},
208204
anyOrNull<TraceContext>(),
209-
anyOrNull(),
210205
anyOrNull()
211206
)
212207
}
@@ -226,7 +221,6 @@ class SentryApollo3InterceptorTest {
226221
assertEquals(1, it.spans.size)
227222
},
228223
anyOrNull<TraceContext>(),
229-
anyOrNull(),
230224
anyOrNull()
231225
)
232226
}

sentry-apollo-3/src/test/java/io/sentry/apollo3/SentryApollo3InterceptorWithVariablesTest.kt

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,6 @@ class SentryApollo3InterceptorWithVariablesTest {
8585
assertEquals(SpanStatus.OK, it.spans.first().status)
8686
},
8787
anyOrNull<TraceContext>(),
88-
anyOrNull(),
8988
anyOrNull()
9089
)
9190
}
@@ -100,7 +99,6 @@ class SentryApollo3InterceptorWithVariablesTest {
10099
assertEquals(SpanStatus.PERMISSION_DENIED, it.spans.first().status)
101100
},
102101
anyOrNull<TraceContext>(),
103-
anyOrNull(),
104102
anyOrNull()
105103
)
106104
}
@@ -115,7 +113,6 @@ class SentryApollo3InterceptorWithVariablesTest {
115113
assertEquals(SpanStatus.INTERNAL_ERROR, it.spans.first().status)
116114
},
117115
anyOrNull<TraceContext>(),
118-
anyOrNull(),
119116
anyOrNull()
120117
)
121118
}

sentry-apollo/src/test/java/io/sentry/apollo/SentryApolloInterceptorTest.kt

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,6 @@ class SentryApolloInterceptorTest {
9191
assertEquals(SpanStatus.OK, it.spans.first().status)
9292
},
9393
anyOrNull<TraceContext>(),
94-
anyOrNull(),
9594
anyOrNull()
9695
)
9796
}
@@ -106,7 +105,6 @@ class SentryApolloInterceptorTest {
106105
assertEquals(SpanStatus.PERMISSION_DENIED, it.spans.first().status)
107106
},
108107
anyOrNull<TraceContext>(),
109-
anyOrNull(),
110108
anyOrNull()
111109
)
112110
}
@@ -121,7 +119,6 @@ class SentryApolloInterceptorTest {
121119
assertEquals(SpanStatus.INTERNAL_ERROR, it.spans.first().status)
122120
},
123121
anyOrNull<TraceContext>(),
124-
anyOrNull(),
125122
anyOrNull()
126123
)
127124
}
@@ -157,7 +154,6 @@ class SentryApolloInterceptorTest {
157154
assertEquals("overwritten description", httpClientSpan.description)
158155
},
159156
anyOrNull<TraceContext>(),
160-
anyOrNull(),
161157
anyOrNull()
162158
)
163159
}
@@ -173,7 +169,6 @@ class SentryApolloInterceptorTest {
173169
assertEquals(1, it.spans.size)
174170
},
175171
anyOrNull<TraceContext>(),
176-
anyOrNull(),
177172
anyOrNull()
178173
)
179174
}

sentry-spring/src/test/kotlin/io/sentry/spring/tracing/SentryTracingFilterTest.kt

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,6 @@ class SentryTracingFilterTest {
9191
assertThat(it.contexts.trace!!.operation).isEqualTo("http.server")
9292
},
9393
anyOrNull<TraceContext>(),
94-
anyOrNull(),
9594
anyOrNull()
9695
)
9796
}
@@ -107,7 +106,6 @@ class SentryTracingFilterTest {
107106
assertThat(it.contexts.trace!!.status).isEqualTo(SpanStatus.INTERNAL_ERROR)
108107
},
109108
anyOrNull<TraceContext>(),
110-
anyOrNull(),
111109
anyOrNull()
112110
)
113111
}
@@ -123,7 +121,6 @@ class SentryTracingFilterTest {
123121
assertThat(it.contexts.trace!!.status).isNull()
124122
},
125123
anyOrNull<TraceContext>(),
126-
anyOrNull(),
127124
anyOrNull()
128125
)
129126
}
@@ -139,7 +136,6 @@ class SentryTracingFilterTest {
139136
assertThat(it.contexts.trace!!.parentSpanId).isNull()
140137
},
141138
anyOrNull<TraceContext>(),
142-
anyOrNull(),
143139
anyOrNull()
144140
)
145141
}
@@ -156,7 +152,6 @@ class SentryTracingFilterTest {
156152
assertThat(it.contexts.trace!!.parentSpanId).isEqualTo(parentSpanId)
157153
},
158154
anyOrNull<TraceContext>(),
159-
anyOrNull(),
160155
anyOrNull()
161156
)
162157
}
@@ -189,7 +184,6 @@ class SentryTracingFilterTest {
189184
assertThat(it.status).isEqualTo(SpanStatus.INTERNAL_ERROR)
190185
},
191186
anyOrNull<TraceContext>(),
192-
anyOrNull(),
193187
anyOrNull()
194188
)
195189
}

sentry-spring/src/test/kotlin/io/sentry/spring/tracing/SentryTransactionAdviceTest.kt

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,6 @@ class SentryTransactionAdviceTest {
6666
assertThat(it.status).isEqualTo(SpanStatus.OK)
6767
},
6868
anyOrNull<TraceContext>(),
69-
anyOrNull(),
7069
anyOrNull()
7170
)
7271
}
@@ -79,7 +78,6 @@ class SentryTransactionAdviceTest {
7978
assertThat(it.status).isEqualTo(SpanStatus.INTERNAL_ERROR)
8079
},
8180
anyOrNull<TraceContext>(),
82-
anyOrNull(),
8381
anyOrNull()
8482
)
8583
}
@@ -93,7 +91,6 @@ class SentryTransactionAdviceTest {
9391
assertThat(it.contexts.trace!!.operation).isEqualTo("op")
9492
},
9593
anyOrNull<TraceContext>(),
96-
anyOrNull(),
9794
anyOrNull()
9895
)
9996
}
@@ -117,7 +114,6 @@ class SentryTransactionAdviceTest {
117114
assertThat(it.contexts.trace!!.operation).isEqualTo("op")
118115
},
119116
anyOrNull<TraceContext>(),
120-
anyOrNull(),
121117
anyOrNull()
122118
)
123119
}
@@ -131,7 +127,6 @@ class SentryTransactionAdviceTest {
131127
assertThat(it.contexts.trace!!.operation).isEqualTo("my-op")
132128
},
133129
anyOrNull<TraceContext>(),
134-
anyOrNull(),
135130
anyOrNull()
136131
)
137132
}

0 commit comments

Comments
 (0)