Skip to main content

Network events

Bugsee records the app's network traffic — requests, responses, headers and bodies — and attaches it to every report. No code is needed: capture starts with the SDK.

What is captured​

SourceWhat Bugsee records
URLSessionData, upload and download tasks, created with a completion handler or with a session delegate
WebSocketURLSessionWebSocketTask, SocketRocket (SRWebSocket) and Starscream connections (Starscream through its onConnect, onText, onData and onDisconnect callbacks, when they are visible to Objective-C): open, sent and received messages, close and errors
WKWebViewRequests the page makes with fetch and XMLHttpRequest, when BugseeOptionCaptureWebViewAdvanced is on (the default)

Bugsee's own traffic is not recorded.

A web view created before Bugsee launched is not set up for capture. Pass it to +[Bugsee addSecureWebView:] to add it.

Options​

OptionBugseeOptions propertyDefaultEffect
BugseeOptionCaptureNetworkmonitorNetworkYESMaster switch for network capture
BugseeOptionCaptureWebSocketmonitorWebSocketYESWebSocket traffic (needs BugseeOptionCaptureNetwork too)
BugseeOptionCaptureNetworkBodySizeLimitmaxNetworkBodySize20480Largest request or response body kept, in bytes
BugseeOptionCaptureNetworkBodyWithoutType—NOKeep bodies that have no Content-Type header
BugseeOptionCaptureNetworkOnLaunch—NOInstall interception synchronously during launchWithToken:
BugseeOptionCaptureNetworkUseDefaultSanitizersanitizeNetworkDataYESBuilt-in redaction of sensitive values — see Privacy: network
BugseeOptionCaptureWebViewAdvanced—YESScript injection into WKWebView pages, which network capture in web views relies on

Options with no BugseeOptions property are set by key — see Configuration.

Body size​

A body larger than BugseeOptionCaptureNetworkBodySizeLimit is left out whole, not cut, and the event records why (size_too_large). A limit of 0 keeps no bodies at all. WebSocket frames of exactly the limit are kept.

Bodies without a Content-Type​

With BugseeOptionCaptureNetworkBodyWithoutType set to NO (the default), a request or response body that has no Content-Type header is left out. WebSocket frames are kept either way.

Requests made at launch​

Capture is brought up off the main thread, so by default a request started in the same run-loop turn as the start of capture is in flight before interception is in place and is not recorded at all. Set BugseeOptionCaptureNetworkOnLaunch to YES to install interception synchronously when capture starts. It is off by default because it puts the interception install on the launch path.

The option does not help while a launch waits for the app to become active: requests started before the app becomes active (for example in application:didFinishLaunchingWithOptions: of a scene-based app) are not recorded either way.

BugseeOptions *options = [BugseeOptions defaultOptions];
options.maxNetworkBodySize = 64 * 1024;
[options updateLaunchOptions:@{
BugseeOptionCaptureNetworkOnLaunch : @YES,
}];

[Bugsee launchWithToken:@"<your_app_token>" options:options];

Filter network events​

A network filter sees each captured event before it is recorded, and can change it or drop it. Install it with a block, or implement bugseeFilterNetworkEvent:completionHandler: in your BugseeDelegate. If both are present, the block is used and the delegate method is not called.

[Bugsee setNetworkEventFilter:^(BugseeNetworkEvent *event,
BugseeNetworkFilterDecisionBlock decision) {
if ([event.url containsString:@"/internal/"]) {
decision(nil); // drop it
return;
}
decision(event);
}];

// Remove it again
[Bugsee setNetworkEventFilter:nil];
  • Call the decision block once, within 10 seconds. Past that the event is dropped, and a later call is ignored.
  • The filter sees the body as intercepted. The body size limit and the Content-Type rule are applied after it.
  • A filter turns off the built-in redaction. To keep it, run Bugsee.defaultNetworkSanitizer from your filter — see Privacy: network.
  • Breadcrumbs do not pass through the network filter — see Privacy: breadcrumbs.

Record your own network events​

Traffic Bugsee does not intercept — a C networking library, a custom socket protocol — can be recorded with addNetworkEvent:.

NSTimeInterval nowMs = [[NSDate date] timeIntervalSince1970] * 1000;

BugseeNetworkEvent *event = [BugseeNetworkEvent new];
event.ID = requestId;
event.type = BugseeNetwork;
event.bugseeNetworkEventType = BugseeNetworkEventComplete;
event.method = @"GET";
event.url = @"https://api.example.com/v1/orders";
event.responseCode = 200;
event.headers = @{@"Content-Type": @"application/json"};
event.body = responseData;
event.dataSize = responseData.length;
event.timestamp = nowMs;

// Recorded as is
[Bugsee addNetworkEvent:event];

// Or run through your network filter and the built-in redaction first
[Bugsee addNetworkEvent:event requiresFiltering:YES];
  • addNetworkEvent: records the event as is: it bypasses both your filter and the built-in redaction. Pass requiresFiltering:YES to run it through your filter, or through the built-in redaction when no filter is set.
  • A manually added event also feeds HTTP error detection and the http breadcrumbs, so a 5xx event you add can file a report.
  • Set timestamp, in milliseconds since 1970. Bugsee does not stamp the event for you, an event left at 0 is discarded, and a filter cannot move it.
  • Events with the same ID belong to the same request: record a BugseeNetworkEventBegin event when it starts and a BugseeNetworkEventComplete (or BugseeNetworkEventError, BugseeNetworkEventCancel) event when it ends.
  • Events are recorded only while the SDK is fully running (BugseeStatusLaunched).

BugseeNetworkEvent fields​

PropertyTypeNotes
ID (Swift id)NSStringTies the events of one request together
typeBugseeNetworkTypeBugseeNetwork, BugseeWebSocket or BugseeUDPSocket
bugseeNetworkEventTypeNSStringHTTP: BugseeNetworkEventBegin, BugseeNetworkEventComplete, BugseeNetworkEventCancel, BugseeNetworkEventError. WebSocket: BugseeWebSocketEventOpen, BugseeWebSocketEventSend, BugseeWebSocketEventMessage, BugseeWebSocketEventClose, BugseeWebSocketEventError
urlNSString
redirectedFromURLNSStringThe URL the request was redirected from
methodNSStringHTTP method
headersNSDictionary
bodyNSData
noBodyReasonNSStringWhy there is no body: BugseeNetworkBodySizeTooLarge, BugseeNetworkBodyUnsupportedContentType, BugseeNetworkBodyNoContentType, BugseeNetworkBodyCantReadData
dataSizeint64_tSize of the body, in bytes
responseCodeNSInteger0 for BugseeNetworkEventBegin
errorNSDictionary
mechanismNSStringWhich stack produced the event, for example URLSession
timestampNSTimeIntervalMilliseconds since 1970
Found an issue, typo, or wrong statement on this page? Report it now →