### Minimal Backtrace Client Setup Source: https://github.com/backtrace-labs/backtrace-cocoa/blob/master/_autodocs/README.md Initialize the Backtrace client with basic credentials. This is the simplest way to start sending reports. ```swift let credentials = BacktraceCredentials(endpoint: endpoint, token: token) BacktraceClient.shared = try BacktraceClient(credentials: credentials) ``` -------------------------------- ### Basic Usage Example Source: https://github.com/backtrace-labs/backtrace-cocoa/blob/master/_autodocs/SUMMARY.txt A fundamental code example demonstrating the initial setup and basic usage of the Backtrace client for sending reports. ```swift // Quick start example let credentials = BacktraceCredentials(token: "YOUR_TOKEN") let client = BacktraceClient(credentials: credentials) client.send(attributes: ["message": "Hello Backtrace!"]) ``` -------------------------------- ### Default Configuration Example Source: https://github.com/backtrace-labs/backtrace-cocoa/blob/master/_autodocs/api-reference/BacktraceMetricsSettings.md Example demonstrating the default configuration for Backtrace metrics submission. ```APIDOC ## Configuration Patterns ### Default Configuration ```swift let settings = BacktraceMetricsSettings() BacktraceClient.shared?.metrics.enable(settings: settings) ``` Sends metrics every 30 minutes or when 350 events collected, whichever comes first. Retries up to 3 times on failure. ``` -------------------------------- ### Swift Example: Initialize Backtrace SDK Source: https://github.com/backtrace-labs/backtrace-cocoa/blob/master/README.md Initialize the Backtrace SDK in your Swift application's AppDelegate. This snippet shows basic setup for capturing exceptions. ```swift import Backtrace @main struct Example_iOSApp: App { @UIApplicationDelegateAdaptor private var appDelegate: AppDelegate var body: some Scene { WindowGroup { ContentView() } } } class AppDelegate: NSObject, UIApplicationDelegate { func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey : Any]? = nil) -> Bool { let configuration = BacktraceConfiguration(token: "YOUR_TOKEN") Backtrace.shared?.install(configuration: configuration) return true } } ``` -------------------------------- ### Objective-C Example: Initialize Backtrace SDK Source: https://github.com/backtrace-labs/backtrace-cocoa/blob/master/README.md Initialize the Backtrace SDK in your Objective-C application's AppDelegate. This snippet demonstrates the basic setup for exception capture. ```objective-c #import "AppDelegate.h" #import @implementation AppDelegate - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { BacktraceConfiguration *configuration = [[BacktraceConfiguration alloc] initWithToken:@"YOUR_TOKEN"]; [[Backtrace shared] installWithConfiguration:configuration]; return YES; } ``` -------------------------------- ### BacktraceClientDelegate Implementation Example Source: https://github.com/backtrace-labs/backtrace-cocoa/blob/master/_autodocs/api-reference/BacktraceClientDelegate.md An example implementation of the BacktraceClientDelegate protocol within an AppDelegate. This demonstrates how to set up the Backtrace client and implement various delegate methods for handling report sending, request modification, server responses, connection failures, and rate limits. ```swift class AppDelegate: UIResponder, UIApplicationDelegate, BacktraceClientDelegate { func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool { let credentials = BacktraceCredentials( endpoint: URL(string: "https://my-universe.backtrace.io")!, token: "token" ) BacktraceClient.shared = try? BacktraceClient(credentials: credentials) BacktraceClient.shared?.delegate = self return true } // MARK: - BacktraceClientDelegate func willSend(_ report: BacktraceReport) -> BacktraceReport { // Add app version and user identifier report.attributes["app_version"] = Bundle.main.releaseVersionNumber report.attributes["user_id"] = UserDefaults.standard.string(forKey: "user_id") ?? "anonymous" return report } func willSendRequest(_ request: URLRequest) -> URLRequest { var modifiedRequest = request modifiedRequest.setValue("MyApp/1.0", forHTTPHeaderField: "User-Agent") return modifiedRequest } func serverDidResponse(_ result: BacktraceResult) { if result.backtraceStatus == .ok { print("Report sent successfully") } } func connectionDidFail(_ error: Error) { print("Connection failed: \(error)") } func didReachLimit(_ result: BacktraceResult) { print("Rate limit reached") } } ``` -------------------------------- ### Initialize BacktraceClientConfiguration with Credentials Source: https://github.com/backtrace-labs/backtrace-cocoa/blob/master/_autodocs/api-reference/BacktraceClientConfiguration.md Creates a configuration object with minimal setup using only Backtrace API credentials. Default settings are applied for other properties. ```swift let credentials = BacktraceCredentials( endpoint: URL(string: "https://my-universe.backtrace.io")!, token: "token-xyz" ) let config = BacktraceClientConfiguration(credentials: credentials) ``` -------------------------------- ### Initialize BacktraceClientConfiguration with Custom Settings Source: https://github.com/backtrace-labs/backtrace-cocoa/blob/master/_autodocs/api-reference/BacktraceClientConfiguration.md Creates a configuration object with custom settings for database, report limits, debugger attachment, and OOM detection. This example also shows how to modify database settings after initialization. ```swift let config = BacktraceClientConfiguration( credentials: credentials, reportsPerMin: 15, allowsAttachingDebugger: true, oomMode: .full ) let dbSettings = BacktraceDatabaseSettings() dbSettings.maxRecordCount = 100 dbSettings.retryLimit = 5 config.dbSettings = dbSettings BacktraceClient.shared = try BacktraceClient(configuration: config) ``` -------------------------------- ### Install Xcode Command Line Tools Source: https://github.com/backtrace-labs/backtrace-cocoa/blob/master/fastlane/README.md Ensure you have the latest Xcode command line tools installed before proceeding with Fastlane installation. ```shell xcode-select --install ``` -------------------------------- ### Initialization Logging Source: https://github.com/backtrace-labs/backtrace-cocoa/blob/master/_autodocs/api-reference/BacktraceLogger.md Configures and initializes the Backtrace client with credentials, configuration, and a logging destination. This is typically done at the start of the application. ```swift let credentials = BacktraceCredentials(submissionUrl: URL(string: "...")!) let config = BacktraceClientConfiguration(credentials: credentials) BacktraceClient.shared?.loggingDestinations = [ BacktraceFancyConsoleDestination(level: .debug) ] BacktraceClient.shared = try BacktraceClient(configuration: config) ``` -------------------------------- ### Initialize BacktraceClient with Error Handling Source: https://github.com/backtrace-labs/backtrace-cocoa/blob/master/_autodocs/errors.md Shows how to initialize the BacktraceClient using a do-catch block to handle potential errors during credential setup and initialization, including specific RepositoryErrors. ```swift do { let credentials = BacktraceCredentials( endpoint: URL(string: "https://my-universe.backtrace.io")!, token: token ) BacktraceClient.shared = try BacktraceClient(credentials: credentials) } catch let error as RepositoryError { print("Database error: (error.localizedDescription)") // Continue without offline storage } catch { print("Initialization failed: (error)") // Fallback initialization } ``` -------------------------------- ### BacktraceClientConfiguration Initializers Source: https://github.com/backtrace-labs/backtrace-cocoa/blob/master/_autodocs/SUMMARY.txt Illustrates the various ways to initialize BacktraceClientConfiguration, allowing for different setup patterns like development, production, and low-memory modes. ```swift // Example of one of the 4 initializers let config = BacktraceClientConfiguration(token: "YOUR_TOKEN") ``` -------------------------------- ### Basic BacktraceClient Integration Source: https://github.com/backtrace-labs/backtrace-cocoa/blob/master/_autodocs/api-reference/BacktraceCrashReporter.md Initializes the BacktraceClient with basic credentials. This is the fundamental setup for integrating crash reporting into your application. ```swift let credentials = BacktraceCredentials( endpoint: URL(string: "https://my-universe.backtrace.io")!, token: "token" ) let reporter = BacktraceCrashReporter() BacktraceClient.shared = try BacktraceClient( credentials: credentials, crashReporter: reporter ) ``` -------------------------------- ### Initialize BacktraceMetricsSettings Source: https://github.com/backtrace-labs/backtrace-cocoa/blob/master/_autodocs/api-reference/BacktraceMetricsSettings.md Creates a BacktraceMetricsSettings object with default values. This is the starting point for configuring metrics collection. ```swift let settings = BacktraceMetricsSettings() BacktraceClient.shared?.metrics.enable(settings: settings) ``` -------------------------------- ### Load Backtrace Credentials from Info.plist Source: https://github.com/backtrace-labs/backtrace-cocoa/blob/master/_autodocs/api-reference/BacktraceCredentials.md This example shows how to load Backtrace endpoint and token from the application's Info.plist file, providing a common pattern for managing credentials. ```swift // Example: Load from Info.plist guard let endpoint = Bundle.main.infoDictionary?["BACKTRACE_ENDPOINT"] as? String, let token = Bundle.main.infoDictionary?["BACKTRACE_TOKEN"] as? String else { fatalError("Backtrace credentials not configured in Info.plist") } let credentials = BacktraceCredentials( endpoint: URL(string: endpoint)!, token: token ) ``` -------------------------------- ### Development Backtrace Client Setup Source: https://github.com/backtrace-labs/backtrace-cocoa/blob/master/_autodocs/README.md Set up the Backtrace client for development with increased report limits and debugger attachment enabled. Includes custom console logging for debugging. ```swift let config = BacktraceClientConfiguration( credentials: credentials, reportsPerMin: 100, allowsAttachingDebugger: true ) BacktraceClient.shared?.loggingDestinations = [ BacktraceFancyConsoleDestination(level: .debug) ] ``` -------------------------------- ### BacktraceFancyConsoleDestination Example Output Source: https://github.com/backtrace-labs/backtrace-cocoa/blob/master/_autodocs/api-reference/BacktraceLogger.md Illustrates the console output format from `BacktraceFancyConsoleDestination`, showing timestamps, log levels, source file, and message. ```text 2025-02-15 09:30:45123 [💚 Backtrace] [BacktraceClient.swift]:45 init -> Report sent successfully 2025-02-15 09:30:46234 [💛 Backtrace] [BacktraceReporter.swift]:123 send -> Retry in 5 seconds 2025-02-15 09:30:47345 [💔 Backtrace] [Dispatcher.swift]:89 execute -> Connection failed ``` -------------------------------- ### Basic Breadcrumb Setup Source: https://github.com/backtrace-labs/backtrace-cocoa/blob/master/_autodocs/api-reference/BacktraceBreadcrumbs.md Enables breadcrumb collection and logs a basic user action. Breadcrumbs are automatically included in crash reports. ```swift BacktraceClient.shared?.enableBreadcrumbs() // Track user actions _ = BacktraceClient.shared?.addBreadcrumb("User tapped login button", type: .user) // When crash occurs, breadcrumbs are included in report ``` -------------------------------- ### Initialize BacktraceClient with Configuration Source: https://github.com/backtrace-labs/backtrace-cocoa/blob/master/_autodocs/api-reference/BacktraceClient.md Initialize the shared BacktraceClient instance using a BacktraceClientConfiguration object. This allows for more detailed setup, including reports per minute and attachment settings. ```swift let credentials = BacktraceCredentials(submissionUrl: URL(string: "...")!) let config = BacktraceClientConfiguration( credentials: credentials, reportsPerMin: 30, allowsAttachingDebugger: false, oomMode: .full ) BacktraceClient.shared = try BacktraceClient(configuration: config) ``` -------------------------------- ### Enable and Track Basic Events Source: https://github.com/backtrace-labs/backtrace-cocoa/blob/master/_autodocs/api-reference/BacktraceMetrics.md Enable the metrics client with default settings and start tracking user actions like sign-ups or button clicks. Use `addUniqueEvent` for distinct occurrences and `addSummedEvent` for events that can be counted. ```swift // Enable metrics BacktraceClient.shared?.metrics.enable(settings: BacktraceMetricsSettings()) // Track user actions BacktraceClient.shared?.metrics.addUniqueEvent(name: "user_signed_up") BacktraceClient.shared?.metrics.addSummedEvent(name: "button_clicked") BacktraceClient.shared?.metrics.addSummedEvent(name: "page_loaded") ``` -------------------------------- ### Implement BacktraceClientDelegate Source: https://github.com/backtrace-labs/backtrace-cocoa/blob/master/_autodocs/OVERVIEW.md Example of implementing the BacktraceClientDelegate protocol to modify reports before they are sent. Assign the delegate instance to the shared client. ```swift class AppDelegate: BacktraceClientDelegate { func willSend(_ report: BacktraceReport) -> BacktraceReport { report.attributes["user_id"] = userID return report } } BacktraceClient.shared?.delegate = appDelegate ``` -------------------------------- ### Conservative Storage Configuration Pattern Source: https://github.com/backtrace-labs/backtrace-cocoa/blob/master/_autodocs/api-reference/BacktraceDatabaseSettings.md Example of configuring BacktraceDatabaseSettings for conservative storage, limiting device space usage. ```APIDOC ## Configuration Patterns ### Conservative Storage (Limited Device Space) ```swift let dbSettings = BacktraceDatabaseSettings() dbSettings.maxRecordCount = 50 dbSettings.maxDatabaseSize = 25 // 25 MB dbSettings.retryBehaviour = .interval dbSettings.retryInterval = 5 dbSettings.retryLimit = 3 ``` Stores maximum 50 reports in 25 MB, retrying failed reports with 5-second intervals. ``` -------------------------------- ### Time-Based Only Submission Example Source: https://github.com/backtrace-labs/backtrace-cocoa/blob/master/_autodocs/api-reference/BacktraceMetricsSettings.md Example for submitting metrics solely based on time intervals, with a very high event count threshold. ```APIDOC ### Time-Based Only ```swift let settings = BacktraceMetricsSettings() settings.timeInterval = 600 // Submit every 10 minutes settings.maxEventsCount = 10000 // Very high count (unlikely to reach) BacktraceClient.shared?.metrics.enable(settings: settings) ``` Metrics submitted at fixed intervals regardless of event count. ``` -------------------------------- ### Add Backtrace Pod to Podfile Source: https://github.com/backtrace-labs/backtrace-cocoa/blob/master/README.md Install the Backtrace SDK using CocoaPods by adding the 'Backtrace' pod to your Podfile and specifying `use_frameworks!`. ```ruby use_frameworks! pod 'Backtrace' ``` -------------------------------- ### Production Backtrace Client Setup Source: https://github.com/backtrace-labs/backtrace-cocoa/blob/master/_autodocs/README.md Configure the Backtrace client for production with specific report limits and OOM detection. Ensures controlled report submission and crash monitoring. ```swift let config = BacktraceClientConfiguration( credentials: credentials, reportsPerMin: 30, oomMode: .full ) BacktraceClient.shared = try BacktraceClient(configuration: config) ``` -------------------------------- ### BacktraceResult Description Example Source: https://github.com/backtrace-labs/backtrace-cocoa/blob/master/_autodocs/api-reference/BacktraceResult.md Prints the message property of the BacktraceResult using its description. This is useful for logging and debugging purposes. ```swift BacktraceClient.shared?.send(message: "Test") { result in print(result) // Uses description, prints message } ``` -------------------------------- ### Initialize Breadcrumb Settings with Defaults Source: https://github.com/backtrace-labs/backtrace-cocoa/blob/master/_autodocs/api-reference/BacktraceBreadcrumbSettings.md Create a BacktraceBreadcrumbSettings object using all default values. This is a convenient way to start with standard configurations before making specific adjustments. ```swift let settings = BacktraceBreadcrumbSettings() BacktraceClient.shared?.enableBreadcrumbs(settings) ``` -------------------------------- ### Troubleshooting Power of 2 Requirement Source: https://github.com/backtrace-labs/backtrace-cocoa/blob/master/_autodocs/api-reference/BacktraceBreadcrumbSettings.md Example demonstrating how to ensure `maxQueueFileSizeBytes` is a power of 2 to avoid initialization errors. This is crucial for the breadcrumb storage mechanism. ```swift let settings = BacktraceBreadcrumbSettings( maxQueueFileSizeBytes: 65536 // Ensure this is power of 2 ) ``` -------------------------------- ### BacktraceBreadcrumbs.addBreadcrumb() Overloads Source: https://github.com/backtrace-labs/backtrace-cocoa/blob/master/_autodocs/SUMMARY.txt Provides examples of adding breadcrumbs to the Backtrace system, illustrating different methods for capturing contextual information. ```swift // Example of one of the 6 overloads BacktraceBreadcrumbs.addBreadcrumb("User logged in") ``` -------------------------------- ### Conservative Storage Configuration Source: https://github.com/backtrace-labs/backtrace-cocoa/blob/master/_autodocs/api-reference/BacktraceDatabaseSettings.md Example configuration for limited device space, storing a maximum of 50 reports within 25 MB and retrying failed reports with a 5-second interval. ```swift let dbSettings = BacktraceDatabaseSettings() dbSettings.maxRecordCount = 50 dbSettings.maxDatabaseSize = 25 // 25 MB dbSettings.retryBehaviour = .interval dbSettings.retryInterval = 5 dbSettings.retryLimit = 3 ``` -------------------------------- ### Custom File Logging Destination Source: https://github.com/backtrace-labs/backtrace-cocoa/blob/master/_autodocs/api-reference/BacktraceLogger.md Implements a custom logging destination that writes logs to a specified file URL. This example shows how to create a custom destination and use it. ```swift class FileLoggingDestination: BacktraceBaseDestination { let fileURL: URL init(fileURL: URL, level: BacktraceLogLevel) { self.fileURL = fileURL super.init(level: level) } override func log(level: BacktraceLogLevel, msg: String, file: String = #file, function: String = #function, line: Int = #line) { let logEntry = "\(Date()) [\(level)] \(msg)\n" if let data = logEntry.data(using: .utf8) { FileManager.default.createFile( atPath: fileURL.path, contents: data, attributes: nil ) } } } // Use custom destination let fileDestination = FileLoggingDestination( fileURL: logsURL.appendingPathComponent("backtrace.log"), level: .debug ) BacktraceClient.shared?.loggingDestinations = [fileDestination] ``` -------------------------------- ### Handle Report Submission Results Source: https://github.com/backtrace-labs/backtrace-cocoa/blob/master/_autodocs/errors.md Provides a callback example for submitting a report, demonstrating how to process the result and print messages based on the BacktraceStatus, such as success, server errors, rate limits, or unknown errors. ```swift BacktraceClient.shared?.send(error: error) { result in switch result.backtraceStatus { case .ok: print("✅ Submitted successfully") case .serverError: print("❌ Server error; will retry") case .limitReached: print("âš ī¸ Rate limit; resuming after cooldown") case .debuggerAttached: print("â„šī¸ Debugger attached; submission submission skipped") case .unknownError: print("❓ Unknown error: (result.message)") } } ``` -------------------------------- ### init(credentials:) Source: https://github.com/backtrace-labs/backtrace-cocoa/blob/master/_autodocs/api-reference/BacktraceClientConfiguration.md Initializes BacktraceClientConfiguration with the provided Backtrace credentials, using default settings for all other properties. ```APIDOC ## Initialization ### init(credentials:) ```swift @objc public init(credentials: BacktraceCredentials) ``` **Parameters**: - **credentials** (`BacktraceCredentials`): Required - API credentials for Backtrace. Creates configuration with minimal setup using default settings. **Example**: ```swift let credentials = BacktraceCredentials( endpoint: URL(string: "https://my-universe.backtrace.io")!, token: "token-xyz" ) let config = BacktraceClientConfiguration(credentials: credentials) ``` ``` -------------------------------- ### Initialize from Environment Variables Source: https://github.com/backtrace-labs/backtrace-cocoa/blob/master/_autodocs/configuration.md Reads Backtrace endpoint and token from environment variables to initialize the SDK. Ensure these variables are set before application launch. ```swift if let endpoint = ProcessInfo.processInfo.environment["BACKTRACE_ENDPOINT"], let token = ProcessInfo.processInfo.environment["BACKTRACE_TOKEN"], let endpointUrl = URL(string: endpoint) { let credentials = BacktraceCredentials(endpoint: endpointUrl, token: token) BacktraceClient.shared = try BacktraceClient(credentials: credentials) } ``` -------------------------------- ### Frequent Submission Example Source: https://github.com/backtrace-labs/backtrace-cocoa/blob/master/_autodocs/api-reference/BacktraceMetricsSettings.md Example for frequent metric submission, useful during development or for critical applications. ```APIDOC ### Frequent Submission ```swift let settings = BacktraceMetricsSettings() settings.timeInterval = 300 // Submit every 5 minutes settings.maxEventsCount = 200 // Or when 200 events collected settings.retryInterval = 5 // Quick retries BacktraceClient.shared?.metrics.enable(settings: settings) ``` Useful for real-time metrics monitoring during development or for critical applications. ``` -------------------------------- ### Initialize BacktraceClientConfiguration (Full with Database Limits) Source: https://github.com/backtrace-labs/backtrace-cocoa/blob/master/_autodocs/api-reference/BacktraceClientConfiguration.md Shows a full configuration including database settings with custom limits for records, size, and retries, along with reporting and OOM detection settings. ```swift let creds = BacktraceCredentials(endpoint: URL(string: "...")!, token: "...") let dbSettings = BacktraceDatabaseSettings() dbSettings.maxRecordCount = 50 dbSettings.maxDatabaseSize = 10 dbSettings.retryLimit = 5 let config = BacktraceClientConfiguration( credentials: creds, dbSettings: dbSettings, reportsPerMin: 20, allowsAttachingDebugger: true, oomMode: .light ) BacktraceClient.shared = try BacktraceClient(configuration: config) ``` -------------------------------- ### Count-Based Only Submission Example Source: https://github.com/backtrace-labs/backtrace-cocoa/blob/master/_autodocs/api-reference/BacktraceMetricsSettings.md Example for submitting metrics solely based on event count, disabling time-based submission. ```APIDOC ### Count-Based Only ```swift let settings = BacktraceMetricsSettings() settings.timeInterval = 0 // Disable time-based submission settings.maxEventsCount = 100 // Submit only when event count reached BacktraceClient.shared?.metrics.enable(settings: settings) ``` Metrics submitted only when event limit is reached, regardless of time elapsed. ``` -------------------------------- ### Conservative Submission Example Source: https://github.com/backtrace-labs/backtrace-cocoa/blob/master/_autodocs/api-reference/BacktraceMetricsSettings.md Example for conservative metric submission, reducing network overhead while ensuring reliable capture. ```APIDOC ### Conservative Submission ```swift let settings = BacktraceMetricsSettings() settings.timeInterval = 3600 // Submit every 1 hour settings.maxEventsCount = 500 // Or when 500 events collected settings.retryInterval = 30 // Longer retry intervals settings.retryLimit = 5 // More retries BacktraceClient.shared?.metrics.enable(settings: settings) ``` Reduces network overhead while still capturing metrics reliably. ``` -------------------------------- ### init(credentials:dbSettings:reportsPerMin:allowsAttachingDebugger:oomMode:) Source: https://github.com/backtrace-labs/backtrace-cocoa/blob/master/_autodocs/api-reference/BacktraceClientConfiguration.md Initializes the Backtrace client configuration with specified settings. This is the primary initializer for setting up the client. ```APIDOC ## init(credentials:dbSettings:reportsPerMin:allowsAttachingDebugger:oomMode:) ### Description Initializes the Backtrace client configuration with specified settings. This is the primary initializer for setting up the client. ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body * **credentials** (BacktraceCredentials) - Required - API authentication credentials. * **dbSettings** (BacktraceDatabaseSettings) - Optional - Local storage configuration. Defaults to an empty `BacktraceDatabaseSettings`. * **reportsPerMin** (Int) - Optional - The maximum number of reports to send per minute. Defaults to 30. * **allowsAttachingDebugger** (Bool) - Optional - Whether to allow attaching a debugger. Defaults to false. * **oomMode** (BacktraceOOMMode) - Optional - Configuration for Out-Of-Memory detection. Defaults to `.none`. ### Request Example ```swift let creds = BacktraceCredentials(submissionUrl: URL(string: "...")!) let dbSettings = BacktraceDatabaseSettings() dbSettings.maxRecordCount = 50 dbSettings.maxDatabaseSize = 10 dbSettings.retryLimit = 5 let config = BacktraceClientConfiguration( credentials: creds, dbSettings: dbSettings, reportsPerMin: 20, allowsAttachingDebugger: true, oomMode: .light ) BacktraceClient.shared = try BacktraceClient(configuration: config) ``` ### Response None (This is an initializer) ### Related Types - `BacktraceCredentials` - `BacktraceDatabaseSettings` - `BacktraceMetricsSettings` - `BacktraceBreadcrumbSettings` - `BacktraceClient` ``` -------------------------------- ### Initialize Backtrace SDK with Configuration Source: https://github.com/backtrace-labs/backtrace-cocoa/blob/master/_autodocs/README.md Initialize the Backtrace SDK using a BacktraceClientConfiguration object, allowing for more detailed settings like reportsPerMin. ```swift let config = BacktraceClientConfiguration(credentials: credentials, reportsPerMin: 30) BacktraceClient.shared = try BacktraceClient(configuration: config) ``` -------------------------------- ### Get Application Name Constant Source: https://github.com/backtrace-labs/backtrace-cocoa/blob/master/_autodocs/types.md Retrieves the application's display name from the bundle. ```swift public let applicationName = Bundle.main.displayName ``` -------------------------------- ### init(credentials:dbSettings:reportsPerMin:allowsAttachingDebugger:detectOOM:) Source: https://github.com/backtrace-labs/backtrace-cocoa/blob/master/_autodocs/api-reference/BacktraceClientConfiguration.md Initializes the Backtrace client configuration with specified settings. This initializer is deprecated and maps `detectOOM` to `oomMode`. ```APIDOC ## init(credentials:dbSettings:reportsPerMin:allowsAttachingDebugger:detectOOM:) ### Description Initializes the Backtrace client configuration with specified settings. This initializer is deprecated and maps `detectOOM` to `oomMode` for backward compatibility. **Deprecated**: Use `init(credentials:dbSettings:reportsPerMin:allowsAttachingDebugger:oomMode:)` instead. ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body * **credentials** (BacktraceCredentials) - Required - API authentication credentials. * **dbSettings** (BacktraceDatabaseSettings) - Optional - Local storage configuration. Defaults to an empty `BacktraceDatabaseSettings`. * **reportsPerMin** (Int) - Optional - The maximum number of reports to send per minute. Defaults to 30. * **allowsAttachingDebugger** (Bool) - Optional - Whether to allow attaching a debugger. Defaults to false. * **detectOOM** (Bool) - Optional - Whether to detect Out-Of-Memory conditions. Defaults to false. Maps to `oomMode`. ### Request Example ```swift let creds = BacktraceCredentials(submissionUrl: URL(string: "...")!) let config = BacktraceClientConfiguration(credentials: creds, detectOOM: true) BacktraceClient.shared = try BacktraceClient(configuration: config) ``` ### Response None (This is an initializer) ### Related Types - `BacktraceCredentials` - `BacktraceDatabaseSettings` - `BacktraceMetricsSettings` - `BacktraceBreadcrumbSettings` - `BacktraceClient` ``` -------------------------------- ### Get Build Version Constant Source: https://github.com/backtrace-labs/backtrace-cocoa/blob/master/_autodocs/types.md Retrieves the application's build version number from the bundle. ```swift public let buildVersion = Bundle.main.buildVersionNumber ``` -------------------------------- ### Get Application Version Constant Source: https://github.com/backtrace-labs/backtrace-cocoa/blob/master/_autodocs/types.md Retrieves the application's release version number from the bundle. ```swift public let applicationVersion = Bundle.main.releaseVersionNumber ``` -------------------------------- ### Enable Features at Runtime Source: https://github.com/backtrace-labs/backtrace-cocoa/blob/master/_autodocs/configuration.md Demonstrates how to enable metrics and breadcrumbs at runtime if they were not configured during client initialization. ```swift // Enable metrics if not done at initialization let metricsSettings = BacktraceMetricsSettings() metricsSettings.timeInterval = 900 BacktraceClient.shared?.metrics.enable(settings: metricsSettings) // Enable breadcrumbs if not done at initialization let breadcrumbSettings = BacktraceBreadcrumbSettings() BacktraceClient.shared?.enableBreadcrumbs(breadcrumbSettings) ``` -------------------------------- ### Add Breadcrumb with Check Source: https://github.com/backtrace-labs/backtrace-cocoa/blob/master/_autodocs/errors.md A simple example of adding a breadcrumb and checking if it was successfully added. If not, a warning is printed to the console. ```swift let added = BacktraceClient.shared?.addBreadcrumb(message) ?? false if !added { print("Warning: Breadcrumb discarded") } ``` -------------------------------- ### Full Backtrace SDK Initialization with Custom Settings Source: https://github.com/backtrace-labs/backtrace-cocoa/blob/master/_autodocs/configuration.md Initializes the Backtrace client with a comprehensive configuration, including custom database, metrics, and breadcrumb settings. This allows for fine-grained control over reporting, storage, and feature enablement. ```swift // Create credentials let credentials = BacktraceCredentials( endpoint: URL(string: "https://my-universe.backtrace.io")!, token: "token" ) // Configure database let dbSettings = BacktraceDatabaseSettings() dbSettings.maxRecordCount = 100 dbSettings.maxDatabaseSize = 50 dbSettings.retryBehaviour = .interval dbSettings.retryInterval = 10 dbSettings.retryLimit = 5 // Configure metrics let metricsSettings = BacktraceMetricsSettings() metricsSettings.timeInterval = 900 metricsSettings.maxEventsCount = 500 // Configure breadcrumbs (iOS only) let breadcrumbSettings = BacktraceBreadcrumbSettings( maxIndividualBreadcrumbSizeBytes: 8192, maxQueueFileSizeBytes: 128 * 1024, breadcrumbTypes: [.user, .navigation, .error], breadcrumbLevel: .warning ) // Create main configuration let config = BacktraceClientConfiguration( credentials: credentials, dbSettings: dbSettings, reportsPerMin: 20, allowsAttachingDebugger: true, oomMode: .full ) // Update optional settings config.metricsSettings = metricsSettings #if os(iOS) && !targetEnvironment(macCatalyst) config.breadcrumbSettings = breadcrumbSettings #endif // Initialize client BacktraceClient.shared = try BacktraceClient(configuration: config) // Enable features BacktraceClient.shared?.metrics.enable(settings: metricsSettings) BacktraceClient.shared?.enableBreadcrumbs(breadcrumbSettings) ``` -------------------------------- ### init(credentials:dbSettings:reportsPerMin:allowsAttachingDebugger:oomMode:) Source: https://github.com/backtrace-labs/backtrace-cocoa/blob/master/_autodocs/api-reference/BacktraceClientConfiguration.md Initializes BacktraceClientConfiguration with specified credentials and allows customization of database settings, report limits, debugger attachment, and OOM detection mode. ```APIDOC ### init(credentials:dbSettings:reportsPerMin:allowsAttachingDebugger:oomMode:) ```swift @objc public init(credentials: BacktraceCredentials, dbSettings: BacktraceDatabaseSettings = BacktraceDatabaseSettings(), reportsPerMin: Int = 30, allowsAttachingDebugger: Bool = false, oomMode: BacktraceOomMode = .none) ``` **Parameters**: - **credentials** (`BacktraceCredentials`): Required - API credentials. - **dbSettings** (`BacktraceDatabaseSettings`): Optional - Database configuration. Defaults to `BacktraceDatabaseSettings()`. - **reportsPerMin** (`Int`): Optional - Reports per minute limit. Defaults to `30`. - **allowsAttachingDebugger** (`Bool`): Optional - Allow debugging. Defaults to `false`. - **oomMode** (`BacktraceOomMode`): Optional - OOM detection mode. Defaults to `.none`. **Example**: ```swift let config = BacktraceClientConfiguration( credentials: credentials, reportsPerMin: 15, allowsAttachingDebugger: true, oomMode: .full ) let dbSettings = BacktraceDatabaseSettings() dbSettings.maxRecordCount = 100 dbSettings.retryLimit = 5 config.dbSettings = dbSettings BacktraceClient.shared = try BacktraceClient(configuration: config) ``` ``` -------------------------------- ### Handle BacktraceUrlParsingError Source: https://github.com/backtrace-labs/backtrace-cocoa/blob/master/_autodocs/api-reference/BacktraceCredentials.md This example demonstrates how to catch and handle potential errors when initializing BacktraceCredentials with a submission URL that cannot be parsed. ```swift do { let badUrl = URL(string: "invalid-url")! let creds = BacktraceCredentials(submissionUrl: badUrl) } catch BacktraceUrlParsingError.invalidInput(let urlString) { print("Could not parse URL: \(urlString)") } ``` -------------------------------- ### Configure Backtrace Client for Beta/Testing Source: https://github.com/backtrace-labs/backtrace-cocoa/blob/master/_autodocs/configuration.md Sets up the Backtrace client with beta credentials, allows debugger attachment, and enables all breadcrumb types and levels for testing. ```swift let config = BacktraceClientConfiguration( credentials: betaCredentials, reportsPerMin: 50, allowsAttachingDebugger: true // Allow debugger ) let dbSettings = BacktraceDatabaseSettings() dbSettings.maxRecordCount = 200 dbSettings.retryBehaviour = .interval dbSettings.retryInterval = 5 config.dbSettings = dbSettings let breadcrumbSettings = BacktraceBreadcrumbSettings( breadcrumbTypes: BacktraceBreadcrumbType.all, // All types breadcrumbLevel: .debug // All levels ) BacktraceClient.shared = try BacktraceClient(configuration: config) BacktraceClient.shared?.enableBreadcrumbs(breadcrumbSettings) ``` -------------------------------- ### Handling Network Errors with BacktraceClient Source: https://github.com/backtrace-labs/backtrace-cocoa/blob/master/_autodocs/errors.md Example of checking for server errors, which often indicate network issues, when sending a message. ```swift BacktraceClient.shared?.send(message: "Test") { result in if result.backtraceStatus == .serverError { // Likely a network error; SDK will retry } } ``` -------------------------------- ### Load Configuration from Info.plist Source: https://github.com/backtrace-labs/backtrace-cocoa/blob/master/_autodocs/configuration.md Reads Backtrace configuration from the application's Info.plist and initializes the SDK if enabled. Requires endpoint, token, and an enabled flag. ```swift if let endpoint = Bundle.main.infoDictionary?["BACKTRACE_ENDPOINT"] as? String, let token = Bundle.main.infoDictionary?["BACKTRACE_TOKEN"] as? String, let enabled = Bundle.main.infoDictionary?["BACKTRACE_ENABLED"] as? Bool, enabled { let credentials = BacktraceCredentials( endpoint: URL(string: endpoint)!, token: token ) BacktraceClient.shared = try BacktraceClient(credentials: credentials) } ``` -------------------------------- ### loggingDestinations Source: https://github.com/backtrace-labs/backtrace-cocoa/blob/master/_autodocs/api-reference/BacktraceClient.md Allows getting and setting the current logging destinations for the Backtrace client. This enables customization of where log messages are sent. ```APIDOC ## loggingDestinations ### Description Get or set current logging destinations. ### Method Signature (Getter) `public var loggingDestinations: Set` ### Method Signature (Setter) `public var loggingDestinations: Set` ### Example ```swift BacktraceClient.shared?.loggingDestinations = [ BacktraceFancyConsoleDestination(level: .debug) ] ``` ``` -------------------------------- ### init() Initializer Source: https://github.com/backtrace-labs/backtrace-cocoa/blob/master/_autodocs/api-reference/BacktraceMetricsSettings.md Creates BacktraceMetricsSettings with default values for all properties. ```APIDOC ## Initialization ### init() ```swift @objc public init() ``` Creates BacktraceMetricsSettings with default values. **Defaults**: - `maxEventsCount`: 350 - `timeInterval`: 1800 (30 minutes) - `retryInterval`: 10 seconds - `retryLimit`: 3 - `customSubmissionUrl`: "" (use default) **Example**: ```swift let settings = BacktraceMetricsSettings() BacktraceClient.shared?.metrics.enable(settings: settings) ``` ``` -------------------------------- ### Configure Backtrace Client for Development Source: https://github.com/backtrace-labs/backtrace-cocoa/blob/master/_autodocs/configuration.md Sets up the Backtrace client with a high report limit and allows attaching the debugger. Includes database and metrics settings for development. ```swift let config = BacktraceClientConfiguration( credentials: credentials, reportsPerMin: 100, // High limit during testing allowsAttachingDebugger: true // Report even with debugger ) let dbSettings = BacktraceDatabaseSettings() dbSettings.maxRecordCount = 500 // Keep many reports dbSettings.retryBehaviour = .interval dbSettings.retryInterval = 2 // Fast retries let metricsSettings = BacktraceMetricsSettings() metricsSettings.timeInterval = 300 // Send every 5 minutes #if DEBUG config.dbSettings = dbSettings config.metricsSettings = metricsSettings BacktraceClient.shared?.loggingDestinations = [ BacktraceFancyConsoleDestination(level: .debug) ] BacktraceClient.shared?.enableBreadcrumbs() #endif ``` -------------------------------- ### BacktraceClient Initialization Source: https://github.com/backtrace-labs/backtrace-cocoa/blob/master/_autodocs/api-reference/BacktraceClient.md Initializes the BacktraceClient. This is the main entry point for the SDK and should be configured during app startup. ```APIDOC ## init(credentials:) ### Description Initializes the Backtrace client with API credentials. ### Method `convenience init(credentials: BacktraceCredentials) throws` ### Parameters #### Path Parameters * None #### Query Parameters * None #### Request Body * None ### Parameters - **credentials** (BacktraceCredentials) - Required - API credentials for Backtrace services ### Throws Error if initialization fails. ### Example ```swift let credentials = BacktraceCredentials( endpoint: URL(string: "https://my-universe.backtrace.io")!, token: "my-token" ) BacktraceClient.shared = try BacktraceClient(credentials: credentials) ``` ``` ```APIDOC ## init(credentials:crashReporter:) ### Description Initializes the Backtrace client with API credentials and a custom crash reporter. ### Method `convenience init(credentials: BacktraceCredentials, crashReporter: BacktraceCrashReporter) throws` ### Parameters #### Path Parameters * None #### Query Parameters * None #### Request Body * None ### Parameters - **credentials** (BacktraceCredentials) - Required - API credentials - **crashReporter** (BacktraceCrashReporter) - Required - Custom crash reporter instance ### Throws Error if initialization fails. ``` ```APIDOC ## init(configuration:) ### Description Initializes the Backtrace client with a configuration object. ### Method `convenience init(configuration: BacktraceClientConfiguration) throws` ### Parameters #### Path Parameters * None #### Query Parameters * None #### Request Body * None ### Parameters - **configuration** (BacktraceClientConfiguration) - Required - Client configuration object ### Throws Error if initialization fails. ### Example ```swift let credentials = BacktraceCredentials(submissionUrl: URL(string: "...")!) let config = BacktraceClientConfiguration( credentials: credentials, reportsPerMin: 30, allowsAttachingDebugger: false, oomMode: .full ) BacktraceClient.shared = try BacktraceClient(configuration: config) ``` ``` ```APIDOC ## init(configuration:crashReporter:) ### Description Initializes the Backtrace client with a configuration object and a custom crash reporter. ### Method `convenience init(configuration: BacktraceClientConfiguration, crashReporter: BacktraceCrashReporter) throws` ### Parameters #### Path Parameters * None #### Query Parameters * None #### Request Body * None ### Parameters - **configuration** (BacktraceClientConfiguration) - Required - Client configuration - **crashReporter** (BacktraceCrashReporter) - Required - Custom crash reporter instance ### Throws Error if initialization fails. ``` -------------------------------- ### Checking File Existence Before Sending Attachment Source: https://github.com/backtrace-labs/backtrace-cocoa/blob/master/_autodocs/errors.md Example of verifying if a file exists at a given path before attempting to send it as an attachment with the Backtrace SDK. ```swift let filePath = "/path/to/file.txt" if FileManager.default.fileExists(atPath: filePath) { BacktraceClient.shared?.send(attachmentPaths: [filePath]) { result in // Safe to send } } ``` -------------------------------- ### Initialize BacktraceDatabaseSettings with Defaults Source: https://github.com/backtrace-labs/backtrace-cocoa/blob/master/_autodocs/api-reference/BacktraceDatabaseSettings.md Creates a BacktraceDatabaseSettings instance using all default values. Custom settings can then be applied. ```swift let dbSettings = BacktraceDatabaseSettings() dbSettings.maxRecordCount = 100 dbSettings.retryLimit = 5 ``` -------------------------------- ### Initialize Backtrace SDK with Credentials Source: https://github.com/backtrace-labs/backtrace-cocoa/blob/master/_autodocs/README.md Initialize the Backtrace SDK using BacktraceCredentials. This is the primary method for setting up crash reporting and error tracking. ```swift let credentials = BacktraceCredentials(endpoint: URL(string: "...")!, token: "...") BacktraceClient.shared = try BacktraceClient(credentials: credentials) ``` -------------------------------- ### Handling Persistent Repository Initialization Errors Source: https://github.com/backtrace-labs/backtrace-cocoa/blob/master/_autodocs/errors.md Demonstrates catching and handling errors during the initialization of the persistent repository, with a fallback to disabling offline storage. ```swift do { BacktraceClient.shared = try BacktraceClient(credentials: credentials) } catch RepositoryError.persistentRepositoryInitError(let details) { print("Database initialization failed: \(details)") // Fallback: disable offline storage } ``` -------------------------------- ### Set Logging Destinations Source: https://github.com/backtrace-labs/backtrace-cocoa/blob/master/_autodocs/api-reference/BacktraceClient.md Set new logging destinations for the Backtrace client. This example configures the client to use a BacktraceFancyConsoleDestination for debug level logs. ```swift BacktraceClient.shared?.loggingDestinations = [ BacktraceFancyConsoleDestination(level: .debug) ] ``` -------------------------------- ### Configure Backtrace Client for Production Source: https://github.com/backtrace-labs/backtrace-cocoa/blob/master/_autodocs/configuration.md Sets up the Backtrace client with standard limits, disallows debugger attachment, and configures database, metrics, and OOM tracking for production. ```swift let config = BacktraceClientConfiguration( credentials: credentials, reportsPerMin: 30, // Standard limit allowsAttachingDebugger: false // Skip debugger ) let dbSettings = BacktraceDatabaseSettings() dbSettings.maxRecordCount = 100 dbSettings.maxDatabaseSize = 50 dbSettings.retryBehaviour = .interval dbSettings.retryInterval = 30 // Longer wait let metricsSettings = BacktraceMetricsSettings() metricsSettings.timeInterval = 1800 // 30 minutes metricsSettings.maxEventsCount = 350 config.dbSettings = dbSettings config.metricsSettings = metricsSettings config.oomMode = .full // Full OOM tracking BacktraceClient.shared = try BacktraceClient(configuration: config) BacktraceClient.shared?.metrics.enable(settings: metricsSettings) ``` -------------------------------- ### BacktraceCredentials Initializers Source: https://github.com/backtrace-labs/backtrace-cocoa/blob/master/_autodocs/SUMMARY.txt Shows how to create BacktraceCredentials instances, essential for authenticating with the Backtrace service. ```swift // Example of one of the 2 initializers let credentials = BacktraceCredentials(token: "YOUR_TOKEN") ``` -------------------------------- ### Initialize BacktraceClient Source: https://github.com/backtrace-labs/backtrace-cocoa/blob/master/_autodocs/OVERVIEW.md Initialize the shared BacktraceClient instance with credentials. This should be done in your application's delegate. ```swift BacktraceClient.shared = try BacktraceClient(credentials: credentials) ``` -------------------------------- ### BacktraceClientConfiguration with Database Settings Source: https://github.com/backtrace-labs/backtrace-cocoa/blob/master/_autodocs/api-reference/BacktraceDatabaseSettings.md Integrate BacktraceDatabaseSettings into BacktraceClientConfiguration to initialize the Backtrace client. ```swift let credentials = BacktraceCredentials( endpoint: URL(string: "https://my-universe.backtrace.io")!, token: "token" ) let dbSettings = BacktraceDatabaseSettings() dbSettings.maxRecordCount = 100 dbSettings.maxDatabaseSize = 50 dbSettings.retryBehaviour = .interval dbSettings.retryInterval = 10 dbSettings.retryLimit = 5 let config = BacktraceClientConfiguration( credentials: credentials, dbSettings: dbSettings, reportsPerMin: 30 ) BacktraceClient.shared = try BacktraceClient(configuration: config) ``` -------------------------------- ### Configure BacktraceClient using Endpoint and Token Source: https://github.com/backtrace-labs/backtrace-cocoa/blob/master/_autodocs/api-reference/BacktraceCredentials.md This snippet shows the recommended way to configure the Backtrace client by initializing BacktraceCredentials with a separate endpoint URL and token. ```swift let credentials = BacktraceCredentials( endpoint: URL(string: "https://my-universe.backtrace.io")!, token: "eJydUMtOwzAM_BXL" ) let config = BacktraceClientConfiguration(credentials: credentials) ``` -------------------------------- ### Initialize BacktraceClient with Credentials Source: https://github.com/backtrace-labs/backtrace-cocoa/blob/master/_autodocs/api-reference/BacktraceClient.md Initialize the shared BacktraceClient instance using BacktraceCredentials. This is typically done during app startup. Ensure the endpoint and token are correctly configured. ```swift let credentials = BacktraceCredentials( endpoint: URL(string: "https://my-universe.backtrace.io")!, token: "my-token" ) BacktraceClient.shared = try BacktraceClient(credentials: credentials) ``` -------------------------------- ### Get Breadcrumb Log Path Source: https://github.com/backtrace-labs/backtrace-cocoa/blob/master/_autodocs/api-reference/BacktraceBreadcrumbSettings.md Retrieves the file system URL where breadcrumbs are stored. This method uses the app's Documents directory and may throw an error if the directory is inaccessible. ```swift @objc public func getBreadcrumbLogPath() throws -> URL ``` ```swift let settings = BacktraceBreadcrumbSettings() do { let logPath = try settings.getBreadcrumbLogPath() print("Breadcrumbs stored at: \(logPath)") } catch { print("Could not get breadcrumb path: \(error)") } ``` -------------------------------- ### Set Static and Dynamic Attributes Source: https://github.com/backtrace-labs/backtrace-cocoa/blob/master/_autodocs/configuration.md Demonstrates how to set static attributes on the Backtrace client and how to dynamically update attributes at runtime. ```swift // Set static attributes BacktraceClient.shared?.attributes = [ "app_version": Bundle.main.releaseVersionNumber, "user_id": userId, "environment": "production" ] // Update attributes dynamically if let client = BacktraceClient.shared { var attrs = client.attributes attrs["session_id"] = UUID().uuidString client.attributes = attrs } ``` -------------------------------- ### Set Custom Data for Crash Reports Source: https://github.com/backtrace-labs/backtrace-cocoa/blob/master/_autodocs/api-reference/BacktraceCrashReporter.md Sets custom serialized data to be included in crash reports. This data is automatically added to crash attributes. Ensure the data is properly serialized, for example, as JSON. ```swift func setCustomData(data: Data) ``` ```swift let customData = """ { "app_state": "in_payment", "network_status": "wifi" } """.data(using: .utf8)! crashReporter.setCustomData(data: customData) ``` -------------------------------- ### Production Balanced Configuration Source: https://github.com/backtrace-labs/backtrace-cocoa/blob/master/_autodocs/api-reference/BacktraceBreadcrumbSettings.md A balanced configuration for production environments, using default file size, tracking important events, and logging warnings and above. ```swift let settings = BacktraceBreadcrumbSettings( maxIndividualBreadcrumbSizeBytes: 4096, // 4 KB per breadcrumb maxQueueFileSizeBytes: 64 * 1024, // 64 KB total (default) breadcrumbTypes: [.user, .navigation, .http, .error, .system], // Important events breadcrumbLevel: .info // Info level and above ) BacktraceClient.shared?.enableBreadcrumbs(settings) ``` -------------------------------- ### Reinitialize Backtrace Client with New Configuration Source: https://github.com/backtrace-labs/backtrace-cocoa/blob/master/_autodocs/configuration.md Demonstrates how to reconfigure an existing Backtrace client by first setting shared instance to nil and then reinitializing with new configuration parameters. ```swift // Old configuration BacktraceClient.shared = nil // New configuration let newConfig = BacktraceClientConfiguration( credentials: newCredentials, reportsPerMin: 50 ) BacktraceClient.shared = try BacktraceClient(configuration: newConfig) ``` -------------------------------- ### Enable Breadcrumbs with Default Settings Source: https://github.com/backtrace-labs/backtrace-cocoa/blob/master/_autodocs/api-reference/BacktraceBreadcrumbs.md Enables breadcrumb collection using default configurations for file size, breadcrumb types, and minimum severity level. This is a convenient way to start logging breadcrumbs without explicit configuration. ```swift BacktraceClient.shared?.enableBreadcrumbs() ``` -------------------------------- ### BacktraceCredentials Configuration Patterns Source: https://github.com/backtrace-labs/backtrace-cocoa/blob/master/_autodocs/api-reference/BacktraceCredentials.md Demonstrates different patterns for configuring Backtrace credentials, including recommended methods and loading from configuration files. ```APIDOC ## Configuration Patterns ### Using Endpoint + Token (Recommended) ```swift let credentials = BacktraceCredentials( endpoint: URL(string: "https://my-universe.backtrace.io")!, token: "eJydUMtOwzAM_BXL" ) let config = BacktraceClientConfiguration(credentials: credentials) ``` Advantages: - Explicit and clear separation of endpoint and token - Easier to manage credentials from environment variables - Standard approach for most integrations ### Using Submission URL ```swift let credentials = BacktraceCredentials( submissionUrl: URL(string: "https://submit.backtrace.io/my-universe/eJydUMtOwzAM_BXL")! ) let config = BacktraceClientConfiguration(credentials: credentials) ``` Advantages: - Single URL encapsulates all authentication information - Useful when credentials are provided as a single string - Compatible with various deployment configurations ### Loading from Configuration ```swift // Example: Load from Info.plist guard let endpoint = Bundle.main.infoDictionary?["BACKTRACE_ENDPOINT"] as? String, let token = Bundle.main.infoDictionary?["BACKTRACE_TOKEN"] as? String else { fatalError("Backtrace credentials not configured in Info.plist") } let credentials = BacktraceCredentials( endpoint: URL(string: endpoint)!, token: token ) ``` ``` -------------------------------- ### BacktraceClientConfiguration Initializers Source: https://github.com/backtrace-labs/backtrace-cocoa/blob/master/_autodocs/SUMMARY.txt Details the various ways to initialize the BacktraceClientConfiguration, supporting different use cases like development and production. ```APIDOC ## BacktraceClientConfiguration Initializers ### Description Initializes the Backtrace client configuration. Supports various patterns for different environments (dev, prod, low-memory) and runtime configuration. ### Method - `BacktraceClientConfiguration()` (4 initializers) ### Parameters Documentation for parameters of each initializer is available in the detailed API reference. ### Return Values Details on return values are available in the detailed API reference. ### Error Conditions Details on error conditions are available in the detailed API reference. ``` -------------------------------- ### BacktraceClientConfiguration Constructor Source: https://github.com/backtrace-labs/backtrace-cocoa/blob/master/_autodocs/configuration.md Initializes the main configuration object for the Backtrace SDK. It accepts credentials, database settings, report limits, debugger attachment allowance, and OOM detection mode. ```swift BacktraceClientConfiguration( credentials: BacktraceCredentials, dbSettings: BacktraceDatabaseSettings = BacktraceDatabaseSettings(), reportsPerMin: Int = 30, allowsAttachingDebugger: Bool = false, oomMode: BacktraceOomMode = .none ) ``` -------------------------------- ### Initialize BacktraceCredentials with Endpoint and Token Source: https://github.com/backtrace-labs/backtrace-cocoa/blob/master/_autodocs/api-reference/BacktraceCredentials.md Use this initializer when you have the Backtrace endpoint URL and submission token separately. This is the recommended approach for clarity and manageability. ```swift let endpoint = URL(string: "https://my-universe.backtrace.io")! let credentials = BacktraceCredentials(endpoint: endpoint, token: "submit-token-abc123") let config = BacktraceClientConfiguration(credentials: credentials) ``` -------------------------------- ### Configure Backtrace Client for Low-Power/Limited Storage Source: https://github.com/backtrace-labs/backtrace-cocoa/blob/master/_autodocs/configuration.md Configures the Backtrace client with conservative rates, minimal storage, and no retries to conserve resources. ```swift let config = BacktraceClientConfiguration( credentials: credentials, reportsPerMin: 10, // Conservative rate oomMode: .none // Disable OOM for performance ) let dbSettings = BacktraceDatabaseSettings() dbSettings.maxRecordCount = 20 // Few reports dbSettings.maxDatabaseSize = 10 // 10 MB max dbSettings.retryBehaviour = .none // No retries dbSettings.retryLimit = 1 config.dbSettings = dbSettings let metricsSettings = BacktraceMetricsSettings() metricsSettings.timeInterval = 3600 // 1 hour intervals metricsSettings.maxEventsCount = 200 config.metricsSettings = metricsSettings BacktraceClient.shared = try BacktraceClient(configuration: config) ``` -------------------------------- ### Initialize Backtrace Metrics with Custom Settings Source: https://github.com/backtrace-labs/backtrace-cocoa/blob/master/_autodocs/api-reference/BacktraceMetrics.md Configure metrics collection intervals, event limits, and retry behavior before enabling the metrics client. This is useful for fine-tuning when and how often metrics are sent. ```swift let metricsSettings = BacktraceMetricsSettings() metricsSettings.timeInterval = 1800 // Send every 30 minutes metricsSettings.maxEventsCount = 350 // Send when 350 events collected metricsSettings.retryInterval = 10 // Retry failed submissions after 10s metricsSettings.retryLimit = 3 // Retry up to 3 times BacktraceClient.shared?.metrics.enable(settings: metricsSettings) ```