Skip to content

Commit

Permalink
Merge pull request #1545 from DataDog/release/2.5.0
Browse files Browse the repository at this point in the history
Release `2.5.0`
  • Loading branch information
maxep authored Nov 14, 2023
2 parents 506d662 + 9e7405b commit aa66234
Show file tree
Hide file tree
Showing 104 changed files with 2,635 additions and 1,081 deletions.
13 changes: 13 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
# Unreleased

# 2.5.0 / 08-11-2023

- [BUGFIX] Optimize Session Replay diffing algorithm. See [#1524][]
- [FEATURE] Add network instrumentation for async/await URLSession APIs. See [#1394][]
- [FEATURE] Change default tracing headers for first party hosts to use both Datadog headers and W3C `tracecontext` headers. See [#1529][]
- [FEATURE] Add tracestate headers when using W3C tracecontext. See [#1536][]
- [BUGFIX] Fix RUM ViewController leaks. See [#1533][]

# 2.4.0 / 18-10-2023

- [FEATURE] WebView Log events can be now sampled. See [#1515][]
Expand Down Expand Up @@ -544,6 +552,11 @@ Release `2.0` introduces breaking changes. Follow the [Migration Guide](MIGRATIO
[#1465]: https://github.com/DataDog/dd-sdk-ios/pull/1465
[#1498]: https://github.com/DataDog/dd-sdk-ios/pull/1498
[#1493]: https://github.com/DataDog/dd-sdk-ios/pull/1493
[#1394]: https://github.com/DataDog/dd-sdk-ios/pull/1394
[#1524]: https://github.com/DataDog/dd-sdk-ios/pull/1524
[#1529]: https://github.com/DataDog/dd-sdk-ios/pull/1529
[#1533]: https://github.com/DataDog/dd-sdk-ios/pull/1533
[#1536]: https://github.com/DataDog/dd-sdk-ios/pull/1536
[@00fa9a]: https://github.com/00FA9A
[@britton-earnin]: https://github.com/Britton-Earnin
[@hengyu]: https://github.com/Hengyu
Expand Down
121 changes: 108 additions & 13 deletions Datadog/Datadog.xcodeproj/project.pbxproj

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@
</EnvironmentVariable>
<EnvironmentVariable
key = "DD_DISABLE_NETWORK_INSTRUMENTATION"
value = "$(DD_DISABLE_NETWORK_INSTRUMENTATION)"
value = "1"
isEnabled = "YES">
</EnvironmentVariable>
<EnvironmentVariable
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@
</EnvironmentVariable>
<EnvironmentVariable
key = "DD_DISABLE_NETWORK_INSTRUMENTATION"
value = "$(DD_DISABLE_NETWORK_INSTRUMENTATION)"
value = "1"
isEnabled = "YES">
</EnvironmentVariable>
<EnvironmentVariable
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,10 @@ internal struct DebugManualTraceInjectionView: View {
Tracer.shared().inject(spanContext: span.context, writer: writer)
writer.traceHeaderFields.forEach { request.setValue($0.value, forHTTPHeaderField: $0.key) }
case .w3c:
let writer = W3CHTTPHeadersWriter(sampleRate: sampleRate)
let writer = W3CHTTPHeadersWriter(
sampleRate: sampleRate,
tracestate: [:]
)
Tracer.shared().inject(spanContext: span.context, writer: writer)
writer.traceHeaderFields.forEach { request.setValue($0.value, forHTTPHeaderField: $0.key) }
case .b3Single:
Expand Down
2 changes: 1 addition & 1 deletion DatadogAlamofireExtension.podspec
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Pod::Spec.new do |s|
s.name = "DatadogAlamofireExtension"
s.version = "2.4.0"
s.version = "2.5.0"
s.summary = "An Official Extensions of Datadog Swift SDK for Alamofire."

s.homepage = "https://www.datadoghq.com"
Expand Down
2 changes: 1 addition & 1 deletion DatadogCore.podspec
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Pod::Spec.new do |s|
s.name = "DatadogCore"
s.version = "2.4.0"
s.version = "2.5.0"
s.summary = "Official Datadog Swift SDK for iOS."

s.homepage = "https://www.datadoghq.com"
Expand Down
20 changes: 8 additions & 12 deletions DatadogCore/Sources/PerformancePreset.swift
Original file line number Diff line number Diff line change
Expand Up @@ -75,23 +75,19 @@ internal extension PerformancePreset {
) {
let meanFileAgeInSeconds: TimeInterval = {
switch (bundleType, batchSize) {
case (.iOSApp, .small): return 5
case (.iOSApp, .medium): return 15
case (.iOSApp, .large): return 60
case (.iOSAppExtension, .small): return 1
case (.iOSAppExtension, .medium): return 3
case (.iOSAppExtension, .large): return 12
case (.iOSApp, .small): return 3
case (.iOSApp, .medium): return 10
case (.iOSApp, .large): return 35
case (.iOSAppExtension, _): return 1
}
}()

let minUploadDelayInSeconds: TimeInterval = {
switch (bundleType, uploadFrequency) {
case (.iOSApp, .frequent): return 1
case (.iOSApp, .average): return 5
case (.iOSApp, .rare): return 10
case (.iOSAppExtension, .frequent): return 0.5
case (.iOSAppExtension, .average): return 1
case (.iOSAppExtension, .rare): return 5
case (.iOSApp, .frequent): return 0.5
case (.iOSApp, .average): return 2
case (.iOSApp, .rare): return 5
case (.iOSAppExtension, _): return 0.5
}
}()

Expand Down
2 changes: 1 addition & 1 deletion DatadogCore/Sources/Versioning.swift
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
// GENERATED FILE: Do not edit directly

internal let __sdkVersion = "2.4.0"
internal let __sdkVersion = "2.5.0"
60 changes: 30 additions & 30 deletions DatadogCore/Tests/Datadog/Core/PerformancePresetTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,41 +12,41 @@ import DatadogInternal
class PerformancePresetTests: XCTestCase {
func testIOSAppPresets() {
let smallBatchAnyFrequency = PerformancePreset(batchSize: .small, uploadFrequency: .mockRandom(), bundleType: .iOSApp)
XCTAssertEqual(smallBatchAnyFrequency.maxFileAgeForWrite, 4.75)
XCTAssertEqual(smallBatchAnyFrequency.minFileAgeForRead, 5.25)
XCTAssertEqual(smallBatchAnyFrequency.uploaderWindow, 5)
XCTAssertEqual(smallBatchAnyFrequency.maxFileAgeForWrite, 2.85, accuracy: 0.01)
XCTAssertEqual(smallBatchAnyFrequency.minFileAgeForRead, 3.15, accuracy: 0.01)
XCTAssertEqual(smallBatchAnyFrequency.uploaderWindow, 3.0)
assertPresetCommonValues(in: smallBatchAnyFrequency)

let mediumBatchAnyFrequency = PerformancePreset(batchSize: .medium, uploadFrequency: .mockRandom(), bundleType: .iOSApp)
XCTAssertEqual(mediumBatchAnyFrequency.maxFileAgeForWrite, 14.25)
XCTAssertEqual(mediumBatchAnyFrequency.minFileAgeForRead, 15.75)
XCTAssertEqual(mediumBatchAnyFrequency.uploaderWindow, 15)
XCTAssertEqual(mediumBatchAnyFrequency.maxFileAgeForWrite, 9.5)
XCTAssertEqual(mediumBatchAnyFrequency.minFileAgeForRead, 10.5)
XCTAssertEqual(mediumBatchAnyFrequency.uploaderWindow, 10.0)
assertPresetCommonValues(in: mediumBatchAnyFrequency)

let largeBatchAnyFrequency = PerformancePreset(batchSize: .large, uploadFrequency: .mockRandom(), bundleType: .iOSApp)
XCTAssertEqual(largeBatchAnyFrequency.maxFileAgeForWrite, 57.0)
XCTAssertEqual(largeBatchAnyFrequency.minFileAgeForRead, 63.0)
XCTAssertEqual(largeBatchAnyFrequency.uploaderWindow, 60)
XCTAssertEqual(largeBatchAnyFrequency.maxFileAgeForWrite, 33.25)
XCTAssertEqual(largeBatchAnyFrequency.minFileAgeForRead, 36.75)
XCTAssertEqual(largeBatchAnyFrequency.uploaderWindow, 35)
assertPresetCommonValues(in: largeBatchAnyFrequency)

let frequentUploadAnyBatch = PerformancePreset(batchSize: .mockRandom(), uploadFrequency: .frequent, bundleType: .iOSApp)
XCTAssertEqual(frequentUploadAnyBatch.initialUploadDelay, 5.0)
XCTAssertEqual(frequentUploadAnyBatch.minUploadDelay, 1.0)
XCTAssertEqual(frequentUploadAnyBatch.maxUploadDelay, 10.0)
XCTAssertEqual(frequentUploadAnyBatch.initialUploadDelay, 2.5)
XCTAssertEqual(frequentUploadAnyBatch.minUploadDelay, 0.5)
XCTAssertEqual(frequentUploadAnyBatch.maxUploadDelay, 5.0)
XCTAssertEqual(frequentUploadAnyBatch.uploadDelayChangeRate, 0.1)
assertPresetCommonValues(in: frequentUploadAnyBatch)

let averageUploadAnyBatch = PerformancePreset(batchSize: .mockRandom(), uploadFrequency: .average, bundleType: .iOSApp)
XCTAssertEqual(averageUploadAnyBatch.initialUploadDelay, 25.0)
XCTAssertEqual(averageUploadAnyBatch.minUploadDelay, 5.0)
XCTAssertEqual(averageUploadAnyBatch.maxUploadDelay, 50.0)
XCTAssertEqual(averageUploadAnyBatch.initialUploadDelay, 10.0)
XCTAssertEqual(averageUploadAnyBatch.minUploadDelay, 2.0)
XCTAssertEqual(averageUploadAnyBatch.maxUploadDelay, 20.0)
XCTAssertEqual(averageUploadAnyBatch.uploadDelayChangeRate, 0.1)
assertPresetCommonValues(in: averageUploadAnyBatch)

let rareUploadAnyBatch = PerformancePreset(batchSize: .mockRandom(), uploadFrequency: .rare, bundleType: .iOSApp)
XCTAssertEqual(rareUploadAnyBatch.initialUploadDelay, 50.0)
XCTAssertEqual(rareUploadAnyBatch.minUploadDelay, 10.0)
XCTAssertEqual(rareUploadAnyBatch.maxUploadDelay, 100.0)
XCTAssertEqual(rareUploadAnyBatch.initialUploadDelay, 25.0)
XCTAssertEqual(rareUploadAnyBatch.minUploadDelay, 5.0)
XCTAssertEqual(rareUploadAnyBatch.maxUploadDelay, 50.0)
XCTAssertEqual(rareUploadAnyBatch.uploadDelayChangeRate, 0.1)
assertPresetCommonValues(in: rareUploadAnyBatch)
}
Expand All @@ -59,15 +59,15 @@ class PerformancePresetTests: XCTestCase {
assertPresetCommonValues(in: smallBatchAnyFrequency)

let mediumBatchAnyFrequency = PerformancePreset(batchSize: .medium, uploadFrequency: .mockRandom(), bundleType: .iOSAppExtension)
XCTAssertEqual(mediumBatchAnyFrequency.maxFileAgeForWrite, 2.85, accuracy: 0.01)
XCTAssertEqual(mediumBatchAnyFrequency.minFileAgeForRead, 3.15, accuracy: 0.01)
XCTAssertEqual(mediumBatchAnyFrequency.uploaderWindow, 3)
XCTAssertEqual(mediumBatchAnyFrequency.maxFileAgeForWrite, 0.95, accuracy: 0.01)
XCTAssertEqual(mediumBatchAnyFrequency.minFileAgeForRead, 1.05, accuracy: 0.01)
XCTAssertEqual(mediumBatchAnyFrequency.uploaderWindow, 1)
assertPresetCommonValues(in: mediumBatchAnyFrequency)

let largeBatchAnyFrequency = PerformancePreset(batchSize: .large, uploadFrequency: .mockRandom(), bundleType: .iOSAppExtension)
XCTAssertEqual(largeBatchAnyFrequency.maxFileAgeForWrite, 11.4, accuracy: 0.01)
XCTAssertEqual(largeBatchAnyFrequency.minFileAgeForRead, 12.6, accuracy: 0.01)
XCTAssertEqual(largeBatchAnyFrequency.uploaderWindow, 12)
XCTAssertEqual(largeBatchAnyFrequency.maxFileAgeForWrite, 0.95, accuracy: 0.01)
XCTAssertEqual(largeBatchAnyFrequency.minFileAgeForRead, 1.05, accuracy: 0.01)
XCTAssertEqual(largeBatchAnyFrequency.uploaderWindow, 1)
assertPresetCommonValues(in: largeBatchAnyFrequency)

let frequentUploadAnyBatch = PerformancePreset(batchSize: .mockRandom(), uploadFrequency: .frequent, bundleType: .iOSAppExtension)
Expand All @@ -78,16 +78,16 @@ class PerformancePresetTests: XCTestCase {
assertPresetCommonValues(in: frequentUploadAnyBatch)

let averageUploadAnyBatch = PerformancePreset(batchSize: .mockRandom(), uploadFrequency: .average, bundleType: .iOSAppExtension)
XCTAssertEqual(averageUploadAnyBatch.initialUploadDelay, 0.5)
XCTAssertEqual(averageUploadAnyBatch.minUploadDelay, 1.0)
XCTAssertEqual(averageUploadAnyBatch.maxUploadDelay, 5.0)
XCTAssertEqual(averageUploadAnyBatch.initialUploadDelay, 0.25)
XCTAssertEqual(averageUploadAnyBatch.minUploadDelay, 0.5)
XCTAssertEqual(averageUploadAnyBatch.maxUploadDelay, 2.5)
XCTAssertEqual(averageUploadAnyBatch.uploadDelayChangeRate, 0.5)
assertPresetCommonValues(in: averageUploadAnyBatch)

let rareUploadAnyBatch = PerformancePreset(batchSize: .mockRandom(), uploadFrequency: .rare, bundleType: .iOSAppExtension)
XCTAssertEqual(rareUploadAnyBatch.initialUploadDelay, 2.5)
XCTAssertEqual(rareUploadAnyBatch.minUploadDelay, 5.0)
XCTAssertEqual(rareUploadAnyBatch.maxUploadDelay, 25.0)
XCTAssertEqual(rareUploadAnyBatch.initialUploadDelay, 0.25)
XCTAssertEqual(rareUploadAnyBatch.minUploadDelay, 0.5)
XCTAssertEqual(rareUploadAnyBatch.maxUploadDelay, 2.5)
XCTAssertEqual(rareUploadAnyBatch.uploadDelayChangeRate, 0.5)
assertPresetCommonValues(in: rareUploadAnyBatch)
}
Expand Down
11 changes: 6 additions & 5 deletions DatadogCore/Tests/Datadog/Mocks/RUMFeatureMocks.swift
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ extension RUMStartViewCommand: AnyMockable, RandomMockable {
return .mockWith(
time: .mockRandomInThePast(),
attributes: mockRandomAttributes(),
identity: String.mockRandom(),
identity: String.mockRandom().asRUMViewIdentity(),
name: .mockRandom(),
path: .mockRandom()
)
Expand All @@ -177,7 +177,7 @@ extension RUMStartViewCommand: AnyMockable, RandomMockable {
static func mockWith(
time: Date = Date(),
attributes: [AttributeKey: AttributeValue] = [:],
identity: RUMViewIdentifiable = mockView,
identity: RUMViewIdentity = mockViewIdentity,
name: String = .mockAny(),
path: String? = nil
) -> RUMStartViewCommand {
Expand All @@ -198,14 +198,14 @@ extension RUMStopViewCommand: AnyMockable, RandomMockable {
return .mockWith(
time: .mockRandomInThePast(),
attributes: mockRandomAttributes(),
identity: String.mockRandom()
identity: String.mockRandom().asRUMViewIdentity()
)
}

static func mockWith(
time: Date = Date(),
attributes: [AttributeKey: AttributeValue] = [:],
identity: RUMViewIdentifiable = mockView
identity: RUMViewIdentity = mockViewIdentity
) -> RUMStopViewCommand {
return RUMStopViewCommand(
time: time, attributes: attributes, identity: identity
Expand Down Expand Up @@ -786,6 +786,7 @@ func createMockView(viewControllerClassName: String) -> UIViewController {

///// Holds the `mockView` object so it can be weakly referenced by `RUMViewScope` mocks.
let mockView: UIViewController = createMockViewInWindow()
let mockViewIdentity = mockView.asRUMViewIdentity()

extension RUMViewScope {
static func mockAny() -> RUMViewScope {
Expand All @@ -802,7 +803,7 @@ extension RUMViewScope {
isInitialView: Bool = false,
parent: RUMContextProvider = RUMContextProviderMock(),
dependencies: RUMScopeDependencies = .mockAny(),
identity: RUMViewIdentifiable = mockView,
identity: RUMViewIdentity = mockViewIdentity,
path: String = .mockAny(),
name: String = .mockAny(),
attributes: [AttributeKey: AttributeValue] = [:],
Expand Down
6 changes: 3 additions & 3 deletions DatadogCore/Tests/Datadog/RUM/RUMDebuggingTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ class RUMDebuggingTests: XCTestCase {
dependencies: .mockWith(rumApplicationID: "rum-123")
)
_ = applicationScope.process(
command: RUMStartViewCommand.mockWith(identity: mockView, name: "FirstView"),
command: RUMStartViewCommand.mockWith(identity: mockViewIdentity, name: "FirstView"),
context: .mockAny(),
writer: FileWriterMock()
)
Expand Down Expand Up @@ -56,7 +56,7 @@ class RUMDebuggingTests: XCTestCase {
dependencies: .mockWith(rumApplicationID: "rum-123")
)
_ = applicationScope.process(
command: RUMStartViewCommand.mockWith(identity: mockView, name: "FirstView"),
command: RUMStartViewCommand.mockWith(identity: mockViewIdentity, name: "FirstView"),
context: context,
writer: writer
)
Expand All @@ -66,7 +66,7 @@ class RUMDebuggingTests: XCTestCase {
writer: writer
)
_ = applicationScope.process(
command: RUMStartViewCommand.mockWith(identity: mockView, name: "SecondView"),
command: RUMStartViewCommand.mockWith(identity: mockViewIdentity, name: "SecondView"),
context: context,
writer: writer
)
Expand Down
25 changes: 22 additions & 3 deletions DatadogCore/Tests/Datadog/TracerTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -871,14 +871,20 @@ class TracerTests: XCTestCase {
let spanContext2 = DDSpanContext(traceID: 4, spanID: 5, parentSpanID: 6, baggageItems: .mockAny())
let spanContext3 = DDSpanContext(traceID: 77, spanID: 88, parentSpanID: nil, baggageItems: .mockAny())

let httpHeadersWriter = W3CHTTPHeadersWriter(sampler: .mockKeepAll())
let httpHeadersWriter = W3CHTTPHeadersWriter(
sampler: .mockKeepAll(),
tracestate: [
W3CHTTPHeaders.Constants.origin: W3CHTTPHeaders.Constants.originRUM
]
)
XCTAssertEqual(httpHeadersWriter.traceHeaderFields, [:])

// When
tracer.inject(spanContext: spanContext1, writer: httpHeadersWriter)

// Then
let expectedHTTPHeaders1 = [
"tracestate": "dd=o:rum;p:0000000000000002;s:1",
"traceparent": "00-00000000000000000000000000000001-0000000000000002-01"
]
XCTAssertEqual(httpHeadersWriter.traceHeaderFields, expectedHTTPHeaders1)
Expand All @@ -888,6 +894,7 @@ class TracerTests: XCTestCase {

// Then
let expectedHTTPHeaders2 = [
"tracestate": "dd=o:rum;p:0000000000000005;s:1",
"traceparent": "00-00000000000000000000000000000004-0000000000000005-01"
]
XCTAssertEqual(httpHeadersWriter.traceHeaderFields, expectedHTTPHeaders2)
Expand All @@ -897,6 +904,7 @@ class TracerTests: XCTestCase {

// Then
let expectedHTTPHeaders3 = [
"tracestate": "dd=o:rum;p:0000000000000058;s:1",
"traceparent": "00-0000000000000000000000000000004d-0000000000000058-01"
]
XCTAssertEqual(httpHeadersWriter.traceHeaderFields, expectedHTTPHeaders3)
Expand All @@ -907,14 +915,20 @@ class TracerTests: XCTestCase {
let tracer = Tracer.shared(in: core)
let spanContext = DDSpanContext(traceID: 1, spanID: 2, parentSpanID: .mockAny(), baggageItems: .mockAny())

let httpHeadersWriter = W3CHTTPHeadersWriter(sampler: .mockRejectAll())
let httpHeadersWriter = W3CHTTPHeadersWriter(
sampler: .mockRejectAll(),
tracestate: [
W3CHTTPHeaders.Constants.origin: W3CHTTPHeaders.Constants.originRUM
]
)
XCTAssertEqual(httpHeadersWriter.traceHeaderFields, [:])

// When
tracer.inject(spanContext: spanContext, writer: httpHeadersWriter)

// Then
let expectedHTTPHeaders = [
"tracestate": "dd=o:rum;p:0000000000000002;s:0",
"traceparent": "00-00000000000000000000000000000001-0000000000000002-00"
]
XCTAssertEqual(httpHeadersWriter.traceHeaderFields, expectedHTTPHeaders)
Expand Down Expand Up @@ -997,7 +1011,12 @@ class TracerTests: XCTestCase {
let tracer = Tracer.shared(in: core)
let injectedSpanContext = DDSpanContext(traceID: 1, spanID: 2, parentSpanID: 3, baggageItems: .mockAny())

let httpHeadersWriter = W3CHTTPHeadersWriter(sampler: .mockKeepAll())
let httpHeadersWriter = W3CHTTPHeadersWriter(
sampler: .mockKeepAll(),
tracestate: [
W3CHTTPHeaders.Constants.origin: W3CHTTPHeaders.Constants.originRUM
]
)
tracer.inject(spanContext: injectedSpanContext, writer: httpHeadersWriter)

let httpHeadersReader = W3CHTTPHeadersReader(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -207,4 +207,24 @@ class TracingURLSessionHandlerTests: XCTestCase {
)
XCTAssertEqual(log.attributes.userAttributes.count, 1)
}

func testGivenAllTracingHeaderTypes_itUsesTheSameIds() throws {
let request: URLRequest = .mockWith(httpMethod: "GET")
let modifiedRequest = handler.modify(request: request, headerTypes: [.datadog, .tracecontext, .b3, .b3multi])

XCTAssertEqual(
modifiedRequest.allHTTPHeaderFields,
[
"traceparent": "00-00000000000000000000000000000001-0000000000000001-01",
"X-B3-SpanId": "0000000000000001",
"X-B3-Sampled": "1",
"X-B3-TraceId": "00000000000000000000000000000001",
"b3": "00000000000000000000000000000001-0000000000000001-1",
"x-datadog-trace-id": "1",
"tracestate": "dd=p:0000000000000001;s:1",
"x-datadog-parent-id": "1",
"x-datadog-sampling-priority": "1"
]
)
}
}
Loading

0 comments on commit aa66234

Please sign in to comment.