Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

RUMM-1490 Migrate to Intake API v2 #562

Merged
merged 9 commits into from
Aug 23, 2021
24 changes: 16 additions & 8 deletions Datadog/Datadog.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
61133BD72423979B00786299 /* DataUploadWorker.swift in Sources */ = {isa = PBXBuildFile; fileRef = 61133BB12423979B00786299 /* DataUploadWorker.swift */; };
61133BD82423979B00786299 /* HTTPClient.swift in Sources */ = {isa = PBXBuildFile; fileRef = 61133BB22423979B00786299 /* HTTPClient.swift */; };
61133BD92423979B00786299 /* DataUploadDelay.swift in Sources */ = {isa = PBXBuildFile; fileRef = 61133BB32423979B00786299 /* DataUploadDelay.swift */; };
61133BDA2423979B00786299 /* HTTPHeaders.swift in Sources */ = {isa = PBXBuildFile; fileRef = 61133BB42423979B00786299 /* HTTPHeaders.swift */; };
61133BDA2423979B00786299 /* RequestBuilder.swift in Sources */ = {isa = PBXBuildFile; fileRef = 61133BB42423979B00786299 /* RequestBuilder.swift */; };
61133BDB2423979B00786299 /* DatadogConfiguration.swift in Sources */ = {isa = PBXBuildFile; fileRef = 61133BB52423979B00786299 /* DatadogConfiguration.swift */; };
61133BDC2423979B00786299 /* Logger.swift in Sources */ = {isa = PBXBuildFile; fileRef = 61133BB62423979B00786299 /* Logger.swift */; };
61133BDD2423979B00786299 /* InternalLoggers.swift in Sources */ = {isa = PBXBuildFile; fileRef = 61133BB82423979B00786299 /* InternalLoggers.swift */; };
Expand Down Expand Up @@ -79,7 +79,7 @@
61133C5D2423990D00786299 /* DataUploadConditionsTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 61133C302423990D00786299 /* DataUploadConditionsTests.swift */; };
61133C5E2423990D00786299 /* DataUploadDelayTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 61133C312423990D00786299 /* DataUploadDelayTests.swift */; };
61133C5F2423990D00786299 /* DataUploaderTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 61133C322423990D00786299 /* DataUploaderTests.swift */; };
61133C602423990D00786299 /* HTTPHeadersTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 61133C332423990D00786299 /* HTTPHeadersTests.swift */; };
61133C602423990D00786299 /* RequestBuilderTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 61133C332423990D00786299 /* RequestBuilderTests.swift */; };
61133C612423990D00786299 /* HTTPClientTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 61133C342423990D00786299 /* HTTPClientTests.swift */; };
61133C622423990D00786299 /* InternalLoggersTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 61133C362423990D00786299 /* InternalLoggersTests.swift */; };
61133C642423990D00786299 /* LoggerTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 61133C382423990D00786299 /* LoggerTests.swift */; };
Expand Down Expand Up @@ -382,6 +382,7 @@
61D6FF7E24E53D3B00D0E375 /* BenchmarkMocks.swift in Sources */ = {isa = PBXBuildFile; fileRef = 61D6FF7D24E53D3B00D0E375 /* BenchmarkMocks.swift */; };
61D980BA24E28D0100E03345 /* RUMIntegrations.swift in Sources */ = {isa = PBXBuildFile; fileRef = 61D980B924E28D0100E03345 /* RUMIntegrations.swift */; };
61D980BC24E293F600E03345 /* RUMIntegrationsTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 61D980BB24E293F600E03345 /* RUMIntegrationsTests.swift */; };
61DA20F026C40121004AFE6D /* DataUploadStatusTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 61DA20EF26C40121004AFE6D /* DataUploadStatusTests.swift */; };
61DB33B225DEDFC200F7EA71 /* CustomObjcViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 61DB33B125DEDFC200F7EA71 /* CustomObjcViewController.m */; };
61DC6D922539E3E300FFAA22 /* LoggingCommonAsserts.swift in Sources */ = {isa = PBXBuildFile; fileRef = 61DC6D912539E3E300FFAA22 /* LoggingCommonAsserts.swift */; };
61DE332625C826E4008E3EC2 /* CrashReportingFeature.swift in Sources */ = {isa = PBXBuildFile; fileRef = 61DE332525C826E4008E3EC2 /* CrashReportingFeature.swift */; };
Expand Down Expand Up @@ -411,6 +412,7 @@
61E917D12465423600E6C631 /* TracerConfiguration.swift in Sources */ = {isa = PBXBuildFile; fileRef = 61E917D02465423600E6C631 /* TracerConfiguration.swift */; };
61E917D3246546BF00E6C631 /* TracerConfigurationTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 61E917D2246546BF00E6C631 /* TracerConfigurationTests.swift */; };
61E95D882695C00200EA3115 /* DDCrashReportExporterTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 61E95D872695C00200EA3115 /* DDCrashReportExporterTests.swift */; };
61ED39D426C2A36B002C0F26 /* DataUploadStatus.swift in Sources */ = {isa = PBXBuildFile; fileRef = 61ED39D326C2A36B002C0F26 /* DataUploadStatus.swift */; };
61EF7890257E289A00EDCCB3 /* DeleteAllDataMigratorTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 61EF788F257E289A00EDCCB3 /* DeleteAllDataMigratorTests.swift */; };
61EF789B257E2B0200EDCCB3 /* DataMigratorBenchmarkTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 61EF789A257E2B0200EDCCB3 /* DataMigratorBenchmarkTests.swift */; };
61EF78B1257E2E7A00EDCCB3 /* MoveDataMigrator.swift in Sources */ = {isa = PBXBuildFile; fileRef = 61EF78B0257E2E7A00EDCCB3 /* MoveDataMigrator.swift */; };
Expand Down Expand Up @@ -663,7 +665,7 @@
61133BB12423979B00786299 /* DataUploadWorker.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = DataUploadWorker.swift; sourceTree = "<group>"; };
61133BB22423979B00786299 /* HTTPClient.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = HTTPClient.swift; sourceTree = "<group>"; };
61133BB32423979B00786299 /* DataUploadDelay.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = DataUploadDelay.swift; sourceTree = "<group>"; };
61133BB42423979B00786299 /* HTTPHeaders.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = HTTPHeaders.swift; sourceTree = "<group>"; };
61133BB42423979B00786299 /* RequestBuilder.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = RequestBuilder.swift; sourceTree = "<group>"; };
61133BB52423979B00786299 /* DatadogConfiguration.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = DatadogConfiguration.swift; sourceTree = "<group>"; };
61133BB62423979B00786299 /* Logger.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Logger.swift; sourceTree = "<group>"; };
61133BB82423979B00786299 /* InternalLoggers.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = InternalLoggers.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -704,7 +706,7 @@
61133C302423990D00786299 /* DataUploadConditionsTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = DataUploadConditionsTests.swift; sourceTree = "<group>"; };
61133C312423990D00786299 /* DataUploadDelayTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = DataUploadDelayTests.swift; sourceTree = "<group>"; };
61133C322423990D00786299 /* DataUploaderTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = DataUploaderTests.swift; sourceTree = "<group>"; };
61133C332423990D00786299 /* HTTPHeadersTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = HTTPHeadersTests.swift; sourceTree = "<group>"; };
61133C332423990D00786299 /* RequestBuilderTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = RequestBuilderTests.swift; sourceTree = "<group>"; };
61133C342423990D00786299 /* HTTPClientTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = HTTPClientTests.swift; sourceTree = "<group>"; };
61133C362423990D00786299 /* InternalLoggersTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = InternalLoggersTests.swift; sourceTree = "<group>"; };
61133C382423990D00786299 /* LoggerTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = LoggerTests.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -1008,6 +1010,7 @@
61D6FF7D24E53D3B00D0E375 /* BenchmarkMocks.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BenchmarkMocks.swift; sourceTree = "<group>"; };
61D980B924E28D0100E03345 /* RUMIntegrations.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = RUMIntegrations.swift; sourceTree = "<group>"; };
61D980BB24E293F600E03345 /* RUMIntegrationsTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = RUMIntegrationsTests.swift; sourceTree = "<group>"; };
61DA20EF26C40121004AFE6D /* DataUploadStatusTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DataUploadStatusTests.swift; sourceTree = "<group>"; };
61DB33B025DEDFC200F7EA71 /* CustomObjcViewController.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = CustomObjcViewController.h; sourceTree = "<group>"; };
61DB33B125DEDFC200F7EA71 /* CustomObjcViewController.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = CustomObjcViewController.m; sourceTree = "<group>"; };
61DC6D912539E3E300FFAA22 /* LoggingCommonAsserts.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LoggingCommonAsserts.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -1037,6 +1040,7 @@
61E917D02465423600E6C631 /* TracerConfiguration.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TracerConfiguration.swift; sourceTree = "<group>"; };
61E917D2246546BF00E6C631 /* TracerConfigurationTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TracerConfigurationTests.swift; sourceTree = "<group>"; };
61E95D872695C00200EA3115 /* DDCrashReportExporterTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DDCrashReportExporterTests.swift; sourceTree = "<group>"; };
61ED39D326C2A36B002C0F26 /* DataUploadStatus.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DataUploadStatus.swift; sourceTree = "<group>"; };
61EF788F257E289A00EDCCB3 /* DeleteAllDataMigratorTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DeleteAllDataMigratorTests.swift; sourceTree = "<group>"; };
61EF789A257E2B0200EDCCB3 /* DataMigratorBenchmarkTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DataMigratorBenchmarkTests.swift; sourceTree = "<group>"; };
61EF78B0257E2E7A00EDCCB3 /* MoveDataMigrator.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MoveDataMigrator.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -1418,10 +1422,11 @@
children = (
61133BAF2423979B00786299 /* DataUploadConditions.swift */,
61133BB32423979B00786299 /* DataUploadDelay.swift */,
61ED39D326C2A36B002C0F26 /* DataUploadStatus.swift */,
61133BB02423979B00786299 /* DataUploader.swift */,
61133BB12423979B00786299 /* DataUploadWorker.swift */,
61133BB22423979B00786299 /* HTTPClient.swift */,
61133BB42423979B00786299 /* HTTPHeaders.swift */,
61133BB42423979B00786299 /* RequestBuilder.swift */,
);
path = Upload;
sourceTree = "<group>";
Expand Down Expand Up @@ -1668,9 +1673,10 @@
61133C2F2423990D00786299 /* DataUploadWorkerTests.swift */,
61133C302423990D00786299 /* DataUploadConditionsTests.swift */,
61133C312423990D00786299 /* DataUploadDelayTests.swift */,
61DA20EF26C40121004AFE6D /* DataUploadStatusTests.swift */,
61133C322423990D00786299 /* DataUploaderTests.swift */,
61133C332423990D00786299 /* HTTPHeadersTests.swift */,
61133C342423990D00786299 /* HTTPClientTests.swift */,
61133C332423990D00786299 /* RequestBuilderTests.swift */,
);
path = Upload;
sourceTree = "<group>";
Expand Down Expand Up @@ -3805,8 +3811,9 @@
6161249E25CAB340009901BE /* CrashContext.swift in Sources */,
61D447E224917F8F00649287 /* DateFormatting.swift in Sources */,
61133BE72423979B00786299 /* LogUtilityOutputs.swift in Sources */,
61133BDA2423979B00786299 /* HTTPHeaders.swift in Sources */,
61133BDA2423979B00786299 /* RequestBuilder.swift in Sources */,
61C3E63924BF19B4008053F2 /* RUMContext.swift in Sources */,
61ED39D426C2A36B002C0F26 /* DataUploadStatus.swift in Sources */,
61133BE82423979B00786299 /* LogFileOutput.swift in Sources */,
61133BD72423979B00786299 /* DataUploadWorker.swift in Sources */,
61133BD12423979B00786299 /* FilesOrchestrator.swift in Sources */,
Expand Down Expand Up @@ -3914,7 +3921,7 @@
613F23F1252B129E006CD2D7 /* URLSessionRUMResourcesHandlerTests.swift in Sources */,
61B03879252724AB00518F3C /* URLSessionInterceptorTests.swift in Sources */,
61C363802436164B00C4D4E6 /* ObjcExceptionHandlerTests.swift in Sources */,
61133C602423990D00786299 /* HTTPHeadersTests.swift in Sources */,
61133C602423990D00786299 /* RequestBuilderTests.swift in Sources */,
61133C572423990D00786299 /* FileReaderTests.swift in Sources */,
61133C5F2423990D00786299 /* DataUploaderTests.swift in Sources */,
61D6FF7924E42A2900D0E375 /* DataUploadWorkerMock.swift in Sources */,
Expand Down Expand Up @@ -3961,6 +3968,7 @@
61A9238E256FCAA2009B9667 /* DateCorrectionTests.swift in Sources */,
61EF7890257E289A00EDCCB3 /* DeleteAllDataMigratorTests.swift in Sources */,
61E45BCF2450A6EC00F2C652 /* TracingUUIDTests.swift in Sources */,
61DA20F026C40121004AFE6D /* DataUploadStatusTests.swift in Sources */,
614AD086254C3027004999A3 /* LaunchTimeProviderTests.swift in Sources */,
6139CD772589FEE3007E8BB7 /* RetryingTests.swift in Sources */,
61133C482423990D00786299 /* DDDatadogTests.swift in Sources */,
Expand Down
10 changes: 4 additions & 6 deletions Sources/Datadog/Core/Feature.swift
Original file line number Diff line number Diff line change
Expand Up @@ -143,8 +143,7 @@ internal struct FeatureUpload {
init(
featureName: String,
storage: FeatureStorage,
uploadHTTPHeaders: HTTPHeaders,
uploadURLProvider: UploadURLProvider,
requestBuilder: RequestBuilder,
commonDependencies: FeaturesCommonDependencies,
internalMonitor: InternalMonitor? = nil
) {
Expand All @@ -159,10 +158,8 @@ internal struct FeatureUpload {
)

let dataUploader = DataUploader(
urlProvider: uploadURLProvider,
httpClient: commonDependencies.httpClient,
httpHeaders: uploadHTTPHeaders,
internalMonitor: internalMonitor
requestBuilder: requestBuilder
)

self.init(
Expand All @@ -172,7 +169,8 @@ internal struct FeatureUpload {
dataUploader: dataUploader,
uploadConditions: uploadConditions,
delay: DataUploadDelay(performance: commonDependencies.performance),
featureName: featureName
featureName: featureName,
internalMonitor: internalMonitor
)
)
}
Expand Down
49 changes: 23 additions & 26 deletions Sources/Datadog/Core/FeaturesConfiguration.swift
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,14 @@ internal struct FeaturesConfiguration {

struct Logging {
let common: Common
let uploadURLWithClientToken: URL
let uploadURL: URL
let clientToken: String
}

struct Tracing {
let common: Common
let uploadURLWithClientToken: URL
let uploadURL: URL
let clientToken: String
let spanEventMapper: SpanEventMapper?
}

Expand All @@ -39,7 +41,8 @@ internal struct FeaturesConfiguration {
}

let common: Common
let uploadURLWithClientToken: URL
let uploadURL: URL
let clientToken: String
let applicationID: String
let sessionSamplingRate: Float
let viewEventMapper: RUMViewEventMapper?
Expand Down Expand Up @@ -76,7 +79,9 @@ internal struct FeaturesConfiguration {
let sdkEnvironment: String
/// Internal monitoring logger's name.
let loggerName = "im-logger"
let logsUploadURLWithClientToken: URL
let logsUploadURL: URL
/// The client token authorized for monitoring org (likely it's different than client token for other features).
let clientToken: String
}

/// Configuration common to all features.
Expand Down Expand Up @@ -157,20 +162,16 @@ extension FeaturesConfiguration {
if configuration.loggingEnabled {
logging = Logging(
common: common,
uploadURLWithClientToken: try ifValid(
endpointURLString: logsEndpoint.url,
clientToken: configuration.clientToken
)
uploadURL: try ifValid(endpointURLString: logsEndpoint.url),
clientToken: try ifValid(clientToken: configuration.clientToken)
)
}

if configuration.tracingEnabled {
tracing = Tracing(
common: common,
uploadURLWithClientToken: try ifValid(
endpointURLString: tracesEndpoint.url,
clientToken: configuration.clientToken
),
uploadURL: try ifValid(endpointURLString: tracesEndpoint.url),
clientToken: try ifValid(clientToken: configuration.clientToken),
spanEventMapper: configuration.spanEventMapper
)
}
Expand All @@ -188,10 +189,8 @@ extension FeaturesConfiguration {
if let rumApplicationID = configuration.rumApplicationID {
rum = RUM(
common: common,
uploadURLWithClientToken: try ifValid(
endpointURLString: rumEndpoint.url,
clientToken: configuration.clientToken
),
uploadURL: try ifValid(endpointURLString: rumEndpoint.url),
clientToken: try ifValid(clientToken: configuration.clientToken),
applicationID: rumApplicationID,
sessionSamplingRate: configuration.rumSessionsSamplingRate,
viewEventMapper: configuration.rumViewEventMapper,
Expand Down Expand Up @@ -263,10 +262,8 @@ extension FeaturesConfiguration {
common: common,
sdkServiceName: "dd-sdk-ios",
sdkEnvironment: "prod",
logsUploadURLWithClientToken: try ifValid(
endpointURLString: Datadog.Configuration.DatadogEndpoint.us1.logsEndpoint.url,
clientToken: internalMonitoringClientToken
)
logsUploadURL: try ifValid(endpointURLString: Datadog.Configuration.DatadogEndpoint.us1.logsEndpoint.url),
clientToken: try ifValid(clientToken: internalMonitoringClientToken)
)
}

Expand All @@ -291,18 +288,18 @@ private func ifValid(environment: String) throws -> String {
return environment
}

private func ifValid(endpointURLString: String, clientToken: String) throws -> URL {
private func ifValid(endpointURLString: String) throws -> URL {
guard let endpointURL = URL(string: endpointURLString) else {
throw ProgrammerError(description: "The `url` in `.custom(url:)` must be a valid URL string.")
}
return endpointURL
}

private func ifValid(clientToken: String) throws -> String {
if clientToken.isEmpty {
throw ProgrammerError(description: "`clientToken` cannot be empty.")
}
let endpointURLWithClientToken = endpointURL.appendingPathComponent(clientToken)
guard let url = URL(string: endpointURLWithClientToken.absoluteString) else {
throw ProgrammerError(description: "Cannot build upload URL.")
}
return url
return clientToken
}

private func sanitized(firstPartyHosts: Set<String>) -> Set<String> {
Expand Down
Loading