diff --git a/DatadogCore/Tests/Datadog/LoggerTests.swift b/DatadogCore/Tests/Datadog/LoggerTests.swift index 2e0caaf7eb..87b7858556 100644 --- a/DatadogCore/Tests/Datadog/LoggerTests.swift +++ b/DatadogCore/Tests/Datadog/LoggerTests.swift @@ -986,7 +986,7 @@ class LoggerTests: XCTestCase { ) XCTAssertEqual( dd.logger.criticalLog?.error?.message, - "🔥 Datadog SDK usage error: `Datadog.initialize()` must be called prior to `Logger.builder.build()`." + "🔥 Datadog SDK usage error: `Datadog.initialize()` must be called prior to `Logger.create()`." ) XCTAssertTrue(logger is NOPLogger) } @@ -1009,7 +1009,7 @@ class LoggerTests: XCTestCase { ) XCTAssertEqual( dd.logger.criticalLog?.error?.message, - "🔥 Datadog SDK usage error: `Logger.builder.build()` produces a non-functional logger, as the logging feature is disabled." + "🔥 Datadog SDK usage error: `Logger.create()` produces a non-functional logger because the `Logs` feature was not enabled." ) XCTAssertTrue(logger is NOPLogger) } diff --git a/DatadogCrashReporting/Tests/CrashReportingPluginTests.swift b/DatadogCrashReporting/Tests/CrashReportingPluginTests.swift index 0ab2e26187..e4a892c715 100644 --- a/DatadogCrashReporting/Tests/CrashReportingPluginTests.swift +++ b/DatadogCrashReporting/Tests/CrashReportingPluginTests.swift @@ -102,7 +102,7 @@ class CrashReportingPluginTests: XCTestCase { func testGivenPendingCrashReport_whenItsLoadingFails_itPrintsError() throws { let expectation = self.expectation(description: "No Crash Report was delivered to the caller.") - var errorPrinted: String? + nonisolated(unsafe) var errorPrinted: String? consolePrint = { message, _ in errorPrinted = message } defer { consolePrint = { message, _ in print(message) } } @@ -132,7 +132,7 @@ class CrashReportingPluginTests: XCTestCase { } func testWhenCrashReporterCannotBeEnabled_itPrintsError() { - var errorPrinted: String? + nonisolated(unsafe) var errorPrinted: String? consolePrint = { message, _ in errorPrinted = message } defer { consolePrint = { message, _ in print(message) } } diff --git a/DatadogInternal/Sources/DD.swift b/DatadogInternal/Sources/DD.swift index 67262e3f4f..bf25428b18 100644 --- a/DatadogInternal/Sources/DD.swift +++ b/DatadogInternal/Sources/DD.swift @@ -30,7 +30,9 @@ import OSLog #endif /// Function printing `String` content to console. -public var consolePrint: @Sendable (String, CoreLoggerLevel) -> Void = { message, level in +/// +/// This value is only ever mutated in tests which ensure its thread-safety through other means. +nonisolated(unsafe) public var consolePrint: @Sendable (String, CoreLoggerLevel) -> Void = { message, level in #if canImport(OSLog) if #available(iOS 14.0, tvOS 14.0, *) { switch level { diff --git a/DatadogLogs/Sources/Log/SynchronizedAttributes.swift b/DatadogLogs/Sources/Log/SynchronizedAttributes.swift index 7cfd7539f6..d0270ed7cd 100644 --- a/DatadogLogs/Sources/Log/SynchronizedAttributes.swift +++ b/DatadogLogs/Sources/Log/SynchronizedAttributes.swift @@ -18,7 +18,7 @@ internal final class SynchronizedAttributes: Sendable { /// Initializes a new instance of `SynchronizedAttributes` with the provided dictionary. /// /// - Parameter attributes: A dictionary of initial attributes. - init(attributes: [String : Encodable]) { + init(attributes: [String: Encodable]) { self.attributes = .init(wrappedValue: attributes) } @@ -45,4 +45,3 @@ internal final class SynchronizedAttributes: Sendable { return attributes.wrappedValue } } - diff --git a/DatadogLogs/Sources/RemoteLogger.swift b/DatadogLogs/Sources/RemoteLogger.swift index 0b94c4d1c7..308f9a1077 100644 --- a/DatadogLogs/Sources/RemoteLogger.swift +++ b/DatadogLogs/Sources/RemoteLogger.swift @@ -68,10 +68,10 @@ internal final class RemoteLogger: LoggerProtocol, Sendable { // MARK: - Attributes - func addAttribute(forKey key: AttributeKey, value: AttributeValue) { + func addAttribute(forKey key: AttributeKey, value: AttributeValue) { loggerAttributes.addAttribute(key: key, value: value) } - + func removeAttribute(forKey key: AttributeKey) { loggerAttributes.removeAttribute(forKey: key) } @@ -130,7 +130,9 @@ internal final class RemoteLogger: LoggerProtocol, Sendable { // SDK context must be requested on the user thread to ensure that it provides values // that are up-to-date for the caller. featureScope.eventWriteContext { [weak self] context, writer in - guard let self else { return } + guard let self else { + return + } var internalAttributes: [String: Encodable] = [:] diff --git a/DatadogLogs/Tests/RemoteLoggerTests.swift b/DatadogLogs/Tests/RemoteLoggerTests.swift index 6216349e92..6b98bfd8c3 100644 --- a/DatadogLogs/Tests/RemoteLoggerTests.swift +++ b/DatadogLogs/Tests/RemoteLoggerTests.swift @@ -203,10 +203,10 @@ class RemoteLoggerTests: XCTestCase { logger.addAttribute(forKey: "attribute-1", value: "value A") logger.info("INFO message") - + logger.addAttribute(forKey: "attribute-2", value: "value B") logger.info("INFO message") - + logger.removeAttribute(forKey: "attribute-1") logger.info("INFO message") @@ -447,7 +447,7 @@ class RemoteLoggerTests: XCTestCase { // When featureScope.contextMock = .mockWith( baggages: [ - "rum" : .init([ + "rum": .init([ "application.id": applicationID, "session.id": sessionID, "view.id": viewID, @@ -511,7 +511,7 @@ class RemoteLoggerTests: XCTestCase { // When featureScope.contextMock = .mockWith( baggages: [ - "rum" : .init("malformed RUM context") + "rum": .init("malformed RUM context") ] ) logger.info("message") @@ -550,7 +550,7 @@ class RemoteLoggerTests: XCTestCase { // When featureScope.contextMock = .mockWith( baggages: [ - "span_context" : .init([ + "span_context": .init([ "dd.trace_id": traceID.toString(representation: .hexadecimal), "dd.span_id": spanID.toString(representation: .decimal) ]) @@ -607,7 +607,7 @@ class RemoteLoggerTests: XCTestCase { // When featureScope.contextMock = .mockWith( baggages: [ - "span_context" : .init("malformed Span context") + "span_context": .init("malformed Span context") ] ) logger.info("message")