Skip to content

Commit

Permalink
Merge branch 'develop' into release/2.9.0
Browse files Browse the repository at this point in the history
  • Loading branch information
maxep authored Apr 11, 2024
2 parents 6ae0fb9 + 93ed73a commit 290ed6c
Show file tree
Hide file tree
Showing 91 changed files with 2,831 additions and 1,012 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# Unreleased

* [FEATURE] Fatal App Hangs are tracked in RUM. See [#1763][]

# 2.9.0 / 11-04-2024

* [FEATURE] Call RUM's `errorEventMapper` for crashes. See [#1742][]
Expand Down Expand Up @@ -627,6 +629,7 @@ Release `2.0` introduces breaking changes. Follow the [Migration Guide](MIGRATIO
[#1741]: https://github.com/DataDog/dd-sdk-ios/pull/1741
[#1742]: https://github.com/DataDog/dd-sdk-ios/pull/1742
[#1746]: https://github.com/DataDog/dd-sdk-ios/pull/1746
[#1763]: https://github.com/DataDog/dd-sdk-ios/pull/1763
[#1767]: https://github.com/DataDog/dd-sdk-ios/pull/1767
[@00fa9a]: https://github.com/00FA9A
[@britton-earnin]: https://github.com/Britton-Earnin
Expand Down
78 changes: 72 additions & 6 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 @@ -72,14 +72,14 @@ class SendingCrashReportTests: XCTestCase {
XCTAssertNotNil(log.attributes.internalAttributes?[DDError.wasTruncated])

// Then (RUMError is sent)
let rumEvent = try XCTUnwrap(core.waitAndReturnEvents(ofFeature: RUMFeature.name, ofType: RUMCrashEvent.self).first)
XCTAssertEqual(rumEvent.model.error.message, crashReport.message)
XCTAssertEqual(rumEvent.model.error.type, crashReport.type)
XCTAssertEqual(rumEvent.model.error.stack, crashReport.stack)
XCTAssertNotNil(rumEvent.additionalAttributes?[DDError.threads])
XCTAssertNotNil(rumEvent.additionalAttributes?[DDError.binaryImages])
XCTAssertNotNil(rumEvent.additionalAttributes?[DDError.meta])
XCTAssertNotNil(rumEvent.additionalAttributes?[DDError.wasTruncated])
let rumEvent = try XCTUnwrap(core.waitAndReturnEvents(ofFeature: RUMFeature.name, ofType: RUMErrorEvent.self).first)
XCTAssertEqual(rumEvent.error.message, crashReport.message)
XCTAssertEqual(rumEvent.error.type, crashReport.type)
XCTAssertEqual(rumEvent.error.stack, crashReport.stack)
XCTAssertNotNil(rumEvent.error.threads)
XCTAssertNotNil(rumEvent.error.binaryImages)
XCTAssertNotNil(rumEvent.error.meta)
XCTAssertNotNil(rumEvent.error.wasTruncated)
}

func testWhenSendingCrashReportAsLog_itIsLinkedToTheRUMSessionThatHasCrashed() throws {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,8 @@ class NetworkInstrumentationIntegrationTests: XCTestCase {
)
)
)
config.traceIDGenerator = RelativeTracingUUIDGenerator(startingFrom: 1, advancingByCount: 1)
config.traceIDGenerator = RelativeTracingUUIDGenerator(startingFrom: .init(idHi: 10, idLo: 100))
config.spanIDGenerator = RelativeSpanIDGenerator(startingFrom: 100, advancingByCount: 1)

Trace.enable(
with: config,
Expand Down Expand Up @@ -76,15 +77,15 @@ class NetworkInstrumentationIntegrationTests: XCTestCase {

let matcher1 = try XCTUnwrap(matchers.first)
try XCTAssertEqual(matcher1.operationName(), "root")
try XCTAssertEqual(matcher1.traceID(), "1")
try XCTAssertEqual(matcher1.spanID(), "2")
try XCTAssertEqual(matcher1.traceID(), .init(idHi: 10, idLo: 100))
try XCTAssertEqual(matcher1.spanID(), .init(rawValue: 100))
try XCTAssertEqual(matcher1.metrics.isRootSpan(), 1)

let matcher2 = try XCTUnwrap(matchers.last)
try XCTAssertEqual(matcher2.operationName(), "urlsession.request")
try XCTAssertEqual(matcher2.traceID(), "1")
try XCTAssertEqual(matcher2.parentSpanID(), "2")
try XCTAssertEqual(matcher2.spanID(), "3")
try XCTAssertEqual(matcher2.traceID(), .init(idHi: 10, idLo: 100))
try XCTAssertEqual(matcher2.parentSpanID(), .init(rawValue: 100))
try XCTAssertEqual(matcher2.spanID(), .init(rawValue: 101))
}

class MockDelegate: NSObject, URLSessionDataDelegate {
Expand Down
18 changes: 9 additions & 9 deletions Datadog/IntegrationUnitTests/RUM/AppHangsMonitoringTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,8 @@ class AppHangsMonitoringTests: XCTestCase {
let appHangError = try XCTUnwrap(errors.first)
let actualHangDuration = try XCTUnwrap(appHangError.freeze?.duration)

XCTAssertEqual(appHangError.error.message, AppHangsObserver.Constants.appHangErrorMessage)
XCTAssertEqual(appHangError.error.type, AppHangsObserver.Constants.appHangErrorType)
XCTAssertEqual(appHangError.error.message, AppHangsMonitor.Constants.appHangErrorMessage)
XCTAssertEqual(appHangError.error.type, AppHangsMonitor.Constants.appHangErrorType)
XCTAssertEqual(appHangError.error.category, .appHang)
XCTAssertTrue(expectedHangDurationRangeNs.contains(actualHangDuration))
}
Expand All @@ -74,8 +74,8 @@ class AppHangsMonitoringTests: XCTestCase {
let appHangError = try XCTUnwrap(errors.first)
let actualHangDuration = try XCTUnwrap(appHangError.freeze?.duration)

XCTAssertEqual(appHangError.error.message, AppHangsObserver.Constants.appHangErrorMessage)
XCTAssertEqual(appHangError.error.type, AppHangsObserver.Constants.appHangErrorType)
XCTAssertEqual(appHangError.error.message, AppHangsMonitor.Constants.appHangErrorMessage)
XCTAssertEqual(appHangError.error.type, AppHangsMonitor.Constants.appHangErrorType)
XCTAssertEqual(appHangError.error.category, .appHang)
XCTAssertTrue(expectedHangDurationRangeNs.contains(actualHangDuration))
}
Expand Down Expand Up @@ -104,8 +104,8 @@ class AppHangsMonitoringTests: XCTestCase {
let appHangError = try XCTUnwrap(errors.first)
let mainThreadStack = try XCTUnwrap(appHangError.error.stack)

XCTAssertEqual(appHangError.error.message, AppHangsObserver.Constants.appHangErrorMessage)
XCTAssertEqual(appHangError.error.type, AppHangsObserver.Constants.appHangErrorType)
XCTAssertEqual(appHangError.error.message, AppHangsMonitor.Constants.appHangErrorMessage)
XCTAssertEqual(appHangError.error.type, AppHangsMonitor.Constants.appHangErrorType)
XCTAssertTrue(mainThreadStack.contains(uiKitLibraryName), "Main thread stack should include UIKit symbols")
XCTAssertEqual(appHangError.error.source, .source)
XCTAssertNotNil(appHangError.error.threads, "Other threads should be available")
Expand All @@ -128,9 +128,9 @@ class AppHangsMonitoringTests: XCTestCase {
let errors = core.waitAndReturnEvents(ofFeature: RUMFeature.name, ofType: RUMErrorEvent.self)
let appHangError = try XCTUnwrap(errors.first)

XCTAssertEqual(appHangError.error.message, AppHangsObserver.Constants.appHangErrorMessage)
XCTAssertEqual(appHangError.error.type, AppHangsObserver.Constants.appHangErrorType)
XCTAssertEqual(appHangError.error.stack, AppHangsObserver.Constants.appHangStackNotAvailableErrorMessage)
XCTAssertEqual(appHangError.error.message, AppHangsMonitor.Constants.appHangErrorMessage)
XCTAssertEqual(appHangError.error.type, AppHangsMonitor.Constants.appHangErrorType)
XCTAssertEqual(appHangError.error.stack, AppHangsMonitor.Constants.appHangStackNotAvailableErrorMessage)
XCTAssertEqual(appHangError.error.source, .source)
XCTAssertNil(appHangError.error.threads, "Threads should be unavailable as CrashReporting was not enabled")
XCTAssertNil(appHangError.error.binaryImages, "Binary Images should be unavailable as CrashReporting was not enabled")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ class TracingWithLoggingIntegrationTests: XCTestCase {

// When
integration.writeLog(
withSpanContext: .mockWith(traceID: 1, spanID: 2),
withSpanContext: .mockWith(traceID: .init(idHi: 10, idLo: 100), spanID: 200),
fields: [
OTLogFields.message: "hello",
"custom field": 123,
Expand All @@ -56,8 +56,8 @@ class TracingWithLoggingIntegrationTests: XCTestCase {
DDAssertJSONEqual(
AnyEncodable(log.attributes.internalAttributes),
AnyEncodable([
"dd.trace_id": "1",
"dd.span_id": "2"
"dd.trace_id": "a0000000000000064",
"dd.span_id": "c8"
])
)
}
Expand Down Expand Up @@ -110,7 +110,7 @@ class TracingWithLoggingIntegrationTests: XCTestCase {

// When
integration.writeLog(
withSpanContext: .mockWith(traceID: 1, spanID: 2),
withSpanContext: .mockWith(traceID: .init(idHi: 10, idLo: 100), spanID: 200),
fields: ["custom field": 123],
date: .mockDecember15th2019At10AMUTC(),
else: {}
Expand All @@ -130,8 +130,8 @@ class TracingWithLoggingIntegrationTests: XCTestCase {
DDAssertJSONEqual(
AnyEncodable(log.attributes.internalAttributes),
AnyEncodable([
"dd.trace_id": "1",
"dd.span_id": "2"
"dd.trace_id": "a0000000000000064",
"dd.span_id": "c8"
])
)
}
Expand Down
4 changes: 2 additions & 2 deletions DatadogCore/Tests/Datadog/LoggerTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -865,11 +865,11 @@ class LoggerTests: XCTestCase {
let logMatchers = try core.waitAndReturnLogMatchers()
logMatchers[0].assertValue(
forKeyPath: "dd.trace_id",
equals: String(span.context.dd.traceID)
equals: span.context.dd.traceID.toString(representation: .hexadecimal)
)
logMatchers[0].assertValue(
forKeyPath: "dd.span_id",
equals: String(span.context.dd.spanID)
equals: span.context.dd.spanID.toString(representation: .decimal)
)
logMatchers[1].assertNoValue(forKey: "dd.trace_id")
logMatchers[1].assertNoValue(forKey: "dd.span_id")
Expand Down
15 changes: 1 addition & 14 deletions DatadogCore/Tests/Datadog/Mocks/RUMDataModelMocks.swift
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ extension RUMViewEvent: RandomMockable {
pageStates: nil,
replayStats: nil,
session: .init(
plan: [.plan1, .plan2].randomElement()!,
plan: .plan1,
sessionPrecondition: .mockRandom()
)
),
Expand Down Expand Up @@ -432,19 +432,6 @@ extension RUMErrorEvent: RandomMockable {
}
}

extension RUMCrashEvent: RandomMockable {
static func mockRandom(error: RUMErrorEvent) -> RUMCrashEvent {
return .init(
error: error,
additionalAttributes: mockRandomAttributes()
)
}

public static func mockRandom() -> RUMCrashEvent {
return mockRandom(error: .mockRandom())
}
}

extension RUMLongTaskEvent.DD.Configuration: RandomMockable {
public static func mockRandom() -> RUMLongTaskEvent.DD.Configuration {
return .init(sessionReplaySampleRate: .mockRandom(min: 0, max: 100), sessionSampleRate: .mockRandom(min: 0, max: 100))
Expand Down
14 changes: 9 additions & 5 deletions DatadogCore/Tests/Datadog/Mocks/RUMFeatureMocks.swift
Original file line number Diff line number Diff line change
Expand Up @@ -319,15 +319,15 @@ extension RUMSpanContext: AnyMockable, RandomMockable {

public static func mockRandom() -> RUMSpanContext {
return RUMSpanContext(
traceID: .mockRandom(),
spanID: .mockRandom(),
traceID: .mock(.mockRandom(), .mockRandom()),
spanID: .mock(.mockRandom()),
samplingRate: .mockRandom()
)
}

static func mockWith(
traceID: String = .mockAny(),
spanID: String = .mockAny(),
traceID: TraceID = .mockAny(),
spanID: SpanID = .mockAny(),
samplingRate: Double = .mockAny()
) -> RUMSpanContext {
return RUMSpanContext(
Expand All @@ -350,7 +350,11 @@ extension RUMStartResourceCommand: AnyMockable, RandomMockable {
httpMethod: .mockRandom(),
kind: .mockAny(),
isFirstPartyRequest: .mockRandom(),
spanContext: .init(traceID: .mockRandom(), spanID: .mockRandom(), samplingRate: .mockAny())
spanContext: .init(
traceID: .mock(.mockRandom(), .mockRandom()),
spanID: .mock(.mockRandom()),
samplingRate: .mockAny()
)
)
}

Expand Down
10 changes: 6 additions & 4 deletions DatadogCore/Tests/Datadog/Mocks/TracingFeatureMocks.swift
Original file line number Diff line number Diff line change
Expand Up @@ -84,8 +84,8 @@ extension DDSpanContext {

static func mockWith(
traceID: TraceID = .mockAny(),
spanID: TraceID = .mockAny(),
parentSpanID: TraceID? = .mockAny(),
spanID: SpanID = .mockAny(),
parentSpanID: SpanID? = .mockAny(),
baggageItems: BaggageItems = .mockAny()
) -> DDSpanContext {
return DDSpanContext(
Expand Down Expand Up @@ -114,7 +114,8 @@ extension DatadogTracer {
core: DatadogCoreProtocol,
sampler: Sampler = .mockKeepAll(),
tags: [String: Encodable] = [:],
tracingUUIDGenerator: TraceIDGenerator = DefaultTraceIDGenerator(),
traceIDGenerator: TraceIDGenerator = DefaultTraceIDGenerator(),
spanIDGenerator: SpanIDGenerator = DefaultSpanIDGenerator(),
dateProvider: DateProvider = SystemDateProvider(),
spanEventBuilder: SpanEventBuilder = .mockAny(),
loggingIntegration: TracingWithLoggingIntegration = .mockAny()
Expand All @@ -123,7 +124,8 @@ extension DatadogTracer {
core: core,
sampler: sampler,
tags: tags,
tracingUUIDGenerator: tracingUUIDGenerator,
traceIDGenerator: traceIDGenerator,
spanIDGenerator: spanIDGenerator,
dateProvider: dateProvider,
loggingIntegration: loggingIntegration,
spanEventBuilder: spanEventBuilder
Expand Down
Loading

0 comments on commit 290ed6c

Please sign in to comment.