Skip to content

Add tracing support - #921

Merged
FranAguilera merged 4 commits into
mainfrom
franjam/prototype-tracing
Mar 31, 2026
Merged

Add tracing support#921
FranAguilera merged 4 commits into
mainfrom
franjam/prototype-tracing

Conversation

@FranAguilera

@FranAguilera FranAguilera commented Mar 23, 2026

Copy link
Copy Markdown
Contributor

What

Resolves BIT-7463, BIT-7462

Depends on bitdriftlabs/shared-core#412

Adds tracing support for Android (W3C, B3). The whole feature is controlled via runtime config client_config.trace.propagation_mode (frontend config will be tracing_features.trace_id_deep_link_url_template)

Android example for manual integration

private val okHttpClientManual: OkHttpClient =
        OkHttpClient
            .Builder()
            .addInterceptor(CaptureOkHttpTracingInterceptor()) // Add this interceptor to your okhttp client
            .eventListenerFactory(
                CaptureOkHttpEventListenerFactory(
                    requestFieldProvider = RetrofitUrlPathProvider(CustomRequestFieldProvider()),
                    responseFieldProvider = CustomResponseFieldProvider(),
                ),
            )
            .build()

If automatic instrumentation is enabled, no additional interceptor needs to be added (only apply gradle plugin flag)

bitdrift {
    instrumentation {
        automaticOkHttpInstrumentation = true
    }
}

For iOS, tracing works automatically when the URLSession integration is enabled with swizzling (default config). No additional setup required.

Verification

  • JUnit tests

Manual

  • In Android gradle-test-app. Use chucker to easily confirm visually the added headers to requests
  • Set runtime flag to W3C, and setup a workflow to set tracing as active
  • Configure runtime config values in staging
  • gradle-test-app should append the required headers (for both auto/and manual okhttp calls)
  • For auto instrumentation, use maven local and use the local version in gradle-test-app. Verify header are still appended
Android Manual Android automatic (automaticOkHttpInstrumentation to true)
link link

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

@FranAguilera
FranAguilera marked this pull request as draft March 23, 2026 11:16
@github-actions

Copy link
Copy Markdown

Size Comparison Report (x86_64)

Metric APK (KB) SO (KB)
Baseline 3406 1280
Current 3406 1280
Difference 0 0

APK size unchanged. SO size unchanged.

@github-actions

github-actions Bot commented Mar 23, 2026

Copy link
Copy Markdown

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 924 919 +0.5%
logNotMatched5000Fields 10 10 0.0%
logNotMatchedNoFields 1 1 0.0%
trackSpansWithFields 140 138 +1.4%
trackSpansWithoutFields 55 56 -1.8%
webViewBridgeBridgeReady 61 60 +1.7%
webViewBridgeCustomLog 66 58 +13.8%
webViewBridgeInvalidJson 38 38 0.0%
webViewBridgeWebVitalCLS 177 175 +1.1%

Timing

Test PR main Δ
logHttpNetworkLog50FieldsAndHeadersAndFieldProviders 240.04 us 273.66 us -12.3%
logNotMatched5000Fields 2.48 ms 3.09 ms -19.8%
logNotMatchedNoFields 446 ns 463 ns -3.8%
trackSpansWithFields 484.45 us 615.34 us -21.3%
trackSpansWithoutFields 7.95 us 8.66 us -8.2%
webViewBridgeBridgeReady 8.48 us 8.03 us +5.7%
webViewBridgeCustomLog 8.81 us 14.01 us -37.1%
webViewBridgeInvalidJson 163.93 us 106.58 us +53.8%
webViewBridgeWebVitalCLS 20.64 us 20.23 us +2.0%

@FranAguilera
FranAguilera force-pushed the franjam/prototype-tracing branch 2 times, most recently from 301b369 to 744ce1a Compare March 23, 2026 12:22
@FranAguilera FranAguilera changed the title Add tracing support [Android] Add tracing support Mar 23, 2026
@FranAguilera FranAguilera changed the title [Android] Add tracing support Add tracing support Mar 23, 2026
@FranAguilera
FranAguilera force-pushed the franjam/prototype-tracing branch 3 times, most recently from a2b6a4a to aff2570 Compare March 23, 2026 16:52

fun getRuntimeConfigValue(config: RuntimeConfig): Int

fun getRuntimeStringConfigValue(config: RuntimeStringConfig): String

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Pending to consolidate both config values

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Actually will do this in a separate PR this is getting a bit noisy given the iOS changes as well

Comment thread platform/jvm/gradle-test-app/build.gradle.kts
@FranAguilera
FranAguilera force-pushed the franjam/prototype-tracing branch 5 times, most recently from 0f7b92b to 09fb128 Compare March 24, 2026 20:21
@FranAguilera FranAguilera reopened this Mar 24, 2026
@github-actions github-actions Bot locked and limited conversation to collaborators Mar 24, 2026
@FranAguilera
FranAguilera force-pushed the franjam/prototype-tracing branch from 09fb128 to 5ed71a8 Compare March 24, 2026 23:15
@FranAguilera
FranAguilera force-pushed the franjam/prototype-tracing branch from 5ed71a8 to e95c456 Compare March 24, 2026 23:25
@FranAguilera
FranAguilera requested a review from murki March 24, 2026 23:26
@FranAguilera
FranAguilera force-pushed the franjam/prototype-tracing branch from b4d1a06 to 9395bd6 Compare March 30, 2026 13:57
@FranAguilera
FranAguilera force-pushed the franjam/prototype-tracing branch from 9395bd6 to 53baba2 Compare March 30, 2026 13:58
@FranAguilera
FranAguilera requested a review from murki March 30, 2026 14:21
@FranAguilera
FranAguilera force-pushed the franjam/prototype-tracing branch from 184c3f1 to eda1863 Compare March 30, 2026 15:10
@FranAguilera
FranAguilera force-pushed the franjam/prototype-tracing branch 3 times, most recently from 7a8c71b to 1f31350 Compare March 30, 2026 16:46
@FranAguilera
FranAguilera force-pushed the franjam/prototype-tracing branch from 1f31350 to 2d2078a Compare March 30, 2026 16:48
@FranAguilera FranAguilera reopened this Mar 30, 2026
@github-actions github-actions Bot locked and limited conversation to collaborators Mar 30, 2026
@bitdriftlabs bitdriftlabs unlocked this conversation Mar 30, 2026
@FranAguilera
FranAguilera force-pushed the franjam/prototype-tracing branch from dd241ef to 7f8d369 Compare March 30, 2026 20:29
*
* The propagation format is resolved from a runtime config flag.
*/
class CaptureOkHttpTracingInterceptor

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

There's potentially a larger discussion to be had about how "tracing enabled" interacts with clients that already populate the headers and whether we can do something in that case but I wouldn't block this PR on it

Comment thread platform/jvm/core/src/jni.rs Outdated
Comment thread platform/jvm/core/src/jni.rs Outdated
Comment thread platform/swift/source/src/bridge.rs Outdated
Comment thread platform/swift/source/src/bridge.rs
@FranAguilera
FranAguilera force-pushed the franjam/prototype-tracing branch from 8178a60 to 50764d2 Compare March 31, 2026 09:11
@FranAguilera
FranAguilera merged commit ff1782b into main Mar 31, 2026
20 of 22 checks passed
@FranAguilera
FranAguilera deleted the franjam/prototype-tracing branch March 31, 2026 11:18
@github-actions github-actions Bot locked and limited conversation to collaborators Mar 31, 2026
@FranAguilera
FranAguilera restored the franjam/prototype-tracing branch March 31, 2026 12:42
@FranAguilera
FranAguilera deleted the franjam/prototype-tracing branch September 2, 2026 15:12
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.

3 participants