-
Notifications
You must be signed in to change notification settings - Fork 134
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
RUM-1053 Make Logger Sendable for Swift 6 concurrency #2035
RUM-1053 Make Logger Sendable for Swift 6 concurrency #2035
Conversation
and replace it with concurrency-safe `FeatureScope`
614a84c
to
87c4a0a
Compare
Datadog ReportBranch report: ✅ 0 Failed, 1880 Passed, 0 Skipped, 1m 16.57s Total Time 🔻 Code Coverage Decreases vs Default Branch (2) |
87c4a0a
to
a3d8423
Compare
DatadogLogs
public API concurrency-safe} else { | ||
let iso8601Formatter = DateFormatter() | ||
iso8601Formatter.locale = Locale(identifier: "en_US_POSIX") | ||
iso8601Formatter.timeZone = TimeZone(abbreviation: "UTC")! // swiftlint:disable:this force_unwrapping | ||
iso8601Formatter.calendar = Calendar(identifier: .gregorian) | ||
iso8601Formatter.dateFormat = "yyyy-MM-dd'T'HH:mm:ss.SSS'Z'" // ISO8601 format | ||
return iso8601Formatter | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
💡 not needed anymore after we dropped iOS 11
/// need to be safely managed across multiple threads or tasks. | ||
internal final class SynchronizedAttributes: Sendable { | ||
/// The underlying dictionary of attributes, wrapped in a `ReadWriteLock` to ensure thread safety. | ||
private let attributes: ReadWriteLock<[String: Encodable]> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
/question We are not using the ReadWriteLock
as a property wrapper in multiple places, is it because it would require it to be a var
? Can't this be solved by making ReadWriteLock
Sendable?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The ReadWriteLock
is Sendable
already - it was done in this PR. And yes, if using property wrapper, this will become var
, raising concurrency issue. I agree with what was discussed here - property wrappers become quite unusable with strict concurrency.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, makes sense 👍
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM 👍
What and why?
📦 This PR prepares DatadogLogs for compatibility with apps that enable "complete" concurrency checking in Swift 6.
I identified a potential data-race safety issue when passing instances of LoggerProtocol across isolation boundaries, such as to different threads:
How?
This issue is resolved by declaring Sendable conformance for
LoggerProtocol
:Since Xcode 15 uses
SWIFT_STRICT_CONCURRENCY: minimal
, which checks only explicitSendable
conformances, this:resulted in concurrency warnings elsewhere.
Instead of using
@unchecked Sendable
forRemoteLogger
,ConsoleLogger
, and some test types, I chose to address concurrency warnings properly, makingRemoteLogger
andConsoleLogger
fully checked Sendable types 👌.This required several major changes:
FeatureScope
always available #1744 and replaced the mutablecore
reference inRemoteLogger
with an immutable reference toFeatureScope
.FeatureScope
sendable, to facilitate similar work in other modules.RemoteLogger
after removing thecore
reference.SynchronizedAttributes
andSynchronizedTags
to ensureRemoteLogger
has onlySendable
members.Smaller adjustments were made as a consequence of spreading
Sendable
conformance. For example, markingBacktraceReporter
asSendable
required resolving issues in Crash Reporting tests, as this type is shared throughDatadogInternal
.Review checklist