Skip to content

Commit

Permalink
RUMM-2334 Alleviate V1 Context
Browse files Browse the repository at this point in the history
  • Loading branch information
maxep committed Aug 30, 2022
1 parent d03009c commit c4c7c66
Show file tree
Hide file tree
Showing 26 changed files with 241 additions and 527 deletions.
24 changes: 6 additions & 18 deletions Datadog/Datadog.xcodeproj/project.pbxproj

Large diffs are not rendered by default.

44 changes: 0 additions & 44 deletions Sources/Datadog/Core/System/LaunchTimeProvider.swift

This file was deleted.

6 changes: 5 additions & 1 deletion Sources/Datadog/CrashReporting/CrashReporter.swift
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,11 @@ internal class CrashReporter {
if let rumFeature = rumFeature {
loggingOrRUMIntegration = CrashReportingWithRUMIntegration(rumFeature: rumFeature, context: context)
} else if let loggingFeature = loggingFeature {
loggingOrRUMIntegration = CrashReportingWithLoggingIntegration(loggingFeature: loggingFeature, context: context)
loggingOrRUMIntegration = CrashReportingWithLoggingIntegration(
loggingFeature: loggingFeature,
context: context,
dateProvider: loggingFeature.configuration.dateProvider
)
} else {
loggingOrRUMIntegration = nil
}
Expand Down
5 changes: 1 addition & 4 deletions Sources/Datadog/Datadog.swift
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,6 @@ public class Datadog {
let dateCorrector = ServerDateCorrector(serverDateProvider: serverDateProvider)
let networkConnectionInfoProvider = NetworkConnectionInfoProvider()
let carrierInfoProvider = CarrierInfoProvider()
let launchTimeProvider = LaunchTimeProvider()
let appStateListener = AppStateListener(dateProvider: configuration.common.dateProvider)

// Set default `DatadogCore`:
Expand All @@ -197,9 +196,7 @@ public class Datadog {
dateCorrector: dateCorrector,
networkConnectionInfoProvider: networkConnectionInfoProvider,
carrierInfoProvider: carrierInfoProvider,
userInfoProvider: userInfoProvider,
appStateListener: appStateListener,
launchTimeProvider: launchTimeProvider
userInfoProvider: userInfoProvider
),
contextProvider: DatadogContextProvider(
configuration: configuration.common,
Expand Down
18 changes: 2 additions & 16 deletions Sources/Datadog/DatadogCore/DatadogCore.swift
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ extension DatadogCore: DatadogV1CoreProtocol {
)
}

var context: DatadogV1Context? {
var legacyContext: DatadogV1Context? {
return v1Context
}

Expand Down Expand Up @@ -271,43 +271,29 @@ extension DatadogV1Context {
/// - Parameters:
/// - configuration: The configuration.
/// - device: The device description.
/// - dateProvider: The local date provider.
/// - dateCorrector: The server date corrector.
/// - networkConnectionInfoProvider: The network info provider.
/// - carrierInfoProvider: The carrier info provider.
/// - userInfoProvider: The user info provider.
/// - appStateListener: The application state listener.
/// - launchTimeProvider: The launch time provider.
init(
configuration: CoreConfiguration,
device: DeviceInfo,
dateCorrector: DateCorrector,
networkConnectionInfoProvider: NetworkConnectionInfoProviderType,
carrierInfoProvider: CarrierInfoProviderType,
userInfoProvider: UserInfoProvider,
appStateListener: AppStateListening,
launchTimeProvider: LaunchTimeProviderType
userInfoProvider: UserInfoProvider
) {
self.site = configuration.site
self.clientToken = configuration.clientToken
self.service = configuration.serviceName
self.env = configuration.environment
self.version = configuration.applicationVersion
self.source = configuration.source
self.sdkVersion = configuration.sdkVersion
self.ciAppOrigin = configuration.origin
self.applicationName = configuration.applicationName
self.applicationBundleIdentifier = configuration.applicationBundleIdentifier
self.dateProvider = configuration.dateProvider

self.sdkInitDate = dateProvider.now
self.device = device
self.dateCorrector = dateCorrector
self.networkConnectionInfoProvider = networkConnectionInfoProvider
self.carrierInfoProvider = carrierInfoProvider
self.userInfoProvider = userInfoProvider
self.appStateListener = appStateListener
self.launchTimeProvider = launchTimeProvider
}
}

Expand Down
29 changes: 0 additions & 29 deletions Sources/Datadog/DatadogInternal/DatadogV1Context.swift
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,6 @@ internal typealias DatadogSite = Datadog.Configuration.DatadogEndpoint
internal struct DatadogV1Context {
// MARK: Datadog Specific

/// [Datadog Site](https://docs.datadoghq.com/getting_started/site/) for data uploads. It can be `nil` in V1
/// if the SDK is configured using deprecated APIs: `set(logsEndpoint:)`, `set(tracesEndpoint:)` and `set(rumEndpoint:)`.
let site: DatadogSite?

/// The client token allowing for data uploads to [Datadog Site](https://docs.datadoghq.com/getting_started/site/).
let clientToken: String

/// The name of the service that data is generated from. Used for [Unified Service Tagging](https://docs.datadoghq.com/getting_started/tagging/unified_service_tagging).
let service: String

Expand All @@ -45,29 +38,13 @@ internal struct DatadogV1Context {
/// The version of Datadog iOS SDK.
let sdkVersion: String

/// The name of [CI Visibility](https://docs.datadoghq.com/continuous_integration/) origin.
/// It is only set if the SDK is running with a context passed from [Swift Tests](https://docs.datadoghq.com/continuous_integration/setup_tests/swift/?tab=swiftpackagemanager) library.
let ciAppOrigin: String?

// MARK: - Application Specific

/// The name of the application, read from `Info.plist` (`CFBundleExecutable`).
let applicationName: String

/// The bundle identifier, read from `Info.plist` (`CFBundleIdentifier`).
let applicationBundleIdentifier: String

/// Date of SDK initialization measured in device time (without NTP correction).
let sdkInitDate: Date

/// Current device information.
let device: DeviceInfo

// MARK: Providers

/// Time provider.
let dateProvider: DateProvider

/// NTP time correction provider.
let dateCorrector: DateCorrector

Expand All @@ -79,10 +56,4 @@ internal struct DatadogV1Context {

/// User information provider.
let userInfoProvider: UserInfoProvider

/// Provides the history of app foreground / background states and lets subscribe for their updates.
let appStateListener: AppStateListening

/// Provides the information about application launch time.
let launchTimeProvider: LaunchTimeProviderType
}
4 changes: 2 additions & 2 deletions Sources/Datadog/DatadogInternal/DatadogV1CoreProtocol.swift
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ internal protocol DatadogV1CoreProtocol: DatadogCoreProtocol {
// MARK: - V1 interface

/// The SDK context created upon core initialization or `nil` if SDK was not yet initialized.
var context: DatadogV1Context? { get }
var legacyContext: DatadogV1Context? { get }

/// Registers a feature instance by its type description.
///
Expand Down Expand Up @@ -60,7 +60,7 @@ extension NOPDatadogCore: DatadogV1CoreProtocol {
// MARK: - V1 interface

/// Returns `nil`.
var context: DatadogV1Context? {
var legacyContext: DatadogV1Context? {
return nil
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,23 +17,29 @@ internal struct CrashReportingWithLoggingIntegration: CrashReportingIntegration
/// authorized output working simultaneously in the Logging feature.
private let logOutput: LogOutput

/// Time provider.
private let dateProvider: DateProvider

private let context: DatadogV1Context

init(loggingFeature: LoggingFeature, context: DatadogV1Context) {
init(loggingFeature: LoggingFeature, context: DatadogV1Context, dateProvider: DateProvider) {
self.init(
logOutput: LogFileOutput(
fileWriter: loggingFeature.storage.arbitraryAuthorizedWriter
),
context: context
context: context,
dateProvider: loggingFeature.configuration.dateProvider
)
}

init(
logOutput: LogOutput,
context: DatadogV1Context
context: DatadogV1Context,
dateProvider: DateProvider
) {
self.logOutput = logOutput
self.context = context
self.dateProvider = dateProvider
}

func send(crashReport: DDCrashReport, with crashContext: CrashContext) {
Expand All @@ -46,7 +52,7 @@ internal struct CrashReportingWithLoggingIntegration: CrashReportingIntegration
// approximation we can get.
let currentTimeCorrection = context.dateCorrector.offset

let crashDate = crashReport.date ?? context.dateProvider.now
let crashDate = crashReport.date ?? dateProvider.now
let realCrashDate = crashDate.addingTimeInterval(currentTimeCorrection)

let log = createLog(from: crashReport, crashContext: crashContext, crashDate: realCrashDate)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,11 +66,11 @@ internal struct CrashReportingWithRUMIntegration: CrashReportingIntegration {
// from the moment of crash), but this is the best approximation we can get.
let currentTimeCorrection = context.dateCorrector.offset

let crashDate = crashReport.date ?? context.dateProvider.now
let crashDate = crashReport.date ?? rumConfiguration.dateProvider.now
let adjustedCrashTimings = AdjustedCrashTimings(
crashDate: crashDate,
realCrashDate: crashDate.addingTimeInterval(currentTimeCorrection),
realDateNow: context.dateProvider.now.addingTimeInterval(currentTimeCorrection)
realDateNow: rumConfiguration.dateProvider.now.addingTimeInterval(currentTimeCorrection)
)

if let lastRUMViewEvent = crashContext.lastRUMViewEvent {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public extension WKUserContentController {
}

private func trackDatadogEventsOrThrow(in hosts: Set<String>, sdk core: DatadogCoreProtocol) throws {
guard let context = core.v1.context else {
guard let context = core.v1.legacyContext else {
throw ProgrammerError(
description: "`Datadog.initialize()` must be called prior to `trackDatadogEvents(in:)`."
)
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@ class CrashReportingWithLoggingIntegrationTests: XCTestCase {
let integration = CrashReportingWithLoggingIntegration(
logOutput: logOutput,
context: .mockWith(
dateProvider: RelativeDateProvider(using: .mockDecember15th2019At10AMUTC()),
dateCorrector: DateCorrectorMock()
)
),
dateProvider: RelativeDateProvider(using: .mockDecember15th2019At10AMUTC())
)
integration.send(crashReport: crashReport, with: crashContext)

Expand Down Expand Up @@ -86,9 +86,9 @@ class CrashReportingWithLoggingIntegrationTests: XCTestCase {
env: configuration.environment,
version: configuration.applicationVersion,
sdkVersion: configuration.sdkVersion,
dateProvider: RelativeDateProvider(using: .mockRandomInThePast()),
dateCorrector: DateCorrectorMock(offset: dateCorrectionOffset)
)
),
dateProvider: RelativeDateProvider(using: .mockRandomInThePast())
)
integration.send(crashReport: crashReport, with: crashContext)

Expand Down
Loading

0 comments on commit c4c7c66

Please sign in to comment.