dd-sdk-ios icon indicating copy to clipboard operation
dd-sdk-ios copied to clipboard

How to check if RUM is enabled before accessing RUMMonitor?

Open mlvea opened this issue 9 months ago • 3 comments

Question

public class RUMMonitor {
    /// Obtains the RUM monitor for manual interaction with the RUM feature.
    ///
    /// It requires `RUM.enable(with:in:)` to be called first - otherwise it will return no-op implementation.
    /// - Parameter core: the instance of Datadog SDK the RUM feature was enabled in (global instance by default)
    /// - Returns: the RUM monitor
    public static func shared(in core: DatadogCoreProtocol = CoreRegistry.default) -> RUMMonitorProtocol {
        do {
            guard !(core is NOPDatadogCore) else {
                throw ProgrammerError(
                    description: "Datadog SDK must be initialized and RUM feature must be enabled before calling `RUMMonitor.shared(in:)`."
                )
            }
            guard let feature = core.get(feature: RUMFeature.self) else {
                throw ProgrammerError(
                    description: "RUM feature must be enabled before calling `RUMMonitor.shared(in:)`."
                )
            }

            return feature.monitor
        } catch {
            consolePrint("\(error)", .error)
            return NOPMonitor()
        }
    }
}

I'm seeing

ProgrammerError(
                    description: "Datadog SDK must be initialized and RUM feature must be enabled before calling `RUMMonitor.shared(in:)`."
                )

in my logs.

I would have preferred this function re-throw the error for client to handle it. Anyhow, is there public API in RUM to check if it is enabled?

mlvea avatar May 08 '24 06:05 mlvea