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)
}

Moya

The Gleap Moya plugin intercepts all requests and forwards them to the Gleap SDK.

Installation

Swift Package Manager

To get started, open your Xcode project and select File > Add packages...

Now you need to paste the following package URL to the search bar in the top right corner. Hit enter to confirm the search.

Package URL:

https://github.com/GleapSDK/Gleap-iOS-Moya-Plugin

Now select the Gleap package and hit Add package to add the Gleap SDK to your project.

Manual installation

Simply copy the GleapMoyaPlugin.swift (Sources/GleapMoyaPlugin) from this repository into your project. In addition to that make sure to install Gleap & Moya.

Using the plugin

After installing the plugin, you can use it by simply declaring it during the initialization of your Moya provider:

let provider = MoyaProvider<SampleType>(plugins: [GleapMoyaPlugin()])

Using an older Moya version?

If you are using an older Moya version, simply use the GleapMoyaPlugin from here.

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](./img/Bildschirmfoto 2021-12-14 um 11.16.06.png)

Blacklisting URLs

It is possible to blacklist URLs or parts of URLs. If a network request matches one of the entries in the blacklist, the network request won't be included in the network logs.

To add a new entry to the blacklist, simply navigate to your project in the Gleap dashboard and open the visual widget configurator. Now click on Developer options and add the desired URLs.