# Swizzling and network capture

Copy as Markdown[Open in ChatGPT](https://chatgpt.com/?q=Read%20https%3A%2F%2Fcoralogix.com%2Fdocs%2Fuser-guides%2Frum%2Fsdk-installation%2Fapple%2Fios%2Fconfiguration%2Fswizzling-and-network-capture.md%20and%20help%20me%20with%20my%20question%20about%20this%20Coralogix%20documentation%20page.)[Open in Claude](https://claude.ai/new?q=Read%20https%3A%2F%2Fcoralogix.com%2Fdocs%2Fuser-guides%2Frum%2Fsdk-installation%2Fapple%2Fios%2Fconfiguration%2Fswizzling-and-network-capture.md%20and%20help%20me%20with%20my%20question%20about%20this%20Coralogix%20documentation%20page.)

### Enable Swizzling[​](#enable-swizzling "Direct link to Enable Swizzling")

Controls whether the SDK automatically swizzles system methods for instrumentation (e.g. `NSURLSession`, view-controller lifecycle). Enabled by default. Set to `false` only if another library conflicts with Coralogix's swizzling.

```
let options = CoralogixExporterOptions(coralogixDomain: CORALOGIX-DOMAIN,

                                        environment: "ENVIRONMENT",

                                        application: "APP-NAME",

                                        version: "APP-VERSION",

                                        publicKey: "API-KEY",

                                        enableSwizzling: false)
```

### Network Header & Payload Capture[​](#network-header--payload-capture "Direct link to Network Header & Payload Capture")

Use `networkExtraConfig` to opt-in to capturing request/response headers and bodies for specific URLs. By default no headers or payloads are captured.

Each `NetworkCaptureRule` matches requests by a **case-insensitive substring** of the absolute URL or by a **regex pattern**, and lets you allowlist which headers to forward and whether to capture bodies.

```
// Build regex patterns separately so the throwing init is handled cleanly.

// For known-good literal patterns you can use try! at development time;

// for patterns loaded from config use try? and check for nil before adding the rule.

let ordersPattern = try! NSRegularExpression(pattern: #"checkout/orders/\d+"#)



let options = CoralogixExporterOptions(coralogixDomain: CORALOGIX-DOMAIN,

                                        environment: "ENVIRONMENT",

                                        application: "APP-NAME",

                                        version: "APP-VERSION",

                                        publicKey: "API-KEY",

                                        networkExtraConfig: [

                                            // Capture Authorization header and response body for all /api/ requests

                                            NetworkCaptureRule(url: "/api/",

                                                               reqHeaders: ["Authorization", "X-Request-ID"],

                                                               resHeaders: ["Content-Type"],

                                                               collectResPayload: true),

                                            // Capture full request and response for URLs matching a regex

                                            NetworkCaptureRule(urlPattern: ordersPattern,

                                                               collectReqPayload: true,

                                                               collectResPayload: true)

                                        ])
```

Note

Only allowlist URLs and header names you are comfortable logging. Avoid capturing `Authorization` or other sensitive headers unless intentional. Body and header capture should not be used for endpoints that return or send PII or secrets. Request and response bodies over 1024 characters are **dropped** (not truncated) and do not appear in RUM.

### User Action Text Redaction (`shouldSendText`)[​](#user-action-text-redaction-shouldsendtext "Direct link to user-action-text-redaction-shouldsendtext")

Called before `target_element_inner_text` is recorded for a tapped view. Return `false` to redact text for sensitive views (e.g. fields showing account numbers or personal data) without disabling text capture globally.

Redacted text is reported as `***` rather than omitted, so a redacted tap stays distinguishable from a tap on an element that had no text at all. Views that are already masked — a view inside a [masked subtree](https://coralogix.com/docs/user-guides/rum/sdk-installation/apple/ios/SessionReplay/Sources/Docs.md#masking-a-specific-view-cxmask), a tap landing on session-replay-masked geometry (`maskText`, `maskAllImages`, SwiftUI `.cxMask()`), a password field, or a field with a sensitive `textContentType` — report `***` without consulting this closure, so their text is never passed to your code.

Interactions reported through the hybrid bridge (`setUserInteraction` — React Native, Flutter) are redacted on the same terms as native ones: the payload's coordinates are tested against the same mask geometry, and a masked tap's inner text is replaced with `***`.

This closure is called on the **main thread** only when the SDK would otherwise record text. Keep it fast and non-blocking.

```
let options = CoralogixExporterOptions(coralogixDomain: CORALOGIX-DOMAIN,

                                        environment: "ENVIRONMENT",

                                        application: "APP-NAME",

                                        version: "APP-VERSION",

                                        publicKey: "API-KEY",

                                        shouldSendText: { view, text in

                                            // Suppress text for any view tagged as sensitive

                                            return view.accessibilityIdentifier != "sensitiveLabel"

                                        })
```

### Custom Target Element Name (`resolveTargetName`)[​](#custom-target-element-name-resolvetargetname "Direct link to custom-target-element-name-resolvetargetname")

Override the `target_element` field in user action events with a business-friendly name instead of the raw UIKit class name. Return `nil` to fall back to the default class name (e.g. `"UIButton"`).

Note

`resolveTargetName` only affects `target_element`. The `element_classes` field always contains the real UIKit class name (e.g. `"UIButton"`) regardless of what the closure returns, so existing analytics queries and backwards-compatible dashboards that filter on `element_classes` continue to work unchanged.

This closure is called on the **main thread** on every tap event. Keep it fast and non-blocking.

```
let options = CoralogixExporterOptions(coralogixDomain: CORALOGIX-DOMAIN,

                                        environment: "ENVIRONMENT",

                                        application: "APP-NAME",

                                        version: "APP-VERSION",

                                        publicKey: "API-KEY",

                                        resolveTargetName: { view in

                                            switch view.accessibilityIdentifier {

                                            case "loginButton":   return "Login Button"

                                            case "checkoutBtn":   return "Checkout"

                                            case "addToCartBtn":  return "Add to Cart"

                                            default:              return nil // use UIKit class name

                                            }

                                        })
```
