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-2759 Automatic w3c headers injection #1071

Merged
merged 20 commits into from
Dec 19, 2022
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions Sources/Datadog/Core/FeaturesConfiguration.swift
Original file line number Diff line number Diff line change
@@ -76,7 +76,7 @@ internal struct FeaturesConfiguration {

struct URLSessionAutoInstrumentation {
/// First party hosts defined by the user with custom tracing header types.
let userDefinedHostsWithHeaderTypes: FirstPartyHosts
let userDefinedFirstPartyHosts: FirstPartyHosts

/// URLs used internally by the SDK - they are not instrumented.
let sdkInternalURLs: Set<String>
@@ -252,7 +252,7 @@ extension FeaturesConfiguration {
if configuration.firstPartyHosts?.hosts != nil {
if configuration.tracingEnabled || configuration.rumEnabled {
urlSessionAutoInstrumentation = URLSessionAutoInstrumentation(
userDefinedHostsWithHeaderTypes: firstPartyHosts,
userDefinedFirstPartyHosts: firstPartyHosts,
sdkInternalURLs: [
logsEndpoint.url,
tracesEndpoint.url,
Original file line number Diff line number Diff line change
@@ -77,7 +77,7 @@ public class URLSessionInterceptor: URLSessionInterceptorType {
configuration: FeaturesConfiguration.URLSessionAutoInstrumentation,
handler: URLSessionInterceptionHandler
) {
self.firstPartyHosts = configuration.userDefinedHostsWithHeaderTypes
self.firstPartyHosts = configuration.userDefinedFirstPartyHosts
self.internalURLsFilter = InternalURLsFilter(urls: configuration.sdkInternalURLs)
self.handler = handler
self.tracingSampler = configuration.tracingSampler
Original file line number Diff line number Diff line change
@@ -605,7 +605,7 @@ class FeaturesConfigurationTests: XCTestCase {
rumEnabled: true,
firstPartyHosts: firstPartyHosts
)
XCTAssertEqual(configuration.urlSessionAutoInstrumentation?.userDefinedHostsWithHeaderTypes, firstPartyHosts)
XCTAssertEqual(configuration.urlSessionAutoInstrumentation?.userDefinedFirstPartyHosts, firstPartyHosts)
XCTAssertEqual(configuration.urlSessionAutoInstrumentation?.sdkInternalURLs, expectedSDKInternalURLs)
XCTAssertTrue(configuration.urlSessionAutoInstrumentation!.instrumentTracing)
XCTAssertTrue(configuration.urlSessionAutoInstrumentation!.instrumentRUM)
@@ -616,7 +616,7 @@ class FeaturesConfigurationTests: XCTestCase {
rumEnabled: false,
firstPartyHosts: firstPartyHosts
)
XCTAssertEqual(configuration.urlSessionAutoInstrumentation?.userDefinedHostsWithHeaderTypes, firstPartyHosts)
XCTAssertEqual(configuration.urlSessionAutoInstrumentation?.userDefinedFirstPartyHosts, firstPartyHosts)
XCTAssertEqual(configuration.urlSessionAutoInstrumentation?.sdkInternalURLs, expectedSDKInternalURLs)
XCTAssertTrue(configuration.urlSessionAutoInstrumentation!.instrumentTracing)
XCTAssertFalse(configuration.urlSessionAutoInstrumentation!.instrumentRUM)
@@ -627,7 +627,7 @@ class FeaturesConfigurationTests: XCTestCase {
rumEnabled: true,
firstPartyHosts: firstPartyHosts
)
XCTAssertEqual(configuration.urlSessionAutoInstrumentation?.userDefinedHostsWithHeaderTypes, firstPartyHosts)
XCTAssertEqual(configuration.urlSessionAutoInstrumentation?.userDefinedFirstPartyHosts, firstPartyHosts)
XCTAssertEqual(configuration.urlSessionAutoInstrumentation?.sdkInternalURLs, expectedSDKInternalURLs)
XCTAssertFalse(configuration.urlSessionAutoInstrumentation!.instrumentTracing)
XCTAssertTrue(configuration.urlSessionAutoInstrumentation!.instrumentRUM)
4 changes: 2 additions & 2 deletions Tests/DatadogTests/Datadog/Mocks/CoreMocks.swift
Original file line number Diff line number Diff line change
@@ -337,15 +337,15 @@ extension FeaturesConfiguration.URLSessionAutoInstrumentation {
static func mockAny() -> Self { mockWith() }

static func mockWith(
userDefinedHostsWithHeaderTypes: FirstPartyHosts = .init(),
userDefinedFirstPartyHosts: FirstPartyHosts = .init(),
sdkInternalURLs: Set<String> = [],
rumAttributesProvider: URLSessionRUMAttributesProvider? = nil,
instrumentTracing: Bool = true,
instrumentRUM: Bool = true,
tracingSampler: Sampler = .mockKeepAll()
) -> Self {
return .init(
userDefinedHostsWithHeaderTypes: userDefinedHostsWithHeaderTypes,
userDefinedFirstPartyHosts: userDefinedFirstPartyHosts,
sdkInternalURLs: sdkInternalURLs,
rumAttributesProvider: rumAttributesProvider,
instrumentTracing: instrumentTracing,
Original file line number Diff line number Diff line change
@@ -117,7 +117,7 @@ class URLSessionInterceptorTests: XCTestCase {
tracingSampler: Sampler = .mockKeepAll()
) -> FeaturesConfiguration.URLSessionAutoInstrumentation {
return .mockWith(
userDefinedHostsWithHeaderTypes: .init(["first-party.com": .init([.dd])]),
userDefinedFirstPartyHosts: .init(["first-party.com": .init([.dd])]),
sdkInternalURLs: ["https://dd.internal.com"],
instrumentTracing: tracingInstrumentationEnabled,
instrumentRUM: rumInstrumentationEnabled,
Original file line number Diff line number Diff line change
@@ -21,7 +21,9 @@ @implementation DDNSURLSessionDelegate_apiTests
- (void)testDDNSURLSessionDelegateAPI {
[[DDNSURLSessionDelegate alloc] init];
[[DDNSURLSessionDelegate alloc] initWithAdditionalFirstPartyHosts:[NSSet setWithArray:@[]]];
[[DDNSURLSessionDelegate alloc] initWithAdditionalFirstPartyHostsWithHeaderTypes:@{@"host": [[NSSet alloc] initWithObjects:[DDTracingHeaderType dd], nil]}];
[[DDNSURLSessionDelegate alloc] initWithAdditionalFirstPartyHostsWithHeaderTypes:@{
@"host": [[NSSet alloc] initWithObjects:[DDTracingHeaderType dd], nil]
}];
}

#pragma clang diagnostic pop