Skip to content

Conversation

@snowp
Copy link
Contributor

@snowp snowp commented Dec 29, 2025

In order to support global fields being persisted on the AppExit log emitted by Android on next app start we were overriding the logs for each log with the global state fields from the previous app run. This instead relies on new behavior in shared core to apply the old values to the logs that specify the previous process run session ID, which avoids the extra allocations in the common case

Also enhances the integration test to verify that we are correctly using the state fields from the process run that crashed and not the reporting one.

Depends on bitdriftlabs/shared-core#357


  • CHANGELOG.md's "Unreleased" section has been updated, if applicable.

@snowp snowp changed the title Global fields android: avoid cloning previous global fields on each log Dec 29, 2025
@github-actions
Copy link

github-actions bot commented Dec 29, 2025

Size Comparison Report (x86_64)

Metric APK (KB) SO (KB)
Baseline 3370 1248
Current 3374 1252
Difference 4 4

APK size increased by 4 KB. SO size increased by 4 KB.

@github-actions
Copy link

github-actions bot commented Jan 5, 2026

Android Benchmark Results

Device: PR: Emulator - Android SDK built for x86_64 (API 31) | main: Emulator - Android SDK built for x86_64 (API 31)

Note: Benchmarks run on emulator. Results may vary between runs and may differ from physical devices.

Allocations

Test PR main Δ
logHttpNetworkLog50FieldsAndHeadersAndFieldProviders 1084 1040 +4.2%
logNotMatched10Fields 18 18 0.0%
logNotMatched5000Fields 160 160 0.0%
logNotMatched500Fields 160 132 +21.2%
logNotMatched5Fields 15 15 0.0%
logNotMatchedNoFields 1 1 0.0%
trackSpansWithFields 361 317 +13.9%
trackSpansWithoutFields 56 55 +1.8%

Timing

Test PR main Δ
logHttpNetworkLog50FieldsAndHeadersAndFieldProviders 232.84 us 242.75 us -4.1%
logNotMatched10Fields 5.64 us 6.58 us -14.3%
logNotMatched5000Fields 2.26 ms 2.82 ms -19.7%
logNotMatched500Fields 231.43 us 280.18 us -17.4%
logNotMatched5Fields 3.19 us 3.70 us -13.8%
logNotMatchedNoFields 437 ns 530 ns -17.6%
trackSpansWithFields 456.06 us 582.27 us -21.7%
trackSpansWithoutFields 7.59 us 8.31 us -8.7%

@snowp snowp requested a review from kattrali January 5, 2026 16:44
@snowp snowp marked this pull request as ready for review January 5, 2026 19:24
Copy link
Contributor

@kattrali kattrali left a comment

Choose a reason for hiding this comment

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

tidy ✨ 🧹

logger.log(LogLevel.INFO, null, null) { "test log" }

var nextLogFound = false
while (!nextLogFound) {
Copy link
Contributor

Choose a reason for hiding this comment

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

optional nit: you could remove this to prevent potential infinite loop and use generateSequence instead

    val testLog = generateSequence { CaptureTestJniLibrary.nextUploadedLog() }
        .take(10)
        .first { it.message == "test log" }

    assertThat(testLog.sessionId).isEqualTo("bar")
    assertThat(testLog.fields["app_version"]).isEqualTo(FieldValue.StringField(newAppVersion))
    assertThat(testLog.fields["_app_version_code"]).isEqualTo(FieldValue.StringField(newAppVersionCode.toString()))

snowp added 5 commits January 7, 2026 10:17
Address PR comment to prevent potential infinite loop and improve code readability.
The UIKit framework is not used in this file and causes build failures
when building for macOS. This file only uses Foundation types.
@snowp snowp merged commit 56171e5 into main Jan 7, 2026
17 checks passed
@snowp snowp deleted the global-fields branch January 7, 2026 19:52
@github-actions github-actions bot locked and limited conversation to collaborators Jan 7, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants