Skip to content

Commit

Permalink
RUM-1053 Fix lint; update concurrency in implicit types
Browse files Browse the repository at this point in the history
  • Loading branch information
ncreated committed Sep 4, 2024
1 parent c8c1e79 commit 614a84c
Show file tree
Hide file tree
Showing 6 changed files with 19 additions and 16 deletions.
4 changes: 2 additions & 2 deletions DatadogCore/Tests/Datadog/LoggerTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand All @@ -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)
}
Expand Down
4 changes: 2 additions & 2 deletions DatadogCrashReporting/Tests/CrashReportingPluginTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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) } }
Expand Down Expand Up @@ -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) } }
Expand Down
4 changes: 3 additions & 1 deletion DatadogInternal/Sources/DD.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
3 changes: 1 addition & 2 deletions DatadogLogs/Sources/Log/SynchronizedAttributes.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}

Expand All @@ -45,4 +45,3 @@ internal final class SynchronizedAttributes: Sendable {
return attributes.wrappedValue
}
}

8 changes: 5 additions & 3 deletions DatadogLogs/Sources/RemoteLogger.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down Expand Up @@ -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] = [:]

Expand Down
12 changes: 6 additions & 6 deletions DatadogLogs/Tests/RemoteLoggerTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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")

Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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")
Expand Down Expand Up @@ -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)
])
Expand Down Expand Up @@ -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")
Expand Down

0 comments on commit 614a84c

Please sign in to comment.