Show TOC

Add Tracing to your Android ApplicationLocate this document in the navigation structure

Add tracing to your native Android OData app, upload the BTX that contains all collected trace data to the server, and view the trace information.

End-to-End Tracing

The E2ETracing component collects end-to-end step and request trace data including performance measurements and user actions. SDK libraries are instrumented for E2ETrace enablement. Furthermore, the E2ETrace component exposes APIs which allows developers to perform various, E2E tracing related tasks on the client.

  • E2E Transactions, Steps and Requests
    To perform E2E tracing, start an end-to-end transaction. A transaction defines the boundaries of an E2E tracing session.
    Restriction Only one E2E transaction can be active at a time. Starting a new transaction while an active one is running causes the latter to terminate (including its active steps and requests).

    Within the context of an active E2E trace transaction one can start several E2E steps. Steps can be logically mapped to a given use case or business scenarios. For example, an E2E step might be assigned to the phase of presenting your main screen and populating it with data.

    Steps can in turn consist of one to many E2E requests. An E2E request is an atomic logical entity generally bound to one network request. An E2E request could be mapped, for example, a GET request for fetching data, or a POST request that updates an entity on the server.

    A Business Transaction XML is generated as a result of running an E2E trace session. This XML file contains E2E trace relevant step and request data in a standard format. The framework allows for uploading the generated BTX to the SAP Mobile Platform Server, where BTX files are archived for further analysis.

  • Basic E2E Tracing
    These steps enable basic E2E trace enablement of an app. Custom E2E tracing is described later.
    1. Instantiate the E2E trace manager instance:
      //get the E2ETraceManager instance 
      E2ETraceManager traceMan = Supportability.getInstance().getE2ETraceManager(this);
      Start a transaction; which is mandatory because E2E steps and requests must start within the context of an E2E transaction. Only one E2E transaction can be active at a time.
      E2ETraceTransaction transaction = traceMan.startTransaction("MyTransaction");
      The call to E2ETraceManager startTransaction creates and starts an E2E transaction. If there was an active transaction when calling the API, the old transaction ends and a new instance is created. You can query the active transaction (if any) using the E2ETraceManager getActiveTransaction API.
      E2ETraceTransaction actTransaction = traceMan.getActiveTransaction();
      An E2E transaction can have two states: Started or Ended.
      Remember If a transaction is ended, it cannot perform further E2E steps and requests.
    2. Start an E2E step in the context of the newly created transaction. To start a step, call E2ETransaction startStep API on a valid E2ETransaction instance. The transaction must be in status started in order to start new steps; if the transaction is ended, attempts to start new steps fail.
      E2ETraceStep step = transaction.startStep();
      You can also call the E2ETraceManager getActiveTransaction API to retrieve the active transaction, and start the step:
    3. Close the active step before ending the E2E trace session. E2ETraceSteps can be ended by invoking their endStep method.
    4. Invoke the E2ETraceManager endTransaction to close the E2E trace session.
      This call ends the active steps and their running requests. You can also call endTransaction on the transaction instance itself:
      Note Selected SDK components are instrumented specifically for E2E tracing. Which means that although the above code snippets did not trigger custom steps or requests, the SDK produces trace data. The BTX contains all collected trace data, including performance measurements, network related metric data like count of bytes sent or received, request / response headers, and so on.
  • Custom E2E Tracing
    Although basic E2E tracing is sufficient in most cases, some apps may need to generate custom E2E trace data, which the Supportability framework provides. In this case, along with starting and ending an E2E transaction and E2E steps, the developer must also manage requests. Create and start an E2E trace request from an active E2E transaction and an E2E step:
    // create a request within the context of the current step
    E2ETraceRequest traceRequest = null;
    E2ETrace e2eTrace = Supportability.getInstance().getE2ETrace();
    if (e2eTrace != null)
    traceRequest = e2eTrace.startRequest();
    The E2ETraceRequest exposes APIs that allow setting properties required for E2E tracing:
    //Should be called before data is sent. 
    void markSending() 
    //Should be called as soon as the data was sent.
    void markSent() 
    //Should be called upon receiving first data bytes. 
    void markReceiving() 
    //Should be called as soon as data was completely received.
    void markReceived() 
    //Sets the size of sent data in bytes.  
    void setByteCountSent(long) 
    //Sets the size of received data in bytes. 
    void setByteCountReceived(long)
    //Sets the HTTP request line 
    void setRequestHeaders(Map<String, String>)
    void setResponseHeaders(Map<String, String>) 
    void setRequestLine(String)
    1. For example, set up the E2E trace request when starting a network request:
    2. After the network request completes, the response is processed:
    3. Close the trace request:
      Calling the E2ETraceRequest endRequest API causes the E2ETrace request to be marked as ended.
      Remember Further attempts to modify this request will fail.
  • Client-Side BTX Persistence
    The end result of an E2E trace session is the Business Transaction XML (BTX), which is temporarily stored in the app’s file system when an upload is initiated. The BTX is automatically removed when one of the following conditions are met:
    • the BTX is successfully uploaded to the server, or
    • a new E2E trace session starts
  • Uploading the BTX

    SAP Mobile Platform Server supports uploading E2E trace results ( BTX). Access is controlled by the security configuration associated with the given application. Therefore, prior to uploading the BTX, the Server Administrator must perform some administrative tasks. For detailed instructions on E2E trace and log related settings and configuration see (or perform a Web search for for “SMP” “Defining Client Log and Trace Policies”). In addition, the application connection ID must be passed as a “X-SMP-APPCID” header field.

    The following code attempts to upload the BTX to the SAP Mobile Platform Server. You must supply a valid SAP Mobile Platform Server log upload URL in the form “http(s)://host:port/btx”, and application E2E tracing must be enabled in Management Cockpit. See for details.
    HttpConversationManager convMan = new HttpConversationManager(this);
    IHttpConversation conv = convMan.create(traceURL);
    conv.addHeader("X-SMP-APPCID", appCId);
    SupportabilityUploaderImpl uploader = new SupportabilityUploaderImpl(conv, this);
    try {
       traceMan.uploadBTX(uploader, new UploadListener() {
    		public void onUploadSuccess() {
    			Log.i(LOG_TAG, "BTX Upload Successful");
    		public void onUploadFailure(UploadResult result) {
                 Log.e(LOG_TAG, "BTX Upload Failed: " + result.getResponseStatusCode() + ", " + result.getHint());
    } catch (E2ETraceException e) {
    	Log.e(LOG_TAG, "BTX Upload Failed: " + e.getMessage());
    Normally the E2E trace closes once the BTX is uploaded; however, if this does not happen, the framework performs the necessary cleanup when calling the upload API.
    Remember Invoking the upload API closes the active E2E trace session; any pending E2E transactions, steps, or requests will be ended.
  • E2E Trace Implications
    Enabling E2E tracing is useful to track the functionality of apps; however, it does come at a cost which affects performance and memory usage. When E2E tracing is on, additional housekeeping is done by the various SDK components to insert the required values in the generated BTX. During the E2E session, the BTX document is managed in memory, and only gets persisted to disk if uploading it to the server fails. Additionally, E2E tracing automatically switches all loggers to DEBUG mode, meaning that logs become more verbose compared to the default ERROR mode.
    Remember When the E2ETrace session is closed, loggers automatically revert to their normal settings.

    Use application E2E tracing only if it is required.

  • Examples

    The Supportability framework includes an extensive set of unit tests that cover many use-cases. Additionally, every public API is documented, and includes usage examples for the less obvious use-cases.