Splunk MINT SDK for iOS (Legacy)

Splunk MINT SDK for iOS Developer Guide

Splunk MINT is no longer available for purchase as of January 29, 2021. Customers who have already been paying to ingest and process MINT data in Splunk Enterprise will continue to receive support until December 31, 2021, which is End of Life for all MINT products: App, Web Service (Management Console), SDK and Add-On.

Swift code example

This code example shows how to use the Splunk MINT SDK for iOS API with Swift.

import UIKit
//Importing the Splunk MINT SDK
import SplunkMint


class ViewController: UIViewController {

    
    func mintConfiguration() {
        
        //To preserve resources, the MINT SDK can be configured to send data only over a WIFI connection
        Mint.sharedInstance().enableFlushOnlyOverWiFi(true)
        
        //To protect privacy, the MINT SDK can be disabled so that no mobile telemetry is reported
        Mint.sharedInstance().enableUserOptOut(true)
        
        
        //The MINT SDK will start a new session if the application has not been in the foreground for
        //the duration of the session interval
        //Default session interval is 60 seconds
        Mint.sharedInstance().setSessionInterval(60)
        
        //In order to send NSLOG in crash reports, enableLogging must be set to true
        Mint.sharedInstance().enableLogging(true)
        
        //Set the number of NSLOG messages to send in the crash report
        Mint.sharedInstance().setLogging(20)
        
        //Set some form of userIdentifier for this session
        Mint.sharedInstance().userIdentifier = "splunk"
        
        //Set the applicationEnvironment, the available options are
        /*
        SPLAppEnvRelease
        SPLAppEnvStaging
        SPLAppEnvUserAcceptanceTesting
        SPLAppEnvTesting
        SPLAppEnvDevelopment
        */
        Mint.sharedInstance().applicationEnvironment = SPLAppEnvDevelopment
        
        //Disable crash reports
        Mint.sharedInstance().disableCrashReporter()
        
        //Disable network monitoring
        Mint.sharedInstance().disableNetworkMonitoring()
        
        //Selectively disable network monitoring on blacklisted url's
        Mint.sharedInstance().addURLToBlackList("https://google.com")
        
        //Breadcrumbs are only sent out in crash reports
        //Leave breadcrumbs throughout the source code to better debug the execution path
        Mint.sharedInstance().leaveBreadcrumb("Code inside mintConfiguration is executing")
        
        //Clear all breadcrumbs that have been added
        Mint.sharedInstance().clearBreadcrumbs()
        
        //Instantiating a MintLimitedExtraData object
        let myExtraData = MintLimitedExtraData()
        
        //Populating a MintLimitedExtraData object with key and value
        myExtraData.setValue("Value0", forKey: "Key0")
        
        
        //Adding local MintLimitedExtraData to global extra Data
        //Global value's will be overwritten if there is a key clash
        //Global extra data is sent out with each data point
        Mint.sharedInstance().addExtraData(myExtraData)
        
        //Add key and value to global extra data
        Mint.sharedInstance().addExtraData("Value1", forKey: "Key1")
        
        //Removing key and value from global extra data
        Mint.sharedInstance().removeExtraDataForKey("Key1")
        
        //Return hashmap of global extra data key and values
        Mint.sharedInstance().extraData()
        
        //Return value in the global extra data for the key passed in if it is present
        Mint.sharedInstance().extraDataForKey("Key0")
        
        //Clears global extra data
        Mint.sharedInstance().removeAllExtraData()
        
    }
    
    func mintInitialize() {
        
        //Initialize the SDK to use the MINT Backend to transport data
        //Will start a new session if one is not active
        Mint.sharedInstance().initAndStartSessionWithAPIKey("API_KEY")
        
        //Initialize the SDK to directly send data to a Splunk instance using
        //HTTP Event Collector
        //Will start a new session if one is not active
        Mint.sharedInstance().initAndStartSessionWithHECUrl("HEC_URL", token: "HEC_TOKEN")
        
    }
    
    func logSession() {
        
        //Will start a new session if one is not active
        Mint.sharedInstance().startSession()
        
        //Will close the active session
        Mint.sharedInstance().closeSession()
        
        
    }
    
    func mintData() {
        
        //Will return set remote settings
        Mint.sharedInstance().getDevSettings()
        
        //Will return the UUID of this MINT installation
        Mint.sharedInstance().getMintUUID()
        
        //Will return the sessionID of the current session
        Mint.sharedInstance().getSessionID()
        
        //Will return a list of the blacklisted url's
        Mint.sharedInstance().blacklistUrls()
        
        //Will return bool indicating if the SDK was initialized to use HEC as its transport mechanism
        Mint.sharedInstance().isHTTPEventCollectorEnabled()
        
        //Will return bool indicating if the SDK was initialized in any way
        Mint.sharedInstance().isInitialized()
        
        //Will return bool indicating if the SDK has an active session
        Mint.sharedInstance().isSessionActive()
        
    }
    
    
    func logView() {
        //Creating a local instance of MintLimitedExtraData to pass into our api calls
        let myExtraData = MintLimitedExtraData()
        myExtraData.setValue("Value0", forKey: "Key0")
        
        
        /*
        Views are automatically collected in native environments. For all other use cases we have 3 API calls to log
        custom views. The difference in the API calls are variations on how to pass in extra data.
        */
        
        
        Mint.sharedInstance().logViewWithCurrentViewName("ViewName")
        Mint.sharedInstance().logViewWithCurrentViewName("ViewName", extraDataKey: "Key1", extraDataValue: "Value1")
        Mint.sharedInstance().logViewWithCurrentViewName("ViewName", extraData: myExtraData)

    }
    
    func logTransaction() {
        //Creating a local instance of MintLimitedExtraData to pass into our api calls
        let myExtraData = MintLimitedExtraData()
        myExtraData.setValue("Value0", forKey: "Key0")
        
        
        /*
        Transactions are manually started through API calls.  Transactions have three separate END states:
        SUCCESS: The transaction was stopped normally through a transactionStop API Call
        CANCEL: The transactionw was cancelled, the API requires a reason for canceling a transaction
        FAIL: Active transactions are automatically failed when an exception crashes the application.
        
        For each API there are 3 variations based on the extra data being passed in.
        */
        
         //Starting 3 transactions
        var transactionId1 = Mint.sharedInstance().transactionStart("transaction1")
        var transactionId2 = Mint.sharedInstance().transactionStart("transaction2", extraDataKey: "Key1", extraDataValue: "Value1")
        var transactionId3 = Mint.sharedInstance().transactionStart("transaction3", extraData: myExtraData)
        
        //Stopping 3 transactions, will have status=SUCCESS
        Mint.sharedInstance().transactionStop(transactionId1)
        Mint.sharedInstance().transactionStop(transactionId2, extraDataKey: "Key1", extraDataValue: "Value1")
        Mint.sharedInstance().transactionStop(transactionId3, extraData: myExtraData)
        
        //Starting 3 transactions
        transactionId1 = Mint.sharedInstance().transactionStart("transaction1")
        transactionId2 = Mint.sharedInstance().transactionStart("transaction2", extraDataKey: "Key1", extraDataValue: "Value1")
        transactionId3 = Mint.sharedInstance().transactionStart("transaction3", extraData: myExtraData)
        
        //Cancelling 3 transactions, will have status=CANCEL
        Mint.sharedInstance().transactionCancel(transactionId1, reason: "bad_transaction")
        Mint.sharedInstance().transactionCancel(transactionId2, reason: "bad_transaction", extraDataKey: "Key1", extraDataValue: "Value1")
        Mint.sharedInstance().transactionCancel(transactionId3, reason: "bad_transaction", extraData: myExtraData)
        
        
        
        // There are also failed transactions, these are sent out automatically when the MINT SDK detects an
        //unhandled exception while a transaction is still in progress
        
        //transactionId1 = Mint.sharedInstance().transactionStart("transaction1")
        //transactionId2 = Mint.sharedInstance().transactionStart("transaction2", extraDataKey: "Key1", extraDataValue: "Value1")
        //transactionId3 = Mint.sharedInstance().transactionStart("transaction3", extraData: myExtraData)
        
        //let myArray = []
        //myArray[1]

    }

    func logEvent() {
        //Creating a local instance of MintLimitedExtraData to pass into our api calls
        let myExtraData = MintLimitedExtraData()
        myExtraData.setValue("Value0", forKey: "Key0")
        
        /*
        The logEvent API calls can be used to log notable events.
        There are 4 variations based on the extra data being passed in and the log level to display.
        The following are allowed log levels
        
        MintLogLevel:
        
        DebugLogLevel
        InfoLogLevel
        NoticeLogLevel
        WarningLogLevel
        ErrorLogLevel
        CriticalLogLevel
        AlertLogLevel
        EmergencyLogLevel
        */
        
        Mint.sharedInstance().logEventWithName("eventName")
        Mint.sharedInstance().logEventWithName("eventnName", logLevel: DebugLogLevel)
        Mint.sharedInstance().logEventWithName("eventName", logLevel: DebugLogLevel, extraDataKey: "Key1", extraDataValue: "Value1")
        Mint.sharedInstance().logEventWithName("eventName", logLevel: DebugLogLevel, extraData: myExtraData)
        
        
    }

    func mintTimer() {
        // The timer API calls can be usedd to create a high-precision timer in nanoseconds
        let timerId = Mint.sharedInstance().startTimerWithName("timer1")
        Mint.sharedInstance().stopTimerWithId(timerId)
    }

    func mintFlushData() {
        
        //Flush all data currently in memory and in the filesystem
        Mint.sharedInstance().flush();
        
    }
    
}
Last modified on 05 November, 2019
Objective-C code example   API Reference

This documentation applies to the following versions of Splunk MINT SDK for iOS (Legacy): 5.2.x


Was this topic useful?







You must be logged into splunk.com in order to post comments. Log in now.

Please try to keep this discussion focused on the content covered in this documentation topic. If you have a more general question about Splunk functionality or are experiencing a difficulty with Splunk, consider posting a question to Splunkbase Answers.

0 out of 1000 Characters