diff --git a/examples/android/HelloWorldApp.kt b/examples/android/HelloWorldApp.kt index 35bf41c..b93904a 100644 --- a/examples/android/HelloWorldApp.kt +++ b/examples/android/HelloWorldApp.kt @@ -31,7 +31,7 @@ class HelloWorldApp : Application() { val userID = UUID.randomUUID().toString(); - Logger.configure( + Logger.start( apiKey = bitdriftAPIKey, apiUrl = BITDRIFT_URL, sessionStrategy = SessionStrategy.Fixed { UUID.randomUUID().toString() }, diff --git a/examples/objective-c/CAPViewController.m b/examples/objective-c/CAPViewController.m index 98b03f5..f0d3e61 100644 --- a/examples/objective-c/CAPViewController.m +++ b/examples/objective-c/CAPViewController.m @@ -80,7 +80,7 @@ - (void)setSelectedLogLevel:(LogLevel)selectedLogLevel { - (void)setUpLogger { [CAPLogger - configureWithAPIKey:kCaptureAPIKey + startWithAPIKey:kCaptureAPIKey sessionStrategy:[CAPSessionStrategy fixed] apiURL:[NSURL URLWithString:kCaptureURLString] ]; diff --git a/examples/swift/hello_world/LoggerCustomer.swift b/examples/swift/hello_world/LoggerCustomer.swift index 16ed099..f165332 100644 --- a/examples/swift/hello_world/LoggerCustomer.swift +++ b/examples/swift/hello_world/LoggerCustomer.swift @@ -84,7 +84,7 @@ final class LoggerCustomer: NSObject, URLSessionDelegate { self.appStartTime = Date() Logger - .configure( + .start( withAPIKey: kBitdriftAPIKey, sessionStrategy: .fixed(), configuration: .init(), diff --git a/platform/jvm/capture/src/main/kotlin/io/bitdrift/capture/Capture.kt b/platform/jvm/capture/src/main/kotlin/io/bitdrift/capture/Capture.kt index f037e2a..17b98ab 100644 --- a/platform/jvm/capture/src/main/kotlin/io/bitdrift/capture/Capture.kt +++ b/platform/jvm/capture/src/main/kotlin/io/bitdrift/capture/Capture.kt @@ -24,43 +24,43 @@ import kotlin.time.Duration internal sealed class LoggerState { /** - * The logger has not yet been configured. + * The logger has not yet been started. */ - data object NotConfigured : LoggerState() + data object NotStarted : LoggerState() /** - * The logger has been successfully configured and is ready for use. Subsequent attempts to configure the logger will be ignored. + * The logger is in the process of being started. Subsequent attempts to start the logger will be ignored. */ - class Configured(val logger: LoggerImpl) : LoggerState() + data object Starting : LoggerState() /** - * The configuration has started but is not yet complete. Subsequent attempts to configure the logger will be ignored. + * The logger has been successfully started and is ready for use. Subsequent attempts to start the logger will be ignored. */ - data object ConfigurationStarted : LoggerState() + class Started(val logger: LoggerImpl) : LoggerState() /** - * The configuration was attempted but failed. Subsequent attempts to configure the logger will be ignored. + * An attempt to start the logger was made but failed. Subsequent attempts to start the logger will be ignored. */ - data object ConfigurationFailure : LoggerState() + data object StartFailure : LoggerState() } /** * Top level namespace Capture SDK. */ object Capture { - private val default: AtomicReference = AtomicReference(LoggerState.NotConfigured) + private val default: AtomicReference = AtomicReference(LoggerState.NotStarted) /** - * Returns a handle to the underlying logger instance, if Capture has been configured. + * Returns a handle to the underlying logger instance, if Capture has been started. * * @return ILogger a logger handle */ fun logger(): ILogger? { return when (val state = default.get()) { - is LoggerState.NotConfigured -> null - is LoggerState.Configured -> state.logger - is LoggerState.ConfigurationStarted -> null - is LoggerState.ConfigurationFailure -> null + is LoggerState.NotStarted -> null + is LoggerState.Starting -> null + is LoggerState.Started -> state.logger + is LoggerState.StartFailure -> null } } @@ -69,7 +69,7 @@ object Capture { * * ## Logger Initialization * - * To initialize the logger, first call Logger.configure() with the desired configuration. Once this + * To initialize the logger, first call Logger.start() with the desired configuration. Once this * call completes, logging can be done either via the top level logging functions or via a logger * handle acquired via Capture.logger(). * @@ -88,7 +88,9 @@ object Capture { private val mainThreadHandler by lazy { MainThreadHandler() } /** - * Configures the static logger. + * Initializes the Capture SDK with the specified API key, providers, and configuration. + * Calling other SDK methods has no effect unless the logger has been initialized. + * Subsequent calls to this function will have no effect. * * @param apiKey The API key provided by bitdrift. This is required. * @param sessionStrategy session strategy for the management of session id. @@ -102,7 +104,7 @@ object Capture { @Synchronized @JvmStatic @JvmOverloads - fun configure( + fun start( apiKey: String, sessionStrategy: SessionStrategy, configuration: Configuration = Configuration(), @@ -110,7 +112,7 @@ object Capture { dateProvider: DateProvider? = null, apiUrl: HttpUrl = defaultCaptureApiUrl, ) { - configure( + start( apiKey, sessionStrategy, configuration, @@ -124,7 +126,7 @@ object Capture { @Synchronized @JvmStatic @JvmOverloads - internal fun configure( + internal fun start( apiKey: String, sessionStrategy: SessionStrategy, configuration: Configuration = Configuration(), @@ -147,7 +149,7 @@ object Capture { } // Ideally we would use `getAndUpdate` in here but it's available for API 24 and up only. - if (default.compareAndSet(LoggerState.NotConfigured, LoggerState.ConfigurationStarted)) { + if (default.compareAndSet(LoggerState.NotStarted, LoggerState.Starting)) { try { val logger = LoggerImpl( apiKey = apiKey, @@ -158,19 +160,19 @@ object Capture { sessionStrategy = sessionStrategy, bridge = bridge, ) - default.set(LoggerState.Configured(logger)) + default.set(LoggerState.Started(logger)) } catch (e: Throwable) { - Log.w("capture", "Capture initialization failed", e) - default.set(LoggerState.ConfigurationFailure) + Log.w("capture", "Failed to start Capture", e) + default.set(LoggerState.StartFailure) } } else { - Log.w("capture", "Attempted to initialize Capture more than once") + Log.w("capture", "Multiple attempts to start Capture") } } /** * The Id for the current ongoing session. - * It's equal to `null` prior to the configuration of Capture SDK. + * It's equal to `null` prior to the start of Capture SDK. */ @JvmStatic val sessionId: String? @@ -178,7 +180,7 @@ object Capture { /** * The URL for the current ongoing session. - * It's equal to `null` prior to the configuration of Capture SDK. + * It's equal to `null` prior to the start of Capture SDK. */ @JvmStatic val sessionUrl: String? @@ -189,15 +191,15 @@ object Capture { * is not reinstalled. * * The value of this property is different for apps from the same vendor running on - * the same device. It is equal to null prior to the configuration of bitdrift Capture SDK. + * the same device. It is equal to null prior to the start of bitdrift Capture SDK. */ @JvmStatic val deviceId: String? get() = logger()?.deviceId /** - * Defines the initialization of a new session within the current configured logger - * If no logger is configured, this is a no-op. + * Defines the initialization of a new session within the currently running logger + * If no logger is started, this is a no-op. */ @JvmStatic fun startNewSession() { @@ -219,7 +221,7 @@ object Capture { mainThreadHandler.run { completion(it) } } } ?: run { - mainThreadHandler.run { completion(Err(SdkNotConfiguredError)) } + mainThreadHandler.run { completion(Err(SdkNotStartedError)) } } } @@ -334,7 +336,7 @@ object Capture { } /** - * Writes an app launch TTI log event. This event should be logged only once per Logger configuration. + * Writes an app launch TTI log event. This event should be logged only once per Logger start. * Consecutive calls have no effect. * * @param duration The time between a user's intent to launch the app and when the app becomes @@ -351,7 +353,7 @@ object Capture { * @param name the name of the operation. * @param level the severity of the log. * @fields additional fields to include in the log. - * @return a [Span] object that can be used to signal the end of the operation if Capture has been configured. + * @return a [Span] object that can be used to signal the end of the operation if Capture has been started. */ @JvmStatic fun startSpan(name: String, level: LogLevel, fields: Map? = null): Span? { @@ -405,7 +407,7 @@ object Capture { * Used for testing purposes. */ internal fun resetShared() { - default.set(LoggerState.NotConfigured) + default.set(LoggerState.NotStarted) } } } diff --git a/platform/jvm/capture/src/main/kotlin/io/bitdrift/capture/CaptureJniLibrary.kt b/platform/jvm/capture/src/main/kotlin/io/bitdrift/capture/CaptureJniLibrary.kt index 2f363e6..d5331de 100644 --- a/platform/jvm/capture/src/main/kotlin/io/bitdrift/capture/CaptureJniLibrary.kt +++ b/platform/jvm/capture/src/main/kotlin/io/bitdrift/capture/CaptureJniLibrary.kt @@ -187,13 +187,13 @@ internal object CaptureJniLibrary : IBridge { ) /** - * Writes an SDK configured log. + * Writes an SDK started log. * * @param loggerId the ID of the logger to write to. * @param fields the fields to include with the log. * @param durationMs the duration of time the SDK configuration took. */ - external fun writeSDKConfiguredLog( + external fun writeSDKStartLog( loggerId: Long, fields: Map, duration: Double, diff --git a/platform/jvm/capture/src/main/kotlin/io/bitdrift/capture/LoggerImpl.kt b/platform/jvm/capture/src/main/kotlin/io/bitdrift/capture/LoggerImpl.kt index 4a85687..f3cf0cc 100644 --- a/platform/jvm/capture/src/main/kotlin/io/bitdrift/capture/LoggerImpl.kt +++ b/platform/jvm/capture/src/main/kotlin/io/bitdrift/capture/LoggerImpl.kt @@ -239,7 +239,7 @@ internal class LoggerImpl( this.replayScreenLogger?.start() } - CaptureJniLibrary.writeSDKConfiguredLog( + CaptureJniLibrary.writeSDKStartLog( this.loggerId, mapOf(), duration.toDouble(DurationUnit.SECONDS), @@ -274,7 +274,7 @@ internal class LoggerImpl( * `SharedPreferences`. */ deviceCodeService.createTemporaryDeviceCode(deviceId, completion) - } ?: completion(Err(SdkNotConfiguredError)) + } ?: completion(Err(SdkNotStartedError)) } private fun appExitSaveCurrentSessionId(sessionId: String? = null) { diff --git a/platform/jvm/capture/src/main/kotlin/io/bitdrift/capture/Models.kt b/platform/jvm/capture/src/main/kotlin/io/bitdrift/capture/Models.kt index 04ae892..cfa6d58 100644 --- a/platform/jvm/capture/src/main/kotlin/io/bitdrift/capture/Models.kt +++ b/platform/jvm/capture/src/main/kotlin/io/bitdrift/capture/Models.kt @@ -45,6 +45,6 @@ sealed class ApiError(override val message: String) : Error(message) { } /** - * Represents a failed operation due to the SDK not being configured. + * Represents a failed operation due to the SDK not being started */ -data object SdkNotConfiguredError : Error("SDK not configured") +data object SdkNotStartedError : Error("SDK not started") diff --git a/platform/jvm/capture/src/test/kotlin/io/bitdrift/capture/CaptureTest.kt b/platform/jvm/capture/src/test/kotlin/io/bitdrift/capture/CaptureTest.kt index 0b7f141..c76114d 100644 --- a/platform/jvm/capture/src/test/kotlin/io/bitdrift/capture/CaptureTest.kt +++ b/platform/jvm/capture/src/test/kotlin/io/bitdrift/capture/CaptureTest.kt @@ -32,7 +32,7 @@ class CaptureTest { fun aConfigureSkipsLoggerCreationWhenContextNotInitialized() { assertThat(Capture.logger()).isNull() - Logger.configure( + Logger.start( apiKey = "test1", sessionStrategy = SessionStrategy.Fixed(), dateProvider = null, @@ -70,7 +70,7 @@ class CaptureTest { assertThat(Capture.logger()).isNull() - Logger.configure( + Logger.start( apiKey = "test1", sessionStrategy = SessionStrategy.Fixed(), dateProvider = null, @@ -80,7 +80,7 @@ class CaptureTest { assertThat(logger).isNotNull() assertThat(Logger.deviceId).isNotNull() - Logger.configure( + Logger.start( apiKey = "test2", sessionStrategy = SessionStrategy.Fixed(), dateProvider = null, diff --git a/platform/jvm/capture/src/test/kotlin/io/bitdrift/capture/ConfigurationTest.kt b/platform/jvm/capture/src/test/kotlin/io/bitdrift/capture/ConfigurationTest.kt index a95d14d..ad0cb36 100644 --- a/platform/jvm/capture/src/test/kotlin/io/bitdrift/capture/ConfigurationTest.kt +++ b/platform/jvm/capture/src/test/kotlin/io/bitdrift/capture/ConfigurationTest.kt @@ -49,7 +49,7 @@ class ConfigurationTest { // We start without configured logger. Assertions.assertThat(Capture.logger()).isNull() - Capture.Logger.configure( + Capture.Logger.start( apiKey = "test1", sessionStrategy = SessionStrategy.Fixed(), dateProvider = null, @@ -76,7 +76,7 @@ class ConfigurationTest { // We perform another attempt to configure the logger to verify that // consecutive configure calls are no-ops. - Capture.Logger.configure( + Capture.Logger.start( apiKey = "test1", sessionStrategy = SessionStrategy.Fixed(), dateProvider = null, diff --git a/platform/jvm/gradle-test-app/src/main/java/io/bitdrift/gradletestapp/BitdriftInit.java b/platform/jvm/gradle-test-app/src/main/java/io/bitdrift/gradletestapp/BitdriftInit.java index 52bb0c8..a080efa 100644 --- a/platform/jvm/gradle-test-app/src/main/java/io/bitdrift/gradletestapp/BitdriftInit.java +++ b/platform/jvm/gradle-test-app/src/main/java/io/bitdrift/gradletestapp/BitdriftInit.java @@ -29,13 +29,13 @@ public static void initBitdriftCaptureInJava() { return fields; }); - Capture.Logger.configure( - "", - new SessionStrategy.Fixed(), - new Configuration(), - fieldProviders, - null, - HttpUrl.get("https://api.bitdrift.io") + Capture.Logger.start( + "", + new SessionStrategy.Fixed(), + new Configuration(), + fieldProviders, + null, + HttpUrl.get("https://api.bitdrift.io") ); } } diff --git a/platform/jvm/jni_symbols.lds b/platform/jvm/jni_symbols.lds index 8c51ce4..212d304 100644 --- a/platform/jvm/jni_symbols.lds +++ b/platform/jvm/jni_symbols.lds @@ -12,7 +12,7 @@ Java_io_bitdrift_capture_CaptureJniLibrary_removeLogField Java_io_bitdrift_capture_CaptureJniLibrary_writeLog Java_io_bitdrift_capture_CaptureJniLibrary_writeSessionReplayLog Java_io_bitdrift_capture_CaptureJniLibrary_writeResourceUtilizationLog -Java_io_bitdrift_capture_CaptureJniLibrary_writeSDKConfiguredLog +Java_io_bitdrift_capture_CaptureJniLibrary_writeSDKStartLog Java_io_bitdrift_capture_CaptureJniLibrary_shouldWriteAppUpdateLog Java_io_bitdrift_capture_CaptureJniLibrary_writeAppUpdateLog Java_io_bitdrift_capture_CaptureJniLibrary_writeAppLaunchTTILog diff --git a/platform/jvm/microbenchmark/src/androidTest/java/io/bitdrift/microbenchmark/ClockTimeProfiler.kt b/platform/jvm/microbenchmark/src/androidTest/java/io/bitdrift/microbenchmark/ClockTimeProfiler.kt index 375693b..894e844 100644 --- a/platform/jvm/microbenchmark/src/androidTest/java/io/bitdrift/microbenchmark/ClockTimeProfiler.kt +++ b/platform/jvm/microbenchmark/src/androidTest/java/io/bitdrift/microbenchmark/ClockTimeProfiler.kt @@ -34,7 +34,7 @@ class ClockTimeProfiler { @Before fun setUp() { - Capture.Logger.configure( + Capture.Logger.start( apiKey = "android-benchmark-test", apiUrl = "https://api-tests.bitdrift.io".toHttpUrl(), sessionStrategy = SessionStrategy.Fixed(), diff --git a/platform/jvm/src/jni.rs b/platform/jvm/src/jni.rs index b8c0e18..c54170c 100644 --- a/platform/jvm/src/jni.rs +++ b/platform/jvm/src/jni.rs @@ -911,7 +911,7 @@ pub extern "system" fn Java_io_bitdrift_capture_CaptureJniLibrary_writeResourceU } #[no_mangle] -pub extern "system" fn Java_io_bitdrift_capture_CaptureJniLibrary_writeSDKConfiguredLog( +pub extern "system" fn Java_io_bitdrift_capture_CaptureJniLibrary_writeSDKStartLog( mut env: JNIEnv<'_>, _class: JClass<'_>, logger_id: jlong, diff --git a/platform/swift/source/Capture.swift b/platform/swift/source/Capture.swift index 6ffaeea..5821932 100644 --- a/platform/swift/source/Capture.swift +++ b/platform/swift/source/Capture.swift @@ -15,20 +15,20 @@ public typealias Fields = [String: FieldValue] public typealias FieldValue = Encodable & Sendable extension Logger { - struct SDKNotConfiguredError: Swift.Error {} + struct SDKNotStartedfError: Swift.Error {} // MARK: - General - /// An instance of the underlying logger, if the Capture SDK is configured. Returns `nil` if the - /// `configure(...)` method has not been called or if Logger configuration failed due to an internal + /// An instance of the underlying logger, if the Capture SDK is started. Returns `nil` if the + /// `start(...)` method has not been called or if starting the logger process failed due to an internal /// error. public static var shared: Logging? { self.getShared(assert: false) } - /// Configures Capture with the given API key, providers, and configuration. - /// This call is required at least once before invoking any log functions. - /// Subsequent calls to this function do nothing. + /// Initializes the Capture SDK with the specified API key, providers, and configuration. + /// Calling other SDK methods has no effect unless the logger has been initialized. + /// Subsequent calls to this function will have no effect. /// /// - parameter apiKey: The API key provided by bitdrift. /// - parameter sessionStrategy: A session strategy for the management of session ID. @@ -43,7 +43,7 @@ extension Logger { /// /// - returns: A logger integrator that can be used to enable various SDK integration. @discardableResult - public static func configure( + public static func start( withAPIKey apiKey: String, sessionStrategy: SessionStrategy, configuration: Configuration = .init(), @@ -53,7 +53,7 @@ extension Logger { apiURL: URL = URL(string: "https://api.bitdrift.io")! ) -> LoggerIntegrator? { - return self.configure( + return self.start( withAPIKey: apiKey, sessionStrategy: sessionStrategy, configuration: configuration, @@ -65,7 +65,7 @@ extension Logger { } @discardableResult - static func configure( + static func start( withAPIKey apiKey: String, sessionStrategy: SessionStrategy, configuration: Configuration, @@ -88,18 +88,18 @@ extension Logger { } } - /// Retrieves the session ID. It is nil before the Capture SDK is configured. + /// Retrieves the session ID. It is nil before the Capture SDK is started. public static var sessionID: String? { return Self.getShared()?.sessionID } - /// Retrieves the session URL. It is `nil` before the Capture SDK is configured. + /// Retrieves the session URL. It is `nil` before the Capture SDK is started. public static var sessionURL: String? { return Self.getShared()?.sessionURL } /// Initializes a new session within the currently configured logger. - /// If no logger is configured, this operation has no effect. + /// The logger must be started before this operation for it to take effect. public static func startNewSession() { Self.getShared()?.startNewSession() } @@ -108,7 +108,7 @@ extension Logger { /// is not reinstalled. /// /// The value of this property is different for apps from the same vendor running on - /// the same device. It is equal to `nil` prior to the configuration of bitdrift Capture SDK. + /// the same device. It is equal to `nil` prior to the start of bitdrift Capture SDK. public static var deviceID: String? { return Self.getShared(assert: false)?.deviceID } @@ -286,7 +286,7 @@ extension Logger { // MARK: - Predefined Logs - /// Writes an app launch TTI log event. This event should be logged only once per Logger configuration. + /// Writes an app launch TTI log event. This event should be logged only once per Logger start. /// Consecutive calls have no effect. /// /// - parameter duration: The time between a user's intent to launch the app and when the app becomes @@ -342,7 +342,7 @@ extension Logger { /// - parameter fields: The extra fields to send as part of start and end logs for the operation. /// /// - returns: A span that can be used to signal the end of the operation if the Capture SDK has been - /// configured. Returns `nil` only if the `configure(...)` method has not been called. + /// started. Returns `nil` if the `start(...)` method has not been called. public static func startSpan( name: String, level: LogLevel, @@ -394,7 +394,7 @@ extension Logger { } } else { DispatchQueue.main.async { - completion(.failure(SDKNotConfiguredError())) + completion(.failure(SDKNotStartedfError())) } } } diff --git a/platform/swift/source/CaptureRustBridge.h b/platform/swift/source/CaptureRustBridge.h index 4af16cb..12175a6 100644 --- a/platform/swift/source/CaptureRustBridge.h +++ b/platform/swift/source/CaptureRustBridge.h @@ -105,13 +105,13 @@ void capture_write_resource_utilization_log( ); /* - * Writes an SDK configured log. + * Writes an SDK started log. * * @param logger_id the ID of the logger to write to. * @param fields the fields to include with the log. * @param duration_s the duration of time the SDK configuration took. */ -void capture_write_sdk_configured_log( +void capture_write_sdk_start_log( logger_id logger_id, const NSArray *fields, double duration_s @@ -153,7 +153,7 @@ void capture_write_app_update_log( * * @param loggerId the ID of the logger to write to. * @param duration_s the duration of time between a user's intent to launch an app and the point in time - * when the app became interactive. + * when the app became interactive. Calls with a negative duration are ignored. */ void capture_write_app_launch_tti_log( logger_id logger_id, diff --git a/platform/swift/source/CoreLogger.swift b/platform/swift/source/CoreLogger.swift index e88d631..e26118a 100644 --- a/platform/swift/source/CoreLogger.swift +++ b/platform/swift/source/CoreLogger.swift @@ -94,8 +94,8 @@ extension CoreLogger: CoreLogging { ) } - func logSDKConfigured(fields: Fields, duration: TimeInterval) { - self.underlyingLogger.logSDKConfigured( + func logSDKStart(fields: Fields, duration: TimeInterval) { + self.underlyingLogger.logSDKStart( fields: self.convertFields(fields: fields), duration: duration ) diff --git a/platform/swift/source/CoreLogging.swift b/platform/swift/source/CoreLogging.swift index 9319762..f96797f 100644 --- a/platform/swift/source/CoreLogging.swift +++ b/platform/swift/source/CoreLogging.swift @@ -63,7 +63,7 @@ protocol CoreLogging: AnyObject { /// /// - parameter fields: The extra fields to include with the log. /// - parameter duration: The duration of time the SDK configuration took. - func logSDKConfigured(fields: Fields, duration: TimeInterval) + func logSDKStart(fields: Fields, duration: TimeInterval) /// Checks whether the app update log should be emitted. /// diff --git a/platform/swift/source/Logger.swift b/platform/swift/source/Logger.swift index 3e0c5f1..a60d5b6 100644 --- a/platform/swift/source/Logger.swift +++ b/platform/swift/source/Logger.swift @@ -12,14 +12,14 @@ import Foundation // swiftlint:disable file_length public final class Logger { enum State { - // The logger has not yet been configured. - case notConfigured - // The logger has been successfully configured and is ready for use. - // Subsequent attempts to configure the logger will be ignored. - case configured(LoggerIntegrator) - // The configuration was attempted but failed. - // Subsequent attempts to configure the logger will be ignored. - case configurationFailure + // The logger has not yet been started. + case notStarted + // The logger has been successfully started and is ready for use. + // Subsequent attempts to start the logger will be ignored. + case started(LoggerIntegrator) + // An attempt to start the logger was made but failed. + // Subsequent attempts to start the logger will be ignored. + case startFailure } private let underlyingLogger: CoreLogging @@ -35,7 +35,7 @@ public final class Logger { private let sessionURLBase: URL - private static let syncedShared = Atomic(.notConfigured) + private static let syncedShared = Atomic(.notStarted) private let network: URLSessionNetworkClient? // Used for benchmarking purposes. @@ -189,7 +189,7 @@ public final class Logger { defer { let duration = timeProvider.timeIntervalSince(start) - self.underlyingLogger.logSDKConfigured(fields: [:], duration: duration) + self.underlyingLogger.logSDKStart(fields: [:], duration: duration) } self.eventsListenerTarget.setUp( @@ -222,6 +222,8 @@ public final class Logger { self.deviceCodeController = DeviceCodeController(client: client) } + // swiftlint:enable function_body_length + /// Enables blocking shutdown operation. In practice, it makes the receiver's deinit wait for the complete /// shutdown of the underlying logger. /// @@ -230,8 +232,6 @@ public final class Logger { self.underlyingLogger.enableBlockingShutdown() } - // swiftlint:enable function_body_length - deinit { self.stop() } @@ -263,47 +263,47 @@ public final class Logger { static func createOnce(_ createLogger: () -> Logger?) -> LoggerIntegrator? { let state = self.syncedShared.update { state in - guard case .notConfigured = state else { + guard case .notStarted = state else { return } if let createdLogger = createLogger() { - state = .configured(LoggerIntegrator(logger: createdLogger)) + state = .started(LoggerIntegrator(logger: createdLogger)) } else { - state = .configurationFailure + state = .startFailure } } return switch state { - case .configured(let logger): + case .started(let logger): logger - case .notConfigured, .configurationFailure: + case .notStarted, .startFailure: nil } } - /// Retrieves a shared instance of logger if one has been configured. + /// Retrieves a shared instance of logger if one has been started. /// - /// - parameter assert: Whether the method should assert if shared logger has not been configured. + /// - parameter assert: Whether the method should assert if shared logger has not been started. /// /// - returns: The shared instance of logger. static func getShared(assert: Bool = true) -> Logging? { return switch Self.syncedShared.load() { - case .notConfigured: { + case .notStarted: { if assert { assertionFailure( """ Default logger is not set up! Did you attempt to log with the default logger without \ - calling `configure(withAPIKey:)` first? + calling `start(withAPIKey:)` first? """ ) } return nil }() - case .configured(let integrator): + case .started(let integrator): integrator.logger - case .configurationFailure: + case .startFailure: nil } } @@ -314,9 +314,9 @@ public final class Logger { static func resetShared(logger: Logging? = nil) { Self.syncedShared.update { state in if let logger { - state = .configured(LoggerIntegrator(logger: logger)) + state = .started(LoggerIntegrator(logger: logger)) } else { - state = .notConfigured + state = .notStarted } } } diff --git a/platform/swift/source/LoggerBridge.swift b/platform/swift/source/LoggerBridge.swift index 820b7a7..b3dfb3d 100644 --- a/platform/swift/source/LoggerBridge.swift +++ b/platform/swift/source/LoggerBridge.swift @@ -113,8 +113,8 @@ final class LoggerBridge: LoggerBridging { capture_write_resource_utilization_log(self.loggerID, fields, duration) } - func logSDKConfigured(fields: [CapturePassable.Field], duration: TimeInterval) { - capture_write_sdk_configured_log(self.loggerID, fields, duration) + func logSDKStart(fields: [CapturePassable.Field], duration: TimeInterval) { + capture_write_sdk_start_log(self.loggerID, fields, duration) } func shouldLogAppUpdate( diff --git a/platform/swift/source/LoggerBridging.swift b/platform/swift/source/LoggerBridging.swift index 7cc2369..654a1c2 100644 --- a/platform/swift/source/LoggerBridging.swift +++ b/platform/swift/source/LoggerBridging.swift @@ -27,7 +27,7 @@ protocol LoggerBridging { func logResourceUtilization(fields: InternalFields, duration: TimeInterval) - func logSDKConfigured(fields: [CapturePassable.Field], duration: TimeInterval) + func logSDKStart(fields: [CapturePassable.Field], duration: TimeInterval) func shouldLogAppUpdate( appVersion: String, diff --git a/platform/swift/source/LoggerObjc.swift b/platform/swift/source/LoggerObjc.swift index 3d6a07d..d873d0c 100644 --- a/platform/swift/source/LoggerObjc.swift +++ b/platform/swift/source/LoggerObjc.swift @@ -16,23 +16,23 @@ public final class LoggerObjc: NSObject { fatalError("init() is not available. Use static methods instead.") } - /// Configures Capture with provided API key and session strategy. This call is required with at - /// least the API key prior to calling the log functions. Subsequent calls to this function will no-op. + /// Initializes the Capture SDK with the specified API key and session strategy. + /// Calling other SDK methods has no effect unless the logger has been initialized. + /// Subsequent calls to this function will have no effect. /// /// - parameter apiKey: The API key provided by bitdrift. - /// - parameter sessionStrategy: A session strategy for the management of session ID. - /// - parameter apiURL: The base URL of Capture API. Depend on its default value unless - /// specifically - /// instructed otherwise during discussions with bitdrift. Defaults to - /// bitdrift's hosted Compose API base URL. + /// - parameter sessionStrategy: A session strategy for the management of session IDs. + /// - parameter apiURL: The base URL of the Capture API. Rely on its default value unless + /// specifically instructed otherwise during discussions with Bitdrift. + /// Defaults to Bitdrift's hosted Compose API base URL. @objc - public static func configure( + public static func start( withAPIKey apiKey: String, sessionStrategy: SessionStrategyObjc, // swiftlint:disable:next force_unwrapping use_static_string_url_init apiURL: URL = URL(string: "https://api.bitdrift.io")! ) { - Capture.Logger.configure( + Capture.Logger.start( withAPIKey: apiKey, sessionStrategy: sessionStrategy.underlyingSessionStrategy, apiURL: apiURL diff --git a/platform/swift/source/src/bridge.rs b/platform/swift/source/src/bridge.rs index 0de5726..fe280e1 100644 --- a/platform/swift/source/src/bridge.rs +++ b/platform/swift/source/src/bridge.rs @@ -669,7 +669,7 @@ extern "C" fn capture_write_resource_utilization_log( } #[no_mangle] -extern "C" fn capture_write_sdk_configured_log( +extern "C" fn capture_write_sdk_start_log( logger_id: LoggerId<'_>, fields: *const Object, duration_s: f64, @@ -687,7 +687,7 @@ extern "C" fn capture_write_sdk_configured_log( logger_id.log_sdk_configured(fields, time::Duration::seconds_f64(duration_s)); Ok(()) }, - "swift write sdk configured log", + "swift write sdk started log", ); } diff --git a/test/platform/swift/unit_integration/ConfigurationTests.swift b/test/platform/swift/unit_integration/ConfigurationTests.swift index 3b88303..200c7ae 100644 --- a/test/platform/swift/unit_integration/ConfigurationTests.swift +++ b/test/platform/swift/unit_integration/ConfigurationTests.swift @@ -24,7 +24,7 @@ final class ConfigurationTests: XCTestCase { } func testConfigurationSimple() throws { - Logger.configure( + Logger.start( withAPIKey: "api_key", sessionStrategy: .fixed(), configuration: .init(sessionReplayConfiguration: nil) @@ -34,7 +34,7 @@ final class ConfigurationTests: XCTestCase { } func testConfigurationDefault() throws { - Logger.configure( + Logger.start( withAPIKey: "api_key", sessionStrategy: .fixed(), configuration: .init() @@ -46,7 +46,7 @@ final class ConfigurationTests: XCTestCase { func testConfigurationFailure() { let factory = MockLoggerBridgingFactory(logger: nil) - Logger.configure( + Logger.start( withAPIKey: "test", sessionStrategy: .fixed(), configuration: .init(), @@ -59,7 +59,7 @@ final class ConfigurationTests: XCTestCase { XCTAssertEqual(1, factory.makeLoggerCallsCount) XCTAssertNil(Logger.shared) - Logger.configure( + Logger.start( withAPIKey: "test", sessionStrategy: .fixed(), configuration: .init(), diff --git a/test/platform/swift/unit_integration/LoggerSharedTests.swift b/test/platform/swift/unit_integration/LoggerSharedTests.swift index 2d5e03b..8b34666 100644 --- a/test/platform/swift/unit_integration/LoggerSharedTests.swift +++ b/test/platform/swift/unit_integration/LoggerSharedTests.swift @@ -26,7 +26,7 @@ final class LoggerSharedTests: XCTestCase { } let integrator = try XCTUnwrap( - Logger.configure( + Logger.start( withAPIKey: "foo", sessionStrategy: .fixed() ) diff --git a/test/platform/swift/unit_integration/SessionURLTests.swift b/test/platform/swift/unit_integration/SessionURLTests.swift index f9e5b72..b9ca894 100644 --- a/test/platform/swift/unit_integration/SessionURLTests.swift +++ b/test/platform/swift/unit_integration/SessionURLTests.swift @@ -16,7 +16,7 @@ final class SessionURLTests: XCTestCase { } func testDefaultSessionUrl() throws { - Logger.configure( + Logger.start( withAPIKey: "api_key", sessionStrategy: .fixed(), configuration: .init() @@ -77,7 +77,7 @@ final class SessionURLTests: XCTestCase { } private func configureLogger(apiURL: String) throws { - Logger.configure( + Logger.start( withAPIKey: "api_key", sessionStrategy: .fixed(), configuration: .init(), diff --git a/test/platform/swift/unit_integration/integrations/URLSessionIntegrationTests.swift b/test/platform/swift/unit_integration/integrations/URLSessionIntegrationTests.swift index 627222d..729f9e6 100644 --- a/test/platform/swift/unit_integration/integrations/URLSessionIntegrationTests.swift +++ b/test/platform/swift/unit_integration/integrations/URLSessionIntegrationTests.swift @@ -56,7 +56,7 @@ final class URLSessionIntegrationTests: XCTestCase { self.logger = MockLogging() Logger.resetShared(logger: self.logger) Logger - .configure(withAPIKey: "123", sessionStrategy: .fixed())? + .start(withAPIKey: "123", sessionStrategy: .fixed())? .enableIntegrations([ .urlSession(), ]) diff --git a/test/platform/swift/unit_integration/mocks/MockCoreLogging.swift b/test/platform/swift/unit_integration/mocks/MockCoreLogging.swift index 7183715..3f88f2f 100644 --- a/test/platform/swift/unit_integration/mocks/MockCoreLogging.swift +++ b/test/platform/swift/unit_integration/mocks/MockCoreLogging.swift @@ -108,7 +108,7 @@ extension MockCoreLogging: CoreLogging { self.logResourceUtilizationExpectation?.fulfill() } - func logSDKConfigured(fields _: Fields, duration _: TimeInterval) {} + func logSDKStart(fields _: Fields, duration _: TimeInterval) {} func shouldLogAppUpdate(appVersion _: String, buildNumber _: String) -> Bool { return self.shouldLogAppUpdateEvent diff --git a/test/platform/swift/unit_integration/mocks/MockLoggerBridging.swift b/test/platform/swift/unit_integration/mocks/MockLoggerBridging.swift index 5fd833b..13dd4f2 100644 --- a/test/platform/swift/unit_integration/mocks/MockLoggerBridging.swift +++ b/test/platform/swift/unit_integration/mocks/MockLoggerBridging.swift @@ -79,7 +79,7 @@ extension MockLoggerBridging: LoggerBridging { func logResourceUtilization(fields _: [Field], duration _: TimeInterval) {} - func logSDKConfigured(fields _: [Field], duration _: TimeInterval) {} + func logSDKStart(fields _: [Field], duration _: TimeInterval) {} func shouldLogAppUpdate(appVersion _: String, buildNumber _: String) -> Bool { self.shouldLogAppUpdateEvent