Skip to main content

🌎 Network logs

Gleap allows you to log all network requests, to get a better understanding of what went wrong. This usually works out of the box, but needs additional configuration, depending on the 3rd party libraries you are using within your applications.

Setting up network logs

Gleap.startNetworkRecording();

In certain circumstances you might need to pass an NSURLSessionConfiguration in order for Gleap to be able to log the network requests.

Gleap.startNetworkRecording(for: sessionConfiguration)

AFNetworking

To enable network logging for AFNetworking, create and use the following class.

// GleapAFURLSessionManager.h
#import <AFNetworking/AFNetworking.h>

@interface GleapAFURLSessionManager : AFHTTPSessionManager

@end

// GleapAFURLSessionManager.m
#import "GleapAFURLSessionManager.h"
#import <Gleap/Gleap.h>

@implementation GleapAFURLSessionManager

- (instancetype)initWithSessionConfiguration:(nullable NSURLSessionConfiguration *)configuration {
[Gleap startNetworkRecordingForSessionConfiguration: configuration];

return [super initWithSessionConfiguration:configuration];
}

@end

Example usage for the GleapAFURLSessionManager.

// Use the GleapAFURLSessionManager for all further requests
NSURLSessionConfiguration *configuration = [NSURLSessionConfiguration defaultSessionConfiguration];
GleapAFURLSessionManager *manager = [[GleapAFURLSessionManager alloc] initWithSessionConfiguration: configuration];

[manager GET: @"https://www.example.org/get" parameters:nil headers:nil progress:nil success:^(NSURLSessionDataTask * _Nonnull task, id _Nullable responseObject) {
NSLog(@"JSON: %@", responseObject);
} failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
NSLog(@"Error: %@", error);
}];

Alamofire

To enable network logging for Alamofire, create and use the following class.

import Alamofire
import Gleap

class GleapSessionManager: Alamofire.Session {
static let sharedManager: GleapSessionManager = {
let configuration = URLSessionConfiguration.default
Gleap.startNetworkRecording(for: configuration)
let manager = GleapSessionManager(configuration: configuration)
return manager
}()
}

Example usage for the GleapSessionManager.

GleapSessionManager.sharedManager.request("https://www.sample.org/get").response { response in
debugPrint(response)
}

Filtering network logs

Gleap allows you to strip off specific key/value pairs from network logs. This empowers you to easily remove sensitive data like tokens, passwords or usernames.

How does it work?

Log in to the Gleap dashboard and open the visual widget configurator. Now enable the network log filters option (within the advanced options tab). Once the option is enabled, you can add multiple keys to the array bellow, which should be excluded.

All keys, which you add to the exclusion list, will be loaded together with the widget configuration. Before sending a feedback item to our backend, the client SDK will loop through all network requests and stripe off all matching key/value pairs from the request headers, header-payload (if it's a JSON) and response body (if it's a JSON).

This ensures that sensitive information will never even leave the client application.

Example:

If you want to remove the Authorization bearer token from your requests, simply add "Authorization" to the list of keys.

Network log filter