Configuration options
CoralogixExporterOptions reference
The fields accepted by CoralogixExporterOptions. Each one is described in detail in the sections below.
| Property | Type | Description | Required |
|---|---|---|---|
| coralogixDomain | CoralogixDomain | The Coralogix domain for your account's region. | Yes |
| publicKey | String | Coralogix token, the publicly-visible public_key value. | Yes |
| environment | String | Specifies the environment, such as development, staging, or production. | Yes |
| application | String | Name of the application. | Yes |
| version | String | Version of the application. | Yes |
| userContext | UserContext? | Configuration for user context. | No |
| debug | Bool | Turns internal debug logging on or off. | No |
| ignoreUrls | [String]? | URLs that partially match any regex in ignoreUrls are not traced. | No |
| urlMasking | UrlMaskingOptions | Adds to the built-in masking of sensitive URL parameters. Masking is always on. See "URL masking". | No |
| ignoreErrors | [String]? | Patterns for error messages that should not be sent to Coralogix. | No |
| labels | [String: Any]? | Labels added to every span. | No |
| beforeSend | (([String: Any]) -> [String: Any]?)? | Callback to inspect, modify, or discard each event before it reaches Coralogix. Receives the event as a dictionary; return nil to drop it. | No |
| tracesExporter | TracesExporterCallback?, i.e. ((CoralogixTraceExporterData) throws -> Void)? | Callback invoked for each exported span batch, for forwarding spans to your own collector. | No |
| networkExtraConfig | [NetworkCaptureRule]? | Per-URL rules for capturing request and response headers and payloads. Nothing is captured by default. Only allowlist URLs and header names you are comfortable logging, and note that bodies over 1024 characters are dropped rather than truncated. See "Swizzling and network capture" for the full rules. | No |
| shouldInstrumentNetworkRequest | ((URLRequest) -> Bool)? | Called before a URLSession request is instrumented. Return false to leave it untouched: no network event and no traceparent header. 2.26.0 and later. | No |
| proxyUrl | String? | Routes all RUM data through a proxy URL. See the Proxy URL guide for what the proxy must do. | No |
| traceParentInHeader | [String: Any]? | Configures W3C traceparent header propagation for distributed tracing. | No |
| collectIPData | Bool | Sends the client IP for region detection. Defaults to true. | No |
| sessionSampleRate | Int | Percentage of overall sessions tracked, 0–100. Defaults to 100. | No |
| excludeFromSampling | Set<ExcludableInstrumentation> | Instrumentations that bypass the sessionSampleRate gate, so their events are sent even from sessions that are not sampled in. Accepts errors, logs, network, userInteractions, mobileVitals, customSpan, customMeasurement, navigation and lifecycle. Defaults to empty. | No |
| alwaysTrackSessionsWithErrors | Bool | Keeps a session that sessionSampleRate leaves out on the device, and sends it whole if an error happens in it. Defaults to false. See "Sessions with errors". | No |
| onlyWithErrorConfig | SessionWithErrorConfig? | Settings for sessions sent only when they have an error. See "Sessions with errors". | No |
| enableSwizzling | Bool | Method swizzling for URLSession instrumentation. Defaults to true. | No |
| instrumentations | [InstrumentationType: Bool]? | Switches individual instrumentations off. All are active by default. Read once while the SDK initializes, so a later change takes effect only after shutdown() and a fresh CoralogixRum(options:). | No |
| mobileVitals | [MobileVitalsType: Bool]? | Switches individual mobile vitals detectors off. All are active by default. Read at initialization only, the same as instrumentations. | No |
| shouldSendText | ((UIView, String) -> Bool)? | Called before recording tapped text. Return false to redact it: the field is still sent, carrying *** instead of the text. Taps on a deliberately masked view (cxMask, SwiftUI .cxMask()), inside a masked subtree, or on a field carrying sensitive traits are redacted without consulting this closure. Text masked only by the replay's pixel policy (maskText, maskAllImages) still reaches it, so use this closure for anything you need kept out of events. | No |
| resolveTargetName | ((UIView) -> String?)? | Returns a human-readable name for a tapped view, used as target_element. Return nil to fall back to the class name. Runs on the main thread on every tap, so keep it fast. | No |
In React Native and Flutter apps, crashes and the life-cycle event sent when the app moves to the background do not pass through the JavaScript or Dart beforeSend. They are sent directly so they are not lost when the app closes.
Instrumentations
Turn on/off specific instrumentation, default to true. Each instrumentation is responsible for which data the SDK will track and collect for you.
let options = CoralogixExporterOptions(coralogixDomain: CORALOGIX-DOMAIN,
environment: "ENVIRONMENT",
application: "APP-NAME",
version: "APP-VERSION",
publicKey: "API-KEY",
instrumentations: [.mobileVitals: true,
.custom: true,
.errors: true,
.network: true,
.userActions: false,
.anr: true,
.lifeCycle: false])
Ignore errors
The ignoreErrors option allows you to exclude errors that meet specific criteria. Each pattern is compared with the event's error message and its error type, as an exact string or as a case-insensitive regular expression that can match part of the text. Every pattern is tried, so SIGSEGV drops segmentation-fault crashes and ANR drops ANR events.
let options = CoralogixExporterOptions(coralogixDomain: CORALOGIX-DOMAIN,
environment: "ENVIRONMENT",
application: "APP-NAME",
version: "APP-VERSION",
publicKey: "API-KEY",
ignoreErrors: []) //[".*errorcode=.*", "Im cusom Error"]
Ignore URLs
The ignoreUrls option allows you to exclude network requests that meet specific criteria. This options accepts a set of strings and regular expressions to match against the event's network url. Use regular expressions for exact matching as strings remove partial matches.
let options = CoralogixExporterOptions(coralogixDomain: CORALOGIX-DOMAIN,
environment: "ENVIRONMENT",
application: "APP-NAME",
version: "APP-VERSION",
publicKey: "API-KEY",
ignoreUrls: []) //[".*\\.il$","https://www.coralogix.com/academy"])
ignoreUrls matches the URL as your app sent it, before URL masking.
To decide per request rather than by URL, use shouldInstrumentNetworkRequest (2.26.0 and later). A request it returns false for gets no network event and no traceparent header. For example, skip the second request a custom URLProtocol makes for each app request, so the request is reported once:
let options = CoralogixExporterOptions(coralogixDomain: CORALOGIX-DOMAIN,
environment: "ENVIRONMENT",
application: "APP-NAME",
version: "APP-VERSION",
publicKey: "API-KEY",
shouldInstrumentNetworkRequest: { request in
URLProtocol.property(forKey: "MyProtocolHandled", in: request) == nil
})
URL masking
The SDK masks secrets in every URL it reports, including network request URLs, view names, URLs in error details, and URLs inside error and crash messages (only the URL changes; the rest of the message is kept). The value of a sensitive query or fragment parameter is replaced with [REDACTED] and the rest of the URL is kept, so https://example.com/callback?code=abc&page=2#access_token=xyz is reported as https://example.com/callback?code=[REDACTED]&page=2#access_token=[REDACTED].
A parameter is sensitive when its name contains token, secret, password, passwd, passphrase, apikey, signature, credential, jwt, session, sessid, oauth, saml, privatekey, accesskey, nonce, csrf or xsrf, or when its whole name is code, state, codeverifier, assertion, clientassertion, devicecode, usercode, bearer, auth, authorization, authcode, authkey, sig, hmac, key, pass, pwd, otp, oobcode, sid, ticket or sso. Names are compared ignoring case and any character that is not a letter or digit, so api_key, apiKey and API-Key all match. JWTs anywhere in the URL, credentials such as https://user:password@host, and session ids in the path such as ;jsessionid= are masked too.
Masking cannot be turned off and no built-in name can be removed. Use urlMasking to mask more:
import Coralogix
import Foundation
var maskedParams: [UrlMaskingOptions.Param] = ["tenant_id"]
if let customerPattern = try? NSRegularExpression(pattern: "^customer") {
maskedParams.append(.regex(customerPattern))
}
let options = CoralogixExporterOptions(coralogixDomain: CORALOGIX-DOMAIN,
environment: "ENVIRONMENT",
application: "APP-NAME",
version: "APP-VERSION",
publicKey: "API-KEY",
urlMasking: UrlMaskingOptions(
params: maskedParams,
mode: .mask))
| Field | Description |
|---|---|
| params | More parameter names to mask. A name such as "tenant_id" matches the whole name, compared the same way as the built-in names. .regex(_:) is tested against the decoded name. |
| mode | .mask (default) masks sensitive values only. .maskAll masks the value of every query and fragment parameter and keeps the names. .dropQuery removes the query and the fragment. |
beforeSend and tracesExporter receive the masked URL.
Label providers
Provide labels based on url or event
let options = CoralogixExporterOptions(coralogixDomain: CORALOGIX-DOMAIN,
environment: "ENVIRONMENT",
application: "APP-NAME",
version: "APP-VERSION",
publicKey: "API-KEY",
labels: ["item" : "item_number_5", "itemPrice" : 1000])
CollectIPData
Determines whether the SDK should collect the user's IP address and corresponding geolocation data. Defaults to true.
let options = CoralogixExporterOptions(coralogixDomain: CORALOGIX-DOMAIN,
environment: "ENVIRONMENT",
application: "APP-NAME",
version: "APP-VERSION",
publicKey: "API-KEY",
collectIPData: true)
Sample rate
Number between 0 and 100 as a percentage of sessions that report the full event stream.
A sampled-out session still starts. Network instrumentation stays installed so outgoing requests keep
carrying traceparent and your backend traces stay correlated across the whole population; the events
that would otherwise be reported are dropped before they leave the device. Session recording follows the
same decision: a session that is not sampled in records no frames, and recording resumes with the next
session that is sampled in. excludeFromSampling does not apply to session recording.
let options = CoralogixExporterOptions(coralogixDomain: CORALOGIX-DOMAIN,
environment: "ENVIRONMENT",
application: "APP-NAME",
version: "APP-VERSION",
publicKey: "API-KEY",
sessionSampleRate: 100)
Excluding instrumentations from session sampling
Opt specific event categories out of the sessionSampleRate gate so they keep exporting from sessions that are otherwise sampled out. Useful when you want a low session sample rate for general telemetry but still need every log and error captured.
This option only ever relaxes the sampling decision, so it does nothing on a session that is already
sampled in — and it never overrides instrumentations. If you switch an instrumentation off there and
also list it here, it stays off.
In the example below, only 10% of sessions are sampled in for the full event stream; the remaining 90% of sessions still export .logs and .errors, but every other category is dropped.
let options = CoralogixExporterOptions(coralogixDomain: CORALOGIX-DOMAIN,
environment: "ENVIRONMENT",
application: "APP-NAME",
version: "APP-VERSION",
publicKey: "API-KEY",
sessionSampleRate: 10,
excludeFromSampling: [.logs, .errors])
Accepted ExcludableInstrumentation cases:
.errors.logs.network.userInteractions.mobileVitals.customSpan.customMeasurement.navigation(2.21.0 and later).lifecycle(2.21.0 and later)
The default is an empty set: a sampled-out session then reports nothing, while still propagating trace context. Once you list any category, the SDK's own initialization events are reported alongside it.
Parity note: the Coralogix Browser SDK exposes the same option with matching semantics.
Network instrumentation and trace propagation
Network is the one instrumentation with three states rather than two: off, propagate-only, and fully reported. The header and the event are independent while the instrumentation is enabled — sampling can silence the event without silencing the header:
| Configuration | Header | network-request event |
|---|---|---|
| Session sampled in, network enabled | injected, flags 01 | reported |
instrumentations: [.network: false] — any session | not injected | not reported |
Session sampled out, .network not excluded | injected, flags 00 | not reported |
Session sampled out, excludeFromSampling: [.network], traceParentInHeader enabled | injected, flags 01 | reported |
Session sampled out, excludeFromSampling: [.network], traceParentInHeader disabled | not injected | reported |
The last byte of the traceparent header is the W3C sampled flag. From 2.21.0 it carries the session's
sampling decision for that request: 00 when the session is sampled out and the request is only
propagating trace context, 01 otherwise. Before 2.21.0 every request carried 01, so a backend that
honours the flag had no way to tell a propagate-only request apart from a reported one.
The flag reflects sampling alone, so 01 is not a guarantee that the event arrives. These still drop a
reported event after the header has gone out, and all of them leave the flag at 01:
- an event your
beforeSendcallback returnsnilfor - a request your app sends while the session is idle, which it becomes after 15 minutes without activity
On Flutter the traceparent header is injected from Dart rather than by this SDK, and an existing
header wins, so it currently always carries 01. React Native on iOS does not inject its own header —
this SDK instruments the request, so the flag behaves as described above.
instrumentations[.network] is the outer gate: switching it off removes network instrumentation
entirely, header included, and neither traceParentInHeader nor excludeFromSampling brings any of
it back. Sampling is deliberately weaker than that — a session that is merely sampled out keeps
injecting the header so your backend traces stay correlated, while reporting no events.
enableSwizzling: false overrides all of the above — with swizzling off the SDK never touches
NSURLSession, so there is no header and no native network event.
Telling excluded events apart in beforeSend
Every event carries session_context.isSessionSampledIn (read-only). false means the event reached export only because its category is listed in excludeFromSampling — the session itself was sampled out. Use it in beforeSend to apply your own filtering on top of the exclude list, e.g. keep only crashes and ANRs from sampled-out sessions:
beforeSend: { cxRum in
let session = cxRum["session_context"] as? [String: Any]
let sampledIn = session?["isSessionSampledIn"] as? Bool ?? true
let severity = (cxRum["event_context"] as? [String: Any])?["severity"] as? Int
// Session sampled out: forward only error-severity events, drop the rest.
if !sampledIn && severity != 5 {
return nil
}
return cxRum
}
Sessions with errors
Available in 2.25.0 and later. Keep a low sessionSampleRate and still get every session in which an error happens.
With alwaysTrackSessionsWithErrors: true, a session that is not sampled in is not dropped. Its events
are kept on the device until an error is reported in it. Then everything it kept is sent, and the rest
of the session is reported as it happens. A session that ends without an error sends nothing. A crash
counts too: the events from before the crash are sent with it on the next launch.
To hold every sampled-in session this way too, set onlyWithErrorConfig to
SessionWithErrorConfig(enable: true). Sessions that sessionSampleRate leaves out behave as
before (see excludeFromSampling) unless alwaysTrackSessionsWithErrors is also on.
let options = CoralogixExporterOptions(coralogixDomain: CORALOGIX-DOMAIN,
environment: "ENVIRONMENT",
application: "APP-NAME",
version: "APP-VERSION",
publicKey: "API-KEY",
sessionSampleRate: 10,
alwaysTrackSessionsWithErrors: true,
onlyWithErrorConfig: SessionWithErrorConfig(maxRumEvents: 5_000,
instrumentationsToSend: [.mobileVitals]))
SessionWithErrorConfig fields:
| Field | Type | Description |
|---|---|---|
| enable | Bool | Holds every sampled-in session until an error. Sessions that sessionSampleRate leaves out behave as before unless alwaysTrackSessionsWithErrors is also on. Defaults to false. |
| maxRumEvents | Int | How many events a session keeps while it waits for an error. Past this, what it kept is discarded and it starts again; a session whose events average over 16 KB, or take over 100 MB, is discarded sooner. Defaults to 5000; at most 20000, and 0 or less uses the default. |
| instrumentationsToSend | Set<ExcludableInstrumentation> | Categories sent at once instead of being held. Accepts errors, logs, network, userInteractions, mobileVitals, customSpan, customMeasurement, navigation and lifecycle. Defaults to empty: a held session sends nothing until it has an error. |
What to expect:
- An event with error severity triggers the session, including a network request that failed with an HTTP
error status. A critical event does not.
ignoreErrorsandbeforeSendapply first, so an error they drop or change to another severity does not trigger it. - An error reported right before the session changes, for example just before
createNewSession(), still counts for the session it was reported in. - While a session is held,
excludeFromSamplingsends nothing early. UseinstrumentationsToSendfor that. - Session recording does not record in a held session.
tracesExporterreceives a held session's spans only for events sent as they happen: from the error on, or listed ininstrumentationsToSend.- With
traceParentInHeaderenabled, network requests from a held session are always traced, even if the session is never sent. - Every event carries
session_context.onlyWithErrorMode(read-only),truein a held session. Events sent from the error on also carrysession_context.hasError: true.
Trace exporter
Forward span data to your own collector or backend by configuring a trace exporter callback. The callback receives each batch on its way out, in OTLP-compatible shape, and spans continue to flow to Coralogix when it is set.
Two things to know about where it sits in the pipeline: the batch has already been filtered, sampled and de-duplicated, so this is not a stream of every span produced; and it runs before beforeSend, so anything beforeSend would redact or drop is still present here. Sanitize attributes yourself before forwarding.
let options = CoralogixExporterOptions(coralogixDomain: CORALOGIX-DOMAIN,
environment: "ENVIRONMENT",
application: "APP-NAME",
version: "APP-VERSION",
publicKey: "API-KEY",
tracesExporter: { data in
// data.tracesData.resourceSpans[].scopeSpans[].spans[]
// data.jsonString — JSON-encoded OTLP payload, nil if encoding fails
if let json = data.jsonString {
// Hand the work to your own queue: this callback runs on the
// export path, so blocking here delays the batches behind it.
DispatchQueue.global(qos: .utility).async {
forwardToCustomCollector(json)
}
}
})