-
Notifications
You must be signed in to change notification settings - Fork 129
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #326 from DataDog/ncreated/RUMM-829-add-consent-aw…
…are-data-writer RUMM-829 Add consent-aware data writer
- Loading branch information
Showing
30 changed files
with
419 additions
and
150 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
42 changes: 42 additions & 0 deletions
42
Sources/Datadog/Core/Persistence/Privacy/ConsentAwareDataWriter.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
/* | ||
* Unless explicitly stated otherwise all files in this repository are licensed under the Apache License Version 2.0. | ||
* This product includes software developed at Datadog (https://www.datadoghq.com/). | ||
* Copyright 2019-2020 Datadog, Inc. | ||
*/ | ||
|
||
import Foundation | ||
|
||
/// File writer which writes data to different folders depending on the tracking consent value. | ||
internal class ConsentAwareDataWriter: FileWriterType { | ||
/// Queue used to synchronize reads and writes for the feature. | ||
/// TODO: RUMM-777 will be used synchronize `activeFileWriter` swaps on consent change. | ||
internal let queue: DispatchQueue | ||
/// File writer writting unauthorized data when consent is `.pending`. | ||
private let unauthorizedFileWriter: FileWriterType | ||
/// File writer writting authorized data when consent is `.granted`. | ||
private let authorizedFileWriter: FileWriterType | ||
|
||
/// File writer for current consent value (including `nil` if consent is `.notGranted`). | ||
private var activeFileWriter: FileWriterType? | ||
|
||
init( | ||
initialConsent: TrackingConsent, | ||
queue: DispatchQueue, | ||
unauthorizedFileWriter: FileWriterType, | ||
authorizedFileWriter: FileWriterType | ||
) { | ||
self.queue = queue | ||
self.unauthorizedFileWriter = unauthorizedFileWriter | ||
self.authorizedFileWriter = authorizedFileWriter | ||
|
||
switch initialConsent { | ||
case .granted: self.activeFileWriter = authorizedFileWriter | ||
case .notGranted: self.activeFileWriter = nil | ||
case .pending: self.activeFileWriter = unauthorizedFileWriter | ||
} | ||
} | ||
|
||
func write<T>(value: T) where T: Encodable { | ||
activeFileWriter?.write(value: value) | ||
} | ||
} |
21 changes: 21 additions & 0 deletions
21
Sources/Datadog/Core/Persistence/Privacy/TrackingConsent.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
/* | ||
* Unless explicitly stated otherwise all files in this repository are licensed under the Apache License Version 2.0. | ||
* This product includes software developed at Datadog (https://www.datadoghq.com/). | ||
* Copyright 2019-2020 Datadog, Inc. | ||
*/ | ||
|
||
import Foundation | ||
|
||
/// Possible values for the Data Tracking Consent. | ||
internal enum TrackingConsent { | ||
/// The permission to persist and send data to the Datadog servers was granted. | ||
/// Any previously stored pending data will be marked as ready for sent. | ||
case granted | ||
/// Any previously stored pending data will be deleted and all Logging, RUM and Tracing events will | ||
/// be dropped from now on, without persisting it in any way. | ||
case notGranted | ||
/// All Logging, RUM and Tracing events will be persisted in an intermediate location and will be pending there | ||
/// until `.granted` or `.notGranted` consent value is set. | ||
/// Based on the next consent value, intermediate data will be send to Datadog or deleted. | ||
case pending | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.