Skip to content

Commit

Permalink
Remove isFirstPartRequest from the command
Browse files Browse the repository at this point in the history
Instead, use the firstPartyURLsFilter on the dependencies to set isFirstPartyResource as we're writing the resource.
  • Loading branch information
fuzzybinary committed May 4, 2022
1 parent afc8c1c commit 62c429d
Show file tree
Hide file tree
Showing 6 changed files with 2 additions and 41 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@ internal class URLSessionRUMResourcesHandler: URLSessionInterceptionHandler, RUM
url: url,
httpMethod: RUMMethod(httpMethod: interception.request.httpMethod),
kind: RUMResourceType(request: interception.request),
isFirstPartyRequest: interception.isFirstPartyRequest,
spanContext: interception.spanContext.flatMap { spanContext in
.init(
traceID: String(spanContext.traceID.rawValue),
Expand Down
2 changes: 0 additions & 2 deletions Sources/Datadog/RUM/RUMMonitor/RUMCommand.swift
Original file line number Diff line number Diff line change
Expand Up @@ -157,8 +157,6 @@ internal struct RUMStartResourceCommand: RUMResourceCommand {
let httpMethod: RUMMethod
/// A type of the Resource if it's possible to determine on start (when the response MIME is not yet known).
let kind: RUMResourceType?
/// Whether or not the resource url targets a first party host, if that information is available.
let isFirstPartyRequest: Bool?
/// Span context passed to the RUM backend in order to generate the APM span for underlying resource.
let spanContext: RUMSpanContext?
}
Expand Down
2 changes: 1 addition & 1 deletion Sources/Datadog/RUM/RUMMonitor/Scopes/RUMViewScope.swift
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,7 @@ internal class RUMViewScope: RUMScope, RUMContextProvider {
dateCorrection: dateCorrection,
url: command.url,
httpMethod: command.httpMethod,
isFirstPartyResource: command.isFirstPartyRequest,
isFirstPartyResource: dependencies.firstPartyURLsFilter.isFirstParty(string: command.url),
resourceKindBasedOnRequest: command.kind,
spanContext: command.spanContext,
onResourceEventSent: { [weak self] in
Expand Down
3 changes: 0 additions & 3 deletions Sources/Datadog/RUMMonitor.swift
Original file line number Diff line number Diff line change
Expand Up @@ -349,7 +349,6 @@ public class RUMMonitor: DDRUMMonitor, RUMCommandSubscriber {
url: request.url?.absoluteString ?? "unknown_url",
httpMethod: RUMMethod(httpMethod: request.httpMethod),
kind: RUMResourceType(request: request),
isFirstPartyRequest: applicationScope.dependencies.firstPartyURLsFilter.isFirstParty(url: request.url),
spanContext: nil
)
)
Expand All @@ -368,7 +367,6 @@ public class RUMMonitor: DDRUMMonitor, RUMCommandSubscriber {
url: url.absoluteString,
httpMethod: .get,
kind: nil,
isFirstPartyRequest: applicationScope.dependencies.firstPartyURLsFilter.isFirstParty(url: url),
spanContext: nil
)
)
Expand All @@ -388,7 +386,6 @@ public class RUMMonitor: DDRUMMonitor, RUMCommandSubscriber {
url: urlString,
httpMethod: httpMethod,
kind: nil,
isFirstPartyRequest: applicationScope.dependencies.firstPartyURLsFilter.isFirstParty(string: urlString),
spanContext: nil
)
)
Expand Down
1 change: 0 additions & 1 deletion Tests/DatadogTests/Datadog/Mocks/RUMFeatureMocks.swift
Original file line number Diff line number Diff line change
Expand Up @@ -362,7 +362,6 @@ extension RUMStartResourceCommand: AnyMockable, RandomMockable {
url: url,
httpMethod: httpMethod,
kind: kind,
isFirstPartyRequest: isFirstPartyRequest,
spanContext: spanContext
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,39 +45,7 @@ class URLSessionRUMResourcesHandlerTests: XCTestCase {
XCTAssertNil(resourceStartCommand.spanContext)
}

func testGivenTaskInterceptionForFirstPartyHost_whenInterceptionStarts_itStartsRUMResourceForFirstPartyHost() throws {
let receiveCommand = expectation(description: "Receive RUM command")
commandSubscriber.onCommandReceived = { _ in receiveCommand.fulfill() }

// Given
let taskInterception = TaskInterception(request: .mockAny(), isFirstParty: true)

// When
handler.notify_taskInterceptionStarted(interception: taskInterception)

// Then
waitForExpectations(timeout: 0.5, handler: nil)

let resourceStartCommand = try XCTUnwrap(commandSubscriber.lastReceivedCommand as? RUMStartResourceCommand)
XCTAssertTrue(resourceStartCommand.isFirstPartyRequest!)
}

func testGivenTaskInterceptionForThirdPartyHost_whenInterceptionStarts_itStartsRUMResourceForThirdPartyHost() throws {
let receiveCommand = expectation(description: "Receive RUM command")
commandSubscriber.onCommandReceived = { _ in receiveCommand.fulfill() }

// Given
let taskInterception = TaskInterception(request: .mockAny(), isFirstParty: false)

// When
handler.notify_taskInterceptionStarted(interception: taskInterception)

// Then
waitForExpectations(timeout: 0.5, handler: nil)

let resourceStartCommand = try XCTUnwrap(commandSubscriber.lastReceivedCommand as? RUMStartResourceCommand)
XCTAssertFalse(resourceStartCommand.isFirstPartyRequest!)
}


func testGivenTaskInterceptionWithSpanContext_whenInterceptionStarts_itStartsRUMResource() throws {
let receiveCommand = expectation(description: "Receive RUM command")
Expand Down

0 comments on commit 62c429d

Please sign in to comment.