Add Tracing to your iOS Application

Add tracing to your native iOS 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.

    Within the context of an active E2E trace transaction, you 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
      id<SAPE2ETraceManager> E2ETraceManager = [[SAPSupportabilityFacade sharedManager] getE2ETraceManager];
      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.
      NSError* errorStartTransaction = nil;
      id<SAPE2ETraceTransaction> E2ETransaction = [E2ETraceManager startTransaction:@"SampleTransaction" error:&errorStartTransaction];
      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.
      id<SAPE2ETraceTransaction> activeTransaction = [self.traceManager getActiveTransaction];
      An E2E transaction can have two states: SAP_E2E_Trace_Status_Started or SAP_E2E_Trace_Status_Ended.
    2. Start an E2E step in the context of the newly created transaction (call E2ETransaction startStep: on a valid E2ETransaction instance.) The transaction must be in status started to start new steps; if the transaction is ended, attempts to start new steps will fail.
      NSError* stepError = nil;
      id<SAPE2ETraceStep> E2EStep = [E2ETransaction startStep:&stepError];
      You can also call E2ETraceManager’s getActiveTransaction API to retrieve the active transaction, and start the step using this:
      [[self.traceManager getActiveTransaction] startStep:&stepError];
    3. Close the active step before ending the E2E trace session. Invoke the endStep: method to end E2ETraceSteps:
      errorEndStep = nil;
      [E2EStep endStep:&errorEndStep];
    4. Close the E2E trace session by invoking E2ETraceManager endTransaction:
      [E2ETraceManager endTransaction:E2ETransaction error:&error];
    5. This call ends the active steps and their running requests; additionally, the BTX document is generated and persisted in the applications sandbox. You can also call endTransaction on the transaction instance itself:
      [E2ETransaction endTransaction:&unexpectedError];
  • 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.
    1. Perform the steps in "Basic E2E Tracing".
    2. Once you have an active E2E transaction and step, create and start an E2E trace request:
      NSError* requestError = nil;
      // created a request within the context of the current step
      SAPE2ETraceRequest* E2ERequest = [E2EStep startRequest:&requestError];
      The SAPE2ETraceRequest 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:(NSUInteger)byteCount 
      //Sets the size of received data in bytes.
      (void) setByteCountReceived:(NSUInteger)byteCount
      //Sets the request headers.
      (void) setRequestHeaders:(NSString*) requestHeaders_in;
      //Sets the response headers.
      (void) setResponseHeadersDictionary:(NSDictionary*) responseHeaders_in; 
      //Sets the HTTP request line. 
      (void) setRequestLine:(NSString*) requestLine_in;
    3. For example, set up the E2E trace request when starting a network request:
      [E2ERequest setByteCountSent:request.HTTPBody.length];
      [E2ERequest markSending:nil];
      [E2ERequest markSent:nil];
      [E2ERequest setRequestHeadersDictionary:request.allHTTPHeaderFields];
      [E2ERequest setRequestLine:[NSString stringWithFormat:@"%@ %@ %@", request.HTTPMethod, request.URL.absoluteString, @“HTTP/1.1"]];
    4. After the network request completes, the response is processed:
      [E2ERequest markReceiving:nil];
      [E2ERequest markReceived:nil];
      [E2ERequest setResponseHeadersDictionary:[(NSHTTPURLResponse*)response allHeaderFields]];
      [E2ERequest setReturnCode:[NSString stringWithFormat:@"%ld", (long)((NSHTTPURLResponse*)response).statusCode]];
      [E2ERequest setByteCountReceived:receivedData.length];
    5. Close the trace request:
      NSError* error = nil;
      [E2ERequest endRequest:&error];
      Calling the E2ETraceRequest endRequest causes the E2ETrace request to be marked as ended.
      E2ETraceSteps can be ended by invoking their endStep method, which also ends all their active requests automatically:
      errorEndStep = nil;
      [E2EStep endStep:&errorEndStep];
    6. End the active ETE trace transaction:
      [E2ETransaction endTransaction:&unexpectedError];
      This call also traverses down and ends all active steps and their requests.
  • 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. 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 “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.
    NSURL* uploadURL = [NSURL URLWithString:@“<upload url>:port"];
    NSMutableURLRequest* request = [NSMutableURLRequest requestWithURL:[NSURL URLWithString:[NSString stringWithFormat:@"http://%@:%li/btx",, (long)uploadURL.port.integerValue]]];
    NSString* appCID = [Settings sharedInstance].appCID;
    [request setValue:appCID forHTTPHeaderField:@"X-SMP-APPCID"];
    SupportabilityUploader* uploader = [[SupportabilityUploader alloc] initWithHttpConversationManager:[SAPStoreManager sharedInstance].conversationManager urlRequest:request];
    [[[SAPSupportabilityFacade sharedManager] getE2ETraceManager] uploadBTX:uploader completion:^(NSError* error) {
        if ( !error )
            LOGDEB( @"BTX upload completed succesfully" );
            UIAlertView* alertView = [[UIAlertView alloc] initWithTitle:NSLocalizedString( @"BTX Upload", nil ) message:NSLocalizedString( @"BTX upload completed succesfully", nil ) delegate:nil cancelButtonTitle:@"OK" otherButtonTitles: nil];
            dispatch_async(dispatch_get_main_queue(), ^{
                [alertView show];
            LOGWAR( @"BTX upload failed: %@", error.localizedDescription );
            UIAlertView* alertView = [[UIAlertView alloc] initWithTitle:NSLocalizedString( @"BTX Upload", nil ) message:[NSString stringWithFormat:@"BTX upload failed: %@", error.localizedDescription] delegate:nil cancelButtonTitle:@"OK" otherButtonTitles: nil];
            dispatch_async(dispatch_get_main_queue(), ^{
                [alertView show];
    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.
  • 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.

    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.