Configure the Splunk RUM iOS agent
Configure the Splunk RUM agent for your iOS application.
To configure the Splunk RUM agent, pass the settings as methods when you initialize the SplunkRum
module. The Splunk Observability Cloud realm and RUM token are passed as arguments to the SplunkRum.install()
function.
The following example shows how to configure the RUM token, realm, deployment environment name, app name, and other settings:
- Swift
import SplunkAgent // Define endpoint configuration let endpointConfiguration = EndpointConfiguration( realm: "<YOUR_REALM>", rumAccessToken: "<YOUR_RUM_ACCESS_TOKEN>" ) // Construct agent configuration let agentConfiguration = AgentConfiguration( endpoint: endpointConfiguration, appName: "<YOUR_APP_NAME>", deploymentEnvironment: "<YOUR_DEPLOYMENT_ENVIRONMENT>" ) // Enable debug logging .enableDebugLogging(true) // Session sampling rate .sessionConfiguration(SessionConfiguration(samplingRate: 1.0)) // Global attributes .globalAttributes(MutableAttributes(dictionary: [ "strKey": .string("strVal"), "intKey": .int(7), "doubleKey": .double(1.5), "boolKey": .bool(true) ])) .spanInterceptor { spanData in var spanData = spanData if (spanData.name == "Drop This") { return nil } var spanAttributes = spanData.attributes // Change values for all URLs spanAttributes["http.url"] = .string("redacted") return spanData.settingAttributes(spanAttributes) } var agent: SplunkRum? do { // Install the agent agent = try SplunkRum.install(with: agentConfiguration) } catch { print("Unable to start the Splunk agent, error: \(error)") } // Example: Enable automated navigation tracking agent?.navigation.preferences.enableAutomatedTracking = true // Example: Start session replay agent?.sessionReplay.start()
- Objective-C
@import SplunkAgentObjC; SPLKEndpointConfiguration* endpointConfiguration = [[SPLKEndpointConfiguration alloc] initWithRealm:@"<YOUR_REALM>" rumAccessToken:@"<YOUR_RUM_ACCESS_TOKEN>"]; SPLKAgentConfiguration* agentConfiguration = [[SPLKAgentConfiguration alloc] initWithEndpoint:endpointConfiguration appName:@"<YOUR_APP_NAME>" deploymentEnvironment:@"<YOUR_DEPLOYMENT_ENVIRONMENT>"]; NSError* error = nil; SPLKAgent* agent = [SPLKAgent installWith:agentConfiguration error:&error]; if (agent == nil) { NSLog(@"Unable to start the Splunk agent, error: %@", [error description]); } else { // Example: Start session replay [[agent sessionReplay] start]; }
General settings
Use the following settings to configure the Splunk RUM agent for iOS applications. Use optional settings is only when you don't want their default values:
Option | Description |
---|---|
endpoint (required) | Sets the configuration needed to export data to an endpoint. Specifically two required inputs:
|
appName (required) | Sets the application name. If not set, the library uses CFBundleIdentifier defined in Info.plist. |
deploymentEnvironment (required) | Environment for all the spans produced by the application. For example, dev , test , or prod . |
appVersion (optional) | Sets the application version of the app being instrumented. If not set, the library uses CFBundleShortVersionString defined in Info.plist. |
enableDebugLogging (optional) | Activates debug logging. Default: false . |
samplingRate (optional) | Percentage of sessions to sample. Expressed as a proportion in the range 0.0 to 1.0 . Default: 1.0 . |
globalAttributes (optional) | Sets additional attributes added to all spans. See Manage global attributes. |
spanInterceptor (optional) | Closure of type ((SpanData) -> SpanData?)? to modify or ignore spans. See Filter spans. |
Instrumentation module settings
You can configure the following modules in the Splunk RUM agent.
isEnabled
is set to true
) do other configurations take effect. Except for navigation detection, all other modules are enabled by default.Network instrumentation
Configure automatic instrumentation for URLSession clients to make HTTP network requests.
Specify patterns for NSRegularExpression to exclude requests from instrumentation as in the example below.
import SplunkNetwork
let networkConfig: SplunkNetwork.NetworkInstrumentationConfiguration
do {
networkConfig = SplunkNetwork.NetworkInstrumentationConfiguration(
isEnabled: true,
ignoreURLs: try IgnoreURLs(patterns: [".*ads.*"])
)
} catch {
print("Failed to set IgnoreURLs in SplunkRum: \(error)")
networkConfig = SplunkNetwork.NetworkInstrumentationConfiguration(
isEnabled: true,
ignoreURLs: nil
)
}
// networkConfig can be passed to moduleConfiguration in SplunkRum.install as follows:
let agent: SplunkRum = try SplunkRum.install(
with: agentConfig,
moduleConfigurations: [networkConfig]
)
Crash reporting module
Slow rendering module
Slow rendering module is activated by default. It detects the number of slow frames or frozen frames in the application. To deactivate this module, see module configuration below.
import SplunkSlowFrameDetector
let slowFrameDetectionConfig = SplunkSlowFrameDetector.SlowFrameDetectorConfiguration(isEnable: true)
let agent: SplunkRum = try SplunkRum.install(with: agentConfig,
moduleConfigurations: [slowFrameDetectionConfig])
More details on how automatic detection is done - see Interaction detection module
Interaction detection is activated by default. You can deactivate it by setting the isEnabled
parameter as in the example below.
import SplunkInteractions
let interactionConfiguration = SplunkInteractions.InteractionsConfiguration(
isEnabled: true
)
let agent: SplunkRum = try SplunkRum.install(with: agentConfig,
moduleConfigurations: [interactionConfiguration])
See Interactions Data model for more details on data model and which user actions are captured