Skip to content

Commit 5e7443c

Browse files
authored
Merge branch 'main' into feat/profiling-remove-vendored-code
2 parents 0fc13c0 + 377d98a commit 5e7443c

File tree

10 files changed

+61
-15
lines changed

10 files changed

+61
-15
lines changed

.github/workflows/agp-matrix.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ jobs:
6060

6161
- name: Create AVD and generate snapshot for caching
6262
if: steps.avd-cache.outputs.cache-hit != 'true'
63-
uses: reactivecircus/android-emulator-runner@1dcd0090116d15e7c562f8db72807de5e036a4ed # pin@v2
63+
uses: reactivecircus/android-emulator-runner@b530d96654c385303d652368551fb075bc2f0b6b # pin@v2
6464
with:
6565
api-level: 30
6666
target: aosp_atd
@@ -79,7 +79,7 @@ jobs:
7979

8080
# We tried to use the cache action to cache gradle stuff, but it made tests slower and timeout
8181
- name: Run instrumentation tests
82-
uses: reactivecircus/android-emulator-runner@1dcd0090116d15e7c562f8db72807de5e036a4ed # pin@v2
82+
uses: reactivecircus/android-emulator-runner@b530d96654c385303d652368551fb075bc2f0b6b # pin@v2
8383
with:
8484
api-level: 30
8585
target: aosp_atd

.github/workflows/generate-javadocs.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ jobs:
2626
run: |
2727
./gradlew aggregateJavadocs
2828
- name: Deploy
29-
uses: JamesIves/github-pages-deploy-action@6c2d9db40f9296374acc17b90404b6e8864128c8 # pin@4.7.3
29+
uses: JamesIves/github-pages-deploy-action@4a3abc783e1a24aeb44c16e869ad83caf6b4cc23 # pin@4.7.4
3030
with:
3131
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
3232
BRANCH: gh-pages

.github/workflows/integration-tests-ui-critical.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ jobs:
9696

9797
- name: Create AVD and generate snapshot for caching
9898
if: steps.avd-cache.outputs.cache-hit != 'true'
99-
uses: reactivecircus/android-emulator-runner@1dcd0090116d15e7c562f8db72807de5e036a4ed # pin@v2
99+
uses: reactivecircus/android-emulator-runner@b530d96654c385303d652368551fb075bc2f0b6b # pin@v2
100100
with:
101101
api-level: ${{ matrix.api-level }}
102102
target: ${{ matrix.target }}
@@ -120,7 +120,7 @@ jobs:
120120
version: ${{env.MAESTRO_VERSION}}
121121

122122
- name: Run tests
123-
uses: reactivecircus/android-emulator-runner@1dcd0090116d15e7c562f8db72807de5e036a4ed # pin@v2.34.0
123+
uses: reactivecircus/android-emulator-runner@b530d96654c385303d652368551fb075bc2f0b6b # pin@v2.35.0
124124
with:
125125
api-level: ${{ matrix.api-level }}
126126
target: ${{ matrix.target }}

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@
1313
- Fix visual artifacts for the Canvas strategy on some devices ([#4861](https://github.com/getsentry/sentry-java/pull/4861))
1414
- [Config] Trim whitespace on properties path ([#4880](https://github.com/getsentry/sentry-java/pull/4880))
1515
- Only set `DefaultReplayBreadcrumbConverter` if replay is available ([#4888](https://github.com/getsentry/sentry-java/pull/4888))
16+
- Session Replay: Cache connection status instead of using blocking calls ([#4891](https://github.com/getsentry/sentry-java/pull/4891))
17+
- Fix log count in client reports ([#4869](https://github.com/getsentry/sentry-java/pull/4869))
1618

1719
### Improvements
1820

sentry-android-core/src/main/java/io/sentry/android/core/AndroidContinuousProfiler.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -190,6 +190,7 @@ private void start() {
190190
}
191191

192192
// If device is offline, we don't start the profiler, to avoid flooding the cache
193+
// TODO .getConnectionStatus() may be blocking, investigate if this can be done async
193194
if (scopes.getOptions().getConnectionStatusProvider().getConnectionStatus() == DISCONNECTED) {
194195
logger.log(SentryLevel.WARNING, "Device is offline. Stopping profiler.");
195196
// Let's stop and reset profiler id, as the profile is now broken anyway

sentry-android-core/src/main/java/io/sentry/android/core/DeviceInfoUtil.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -203,6 +203,7 @@ private void setDeviceIO(final @NotNull Device device, final boolean includeDyna
203203
device.setBatteryTemperature(getBatteryTemperature(batteryIntent));
204204
}
205205

206+
// TODO .getConnectionStatus() may be blocking, investigate if this can be done async
206207
Boolean connected;
207208
switch (options.getConnectionStatusProvider().getConnectionStatus()) {
208209
case DISCONNECTED:

sentry-android-replay/src/main/java/io/sentry/android/replay/ReplayIntegration.kt

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,7 @@ public class ReplayIntegration(
9595
this.gestureRecorderProvider = gestureRecorderProvider
9696
}
9797

98+
@Volatile private var lastKnownConnectionStatus: ConnectionStatus = ConnectionStatus.UNKNOWN
9899
private var debugMaskingEnabled: Boolean = false
99100
private lateinit var options: SentryOptions
100101
private var scopes: IScopes? = null
@@ -219,7 +220,7 @@ public class ReplayIntegration(
219220

220221
if (
221222
isManualPause.get() ||
222-
options.connectionStatusProvider.connectionStatus == DISCONNECTED ||
223+
lastKnownConnectionStatus == DISCONNECTED ||
223224
scopes?.rateLimiter?.isActiveForCategory(All) == true ||
224225
scopes?.rateLimiter?.isActiveForCategory(Replay) == true
225226
) {
@@ -335,6 +336,8 @@ public class ReplayIntegration(
335336
}
336337

337338
override fun onConnectionStatusChanged(status: ConnectionStatus) {
339+
lastKnownConnectionStatus = status
340+
338341
if (captureStrategy !is SessionCaptureStrategy) {
339342
// we only want to stop recording when offline for session mode
340343
return
@@ -375,7 +378,7 @@ public class ReplayIntegration(
375378
private fun checkCanRecord() {
376379
if (
377380
captureStrategy is SessionCaptureStrategy &&
378-
(options.connectionStatusProvider.connectionStatus == DISCONNECTED ||
381+
(lastKnownConnectionStatus == DISCONNECTED ||
379382
scopes?.rateLimiter?.isActiveForCategory(All) == true ||
380383
scopes?.rateLimiter?.isActiveForCategory(Replay) == true)
381384
) {

sentry-android-replay/src/test/java/io/sentry/android/replay/ReplayIntegrationTest.kt

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,6 @@ class ReplayIntegrationTest {
120120
context: Context,
121121
sessionSampleRate: Double = 1.0,
122122
onErrorSampleRate: Double = 1.0,
123-
isOffline: Boolean = false,
124123
isRateLimited: Boolean = false,
125124
recorderProvider: (() -> Recorder)? = null,
126125
replayCaptureStrategyProvider: ((isFullSession: Boolean) -> CaptureStrategy)? = null,
@@ -130,9 +129,6 @@ class ReplayIntegrationTest {
130129
options.run {
131130
sessionReplay.onErrorSampleRate = onErrorSampleRate
132131
sessionReplay.sessionSampleRate = sessionSampleRate
133-
connectionStatusProvider = mock {
134-
on { connectionStatus }.thenReturn(if (isOffline) DISCONNECTED else CONNECTED)
135-
}
136132
}
137133
if (isRateLimited) {
138134
whenever(rateLimiter.isActiveForCategory(any())).thenReturn(true)
@@ -623,13 +619,13 @@ class ReplayIntegrationTest {
623619
context,
624620
recorderProvider = { recorder },
625621
replayCaptureStrategyProvider = { captureStrategy },
626-
isOffline = true,
627622
)
628623

629624
replay.register(fixture.scopes, fixture.options)
630625
replay.start()
631626
replay.onScreenshotRecorded(mock<Bitmap>())
632627

628+
replay.onConnectionStatusChanged(DISCONNECTED)
633629
verify(recorder).pause()
634630
}
635631

@@ -903,10 +899,10 @@ class ReplayIntegrationTest {
903899
context,
904900
recorderProvider = { recorder },
905901
replayCaptureStrategyProvider = { captureStrategy },
906-
isOffline = true,
907902
)
908903

909904
replay.register(fixture.scopes, fixture.options)
905+
replay.onConnectionStatusChanged(DISCONNECTED)
910906
replay.start()
911907

912908
replay.pause()

sentry/src/main/java/io/sentry/clientreport/ClientReportRecorder.java

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import io.sentry.SentryEnvelopeItem;
77
import io.sentry.SentryItemType;
88
import io.sentry.SentryLevel;
9+
import io.sentry.SentryLogEvents;
910
import io.sentry.SentryOptions;
1011
import io.sentry.protocol.SentrySpan;
1112
import io.sentry.protocol.SentryTransaction;
@@ -98,9 +99,19 @@ public void recordLostEnvelopeItem(
9899
reason.getReason(), DataCategory.Span.getCategory(), spans.size() + 1L);
99100
executeOnDiscard(reason, DataCategory.Span, spans.size() + 1L);
100101
}
102+
recordLostEventInternal(reason.getReason(), itemCategory.getCategory(), 1L);
103+
executeOnDiscard(reason, itemCategory, 1L);
104+
} else if (itemCategory.equals(DataCategory.LogItem)) {
105+
final @Nullable SentryLogEvents logs = envelopeItem.getLogs(options.getSerializer());
106+
if (logs != null) {
107+
final long count = logs.getItems().size();
108+
recordLostEventInternal(reason.getReason(), itemCategory.getCategory(), count);
109+
executeOnDiscard(reason, itemCategory, count);
110+
}
111+
} else {
112+
recordLostEventInternal(reason.getReason(), itemCategory.getCategory(), 1L);
113+
executeOnDiscard(reason, itemCategory, 1L);
101114
}
102-
recordLostEventInternal(reason.getReason(), itemCategory.getCategory(), 1L);
103-
executeOnDiscard(reason, itemCategory, 1L);
104115
}
105116
} catch (Throwable e) {
106117
options.getLogger().log(SentryLevel.ERROR, e, "Unable to record lost envelope item.");

sentry/src/test/java/io/sentry/clientreport/ClientReportTest.kt

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,10 @@ import io.sentry.SentryEnvelope
1616
import io.sentry.SentryEnvelopeHeader
1717
import io.sentry.SentryEnvelopeItem
1818
import io.sentry.SentryEvent
19+
import io.sentry.SentryLogEvent
20+
import io.sentry.SentryLogEvents
21+
import io.sentry.SentryLogLevel
22+
import io.sentry.SentryLongDate
1923
import io.sentry.SentryOptions
2024
import io.sentry.SentryReplayEvent
2125
import io.sentry.SentryTracer
@@ -347,6 +351,34 @@ class ClientReportTest {
347351
verify(onDiscardMock, times(1)).execute(DiscardReason.BEFORE_SEND, DataCategory.Profile, 1)
348352
}
349353

354+
@Test
355+
fun `recording lost client report counts log entries`() {
356+
val onDiscardMock = mock<SentryOptions.OnDiscardCallback>()
357+
givenClientReportRecorder { options -> options.onDiscard = onDiscardMock }
358+
359+
val envelope =
360+
testHelper.newEnvelope(
361+
SentryEnvelopeItem.fromLogs(
362+
opts.serializer,
363+
SentryLogEvents(
364+
listOf(
365+
SentryLogEvent(SentryId(), SentryLongDate(1), "log message 1", SentryLogLevel.ERROR),
366+
SentryLogEvent(SentryId(), SentryLongDate(2), "log message 2", SentryLogLevel.WARN),
367+
)
368+
),
369+
)
370+
)
371+
372+
clientReportRecorder.recordLostEnvelopeItem(DiscardReason.NETWORK_ERROR, envelope.items.first())
373+
374+
verify(onDiscardMock, times(1)).execute(DiscardReason.NETWORK_ERROR, DataCategory.LogItem, 2)
375+
376+
val clientReport = clientReportRecorder.resetCountsAndGenerateClientReport()
377+
val logItem =
378+
clientReport!!.discardedEvents!!.first { it.category == DataCategory.LogItem.category }
379+
assertEquals(2, logItem.quantity)
380+
}
381+
350382
private fun givenClientReportRecorder(
351383
callback: Sentry.OptionsConfiguration<SentryOptions>? = null
352384
) {

0 commit comments

Comments
 (0)