Skip to content

Manual Integration

Integrating the SDK Without Using ft-plugin

Guance uses Android Gradle Plugin Transformation for code injection to enable automatic data collection. However, due to compatibility issues, ft-plugin or ft-plugin-legacy may not be available in some cases. The affected scope includes:

  • RUM Action and Resource
  • android.util.Log
  • Automatic capture of Java and Kotlin println console logs
  • Automatic symbol file upload

Currently, for such cases, a manual integration approach can be used.

Application Startup Event

Source code example reference DemoForManualSet.kt.

// Application
@Override
public void onCreate() {
    super.onCreate();
    // Must be called before SDK initialization
    FTAutoTrack.startApp(null);
    // Set SDK configuration
    setSDK(this);
}
// Application
override fun onCreate() {
    super.onCreate()
    // Must be called before SDK initialization
    FTAutoTrack.startApp(null)
    // Set SDK configuration
    setSDK(this)
}

Manually Adding User Actions

Events such as button clicks need to be added manually at the trigger point. Here, a Button onClick event is used as an example. Source code example reference ManualActivity.kt:

view.setOnClickListener(new View.OnClickListener() {
    @Override
    public void onClick(View v) {
        FTRUMGlobalManager.get().startAction("[action button]", "click");
    }
});
view.setOnClickListener {
    FTRUMGlobalManager.get().startAction("[action button]", "click")
}

Manually Integrating OkHttp Resource / Trace

OkHttp can be used to integrate Resource and Trace via addInterceptor and eventListener. Example below, source code example reference ManualActivity.kt:

OkHttpClient.Builder builder = new OkHttpClient.Builder()
    .addInterceptor(new FTTraceInterceptor())
    .addInterceptor(new FTResourceInterceptor())
    .eventListenerFactory(new FTResourceEventListener.FTFactory());
//.eventListenerFactory(new FTResourceEventListener.FTFactory(true));
OkHttpClient client = builder.build();
val builder = OkHttpClient.Builder()
    .addInterceptor(FTTraceInterceptor())
    .addInterceptor(FTResourceInterceptor())
    .eventListenerFactory(FTResourceEventListener.FTFactory())
    //.eventListenerFactory(new FTResourceEventListener.FTFactory(true))
val client = builder.build()

Other network frameworks need to implement FTRUMGlobalManager.startResource, stopResource, addResource, and FTTraceManager.getTraceHeader themselves. See the source code example ManualActivity.kt for detailed implementation.

Manually Integrating OkHttp WebSocket Resource

When ft-sdk >= 1.7.5 and the ft-plugin that supports automatic WebSocket instrumentation is not used, the OkHttp WebSocket handshake Resource can be explicitly collected via FTWebSocket. First, enable FTRUMConfig.setEnableTraceUserResource(true). Existing Resource URL filtering and RUM sampling rules still apply. Collection only covers successful handshake, server rejection, or failure; connection duration is not tracked, and message content is not collected.

For a small number of call sites, FTWebSocket.newWebSocket() can be used directly:

WebSocket socket = FTWebSocket.newWebSocket(okHttpClient, request, listener);
val socket = FTWebSocket.newWebSocket(okHttpClient, request, listener)

If the project provides a WebSocket factory uniformly via dependency injection, wrap it once and inject a WebSocket.Factory:

WebSocket.Factory factory = FTWebSocket.wrap(okHttpClient);
WebSocket socket = factory.newWebSocket(request, listener);
val factory: WebSocket.Factory = FTWebSocket.wrap(okHttpClient)
val socket = factory.newWebSocket(request, listener)

wrap() supports repeated calls. Even if ft-plugin >= 1.3.8 is also enabled, the same request will only be collected once for the handshake Resource. If a third-party library holds an OkHttpClient internally and neither exposes the newWebSocket() call site nor allows passing in a WebSocket.Factory, the ft-plugin automatic instrumentation must still be used.

WebView Manual Configuration

FTAutoTrack.setUpWebView(webview);
// Configure before loadUrl loading
FTAutoTrack.setUpWebView(webview)
// Configure before loadUrl loading

Feedback

Is this page helpful?