Skip to content
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

fix: Datadog integration leads to build failures - WPB-11936 #2153

Open
wants to merge 19 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 25 additions & 13 deletions WireAnalytics/Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@
import Foundation
import PackageDescription

// You can enable/disable Datadog for debugging by overriding the boolean.
let datadogEnabled = hasEnvironmentVariable("ENABLE_DATADOG", "true")

let package = Package(
name: "WireAnalytics",
platforms: [.iOS(.v16), .macOS(.v12)],
Expand All @@ -19,20 +22,16 @@ let package = Package(
targets: [
.target(
name: "WireAnalytics",
dependencies: resolveWireAnalyticsDependencies() + [
dependencies: [
.product(name: "Countly", package: "countly-sdk-ios")
],
swiftSettings: swiftSettings
),
.target(
name: "WireDatadog",
dependencies: [
.product(name: "DatadogCore", package: "dd-sdk-ios"),
.product(name: "DatadogCrashReporting", package: "dd-sdk-ios"),
.product(name: "DatadogLogs", package: "dd-sdk-ios"),
.product(name: "DatadogRUM", package: "dd-sdk-ios"),
.product(name: "DatadogTrace", package: "dd-sdk-ios")
],
dependencies: datadogDependencies(),
path: "Sources/WireDatadog",
Copy link
Contributor

@samwyndham samwyndham Nov 15, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Did you consider making the path change instead of the source files? It might be easier to maintain 🤔

As a side note, if we take the file route perhaps this line is not necessary as I guess that is the default path

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

from the doc it was saying here lies the directory and on the other one just filenames. I didn't play with this

sources: datadogFiles(),
swiftSettings: swiftSettings
),
.target(
Expand All @@ -49,12 +48,25 @@ let package = Package(
]
)

func resolveWireAnalyticsDependencies() -> [Target.Dependency] {
// You can enable/disable Datadog for debugging by overriding the boolean.
if hasEnvironmentVariable("ENABLE_DATADOG", "true") {
["WireDatadog"]
func datadogDependencies() -> [Target.Dependency] {
guard datadogEnabled else {
// note: in this case SPM will warn that the dd-sdk-ios is not used
return []
}
return [
.product(name: "DatadogCore", package: "dd-sdk-ios"),
.product(name: "DatadogCrashReporting", package: "dd-sdk-ios"),
.product(name: "DatadogLogs", package: "dd-sdk-ios"),
.product(name: "DatadogRUM", package: "dd-sdk-ios"),
.product(name: "DatadogTrace", package: "dd-sdk-ios")
]
}

func datadogFiles() -> [String] {
if datadogEnabled {
["WireDatadog.swift", "LogLevel.swift"]
} else {
[]
["WireFakeDatadog.swift", "LogLevel.swift"]
}
}

Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,13 @@
// along with this program. If not, see http://www.gnu.org/licenses/.
//

public protocol WireDatadogProtocol {

/// Unique obfuscated identifier of the current device across app and extensions.
var userIdentifier: String { get }

func enable()
public extension WireDatadog {
enum LogLevel: String, Codable {
case debug
case info
case notice
case warn
case error
case critical
}
}
39 changes: 33 additions & 6 deletions WireAnalytics/Sources/WireDatadog/WireDatadog.swift
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,10 @@ public final class WireDatadog {
private let applicationID: String
private let buildVersion: String
private let buildNumber: String
private let logLevel: LogLevel = .debug
private let logLevel: WireDatadog.LogLevel = .debug

public private(set) var userIdentifier: String
public private(set) var logger: (any DatadogLogs.LoggerProtocol)?
private(set) var logger: (any DatadogLogs.LoggerProtocol)?

public init(
applicationID: String,
Expand Down Expand Up @@ -72,7 +72,7 @@ public final class WireDatadog {
let loggerConfiguration = Logger.Configuration(
name: "iOS Wire App",
networkInfoEnabled: true,
remoteLogThreshold: logLevel
remoteLogThreshold: logLevel.datadogLevel
)
logger = Logger.create(with: loggerConfiguration)
}
Expand All @@ -96,15 +96,15 @@ public final class WireDatadog {
Datadog.setUserInfo(id: userIdentifier)

logger?.log(
level: logLevel,
level: logLevel.datadogLevel,
message: "Datadog startMonitoring for device: \(userIdentifier)",
error: nil,
attributes: nil
)
}

public func log(
level: LogLevel,
level: WireDatadog.LogLevel,
message: String,
error: (any Error)? = nil,
attributes: [String: any Encodable]
Expand All @@ -114,13 +114,21 @@ public final class WireDatadog {
finalAttributes["version"] = buildVersion

logger?.log(
level: level,
level: level.datadogLevel, // TODO: [WPB-11881] review this when WireLogger is available as package
message: message,
error: error,
attributes: finalAttributes
)
}

public func addAttribute(forKey key: String, value: String) {
logger?.addTag(withKey: key, value: value)
}

public func removeAttribute(forKey key: String) {
logger?.removeAttribute(forKey: key)
}

// MARK: Static Helpers

private static func hashedDatadogUserIdentifier(_ uuid: UUID) -> String {
Expand All @@ -139,3 +147,22 @@ public final class WireDatadog {
)
}
}

extension WireDatadog.LogLevel {
var datadogLevel: LogLevel {
switch self {
case .debug:
.debug
case .info:
.info
case .notice:
.notice
case .warn:
.warn
case .error:
.error
case .critical:
.critical
}
}
}
58 changes: 58 additions & 0 deletions WireAnalytics/Sources/WireDatadog/WireFakeDatadog.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
//
// Wire
// Copyright (C) 2024 Wire Swiss GmbH
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see http://www.gnu.org/licenses/.
//

import UIKit

public final class WireDatadog {

public var userIdentifier: String {
""
}

public init(
applicationID: String,
buildVersion: String,
buildNumber: String,
clientToken: String,
identifierForVendor: UUID?,
environmentName: String
) {
// do nothing
}

public func enable() {
// do nothing
}

public func log(
level: WireDatadog.LogLevel,
message: String,
error: (any Error)? = nil,
attributes: [String: any Encodable]
) {
// do nothing
}

public func addAttribute(forKey key: String, value: String) {
// do nothing
}

public func removeAttribute(forKey key: String) {
// do nothing
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@

import WireAnalytics

/// sourcery: AutoMockable
public protocol SubmitCallQualitySurveyUseCaseProtocol {

func invoke(_ review: CallQualitySurveyReview)
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions wire-ios-sync-engine/Tests/TestsPlans/AllTests.xctestplan
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
}
],
"defaultOptions" : {
"codeCoverage" : false,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Did you confirm that this was necessary?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not completely sure, but I think it does not hurt to keep it disabled for now since we don't collect code coverage for now

"commandLineArgumentEntries" : [
{
"argument" : "-XCTestObserverClass InfiniteLoopAfterRunningTests",
Expand Down
13 changes: 1 addition & 12 deletions wire-ios-sync-engine/Tests/TestsPlans/SecurityTests.xctestplan
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
}
],
"defaultOptions" : {
"codeCoverage" : false,
"commandLineArgumentEntries" : [
{
"argument" : "-com.apple.CoreData.ConcurrencyDebug 1",
Expand All @@ -18,18 +19,6 @@
"testTimeoutsEnabled" : true
},
"testTargets" : [
{
"selectedTests" : [
"SessionManagerTests_EncryptionAtRestIsEnabledByDefault_Option\/testThatEncryptionAtRestIsEnabled_OnActiveUserSession()",
"SessionManagerTests_EncryptionAtRestMigration\/testThatDatabaseIsMigrated_WhenEncryptionAtRestIsDisabled()",
"SessionManagerTests_EncryptionAtRestMigration\/testThatDatabaseIsMigrated_WhenEncryptionAtRestIsEnabled()"
],
"target" : {
"containerPath" : "container:WireSyncEngine.xcodeproj",
"identifier" : "169BA1D125ECDBA300374343",
"name" : "IntegrationTests"
}
},
{
"selectedTests" : [
"ZMUserSessionTests_EncryptionAtRest\/testThatDatabaseIsLocked_AfterEnteringBackground()",
Expand Down
Loading
Loading