mirror of
https://github.com/Novaloop-AG/element-x-ios.git
synced 2026-11-04 01:20:12 +00:00
Feature flag to OTLP tracing
This commit is contained in:
committed by
Stefan Ceriu
parent
63d90eeb3e
commit
ecc549b280
@@ -58,7 +58,14 @@ class AppCoordinator: AppCoordinatorProtocol, AuthenticationCoordinatorDelegate,
|
||||
|
||||
init() {
|
||||
let appSettings = AppSettings()
|
||||
MXLog.configure(logLevel: appSettings.logLevel)
|
||||
|
||||
if appSettings.otlpTracingEnabled {
|
||||
MXLog.configure(logLevel: appSettings.logLevel, otlpConfiguration: .init(url: appSettings.otlpTracingURL,
|
||||
username: appSettings.otlpTracingUsername,
|
||||
password: appSettings.otlpTracingPassword))
|
||||
} else {
|
||||
MXLog.configure(logLevel: appSettings.logLevel)
|
||||
}
|
||||
|
||||
if ProcessInfo.processInfo.environment["RESET_APP_SETTINGS"].map(Bool.init) == true {
|
||||
AppSettings.reset()
|
||||
|
||||
@@ -30,6 +30,7 @@ final class AppSettings {
|
||||
case enableInAppNotifications
|
||||
case pusherProfileTag
|
||||
case logLevel
|
||||
case otlpTracingEnabled
|
||||
|
||||
// Feature flags
|
||||
case shouldCollapseRoomStateEvents
|
||||
@@ -197,9 +198,18 @@ final class AppSettings {
|
||||
|
||||
let permalinkBaseURL: URL = "https://matrix.to"
|
||||
|
||||
// MARK: - Logging
|
||||
|
||||
@UserPreference(key: UserDefaultsKeys.logLevel, defaultValue: TracingConfiguration.LogLevel.info, storageType: .userDefaults(store))
|
||||
var logLevel
|
||||
|
||||
@UserPreference(key: UserDefaultsKeys.otlpTracingEnabled, defaultValue: false, storageType: .userDefaults(store))
|
||||
var otlpTracingEnabled
|
||||
|
||||
let otlpTracingURL = InfoPlistReader.main.otlpTracingURL
|
||||
let otlpTracingUsername = InfoPlistReader.main.otlpTracingUsername
|
||||
let otlpTracingPassword = InfoPlistReader.main.otlpTracingPassword
|
||||
|
||||
// MARK: - Maps
|
||||
|
||||
// maptiler base url
|
||||
|
||||
@@ -27,6 +27,10 @@ struct InfoPlistReader {
|
||||
static let utExportedTypeDeclarationsKey = "UTExportedTypeDeclarations"
|
||||
static let utTypeIdentifierKey = "UTTypeIdentifier"
|
||||
static let utDescriptionKey = "UTTypeDescription"
|
||||
|
||||
static let otlpTracingURL = "otlpTracingURL"
|
||||
static let otlpTracingUsername = "otlpTracingUsername"
|
||||
static let otlpTracingPassword = "otlpTracingPassword"
|
||||
}
|
||||
|
||||
private enum Values {
|
||||
@@ -87,10 +91,27 @@ struct InfoPlistReader {
|
||||
infoPlistValue(forKey: Keys.bundleDisplayName)
|
||||
}
|
||||
|
||||
/// Map Libre API Key
|
||||
// MARK: - MapLibre
|
||||
|
||||
var mapLibreAPIKey: String {
|
||||
infoPlistValue(forKey: Keys.mapLibreAPIKey)
|
||||
}
|
||||
|
||||
// MARK: - OTLP Tracing
|
||||
|
||||
var otlpTracingURL: String {
|
||||
infoPlistValue(forKey: Keys.otlpTracingURL)
|
||||
}
|
||||
|
||||
var otlpTracingUsername: String {
|
||||
infoPlistValue(forKey: Keys.otlpTracingUsername)
|
||||
}
|
||||
|
||||
var otlpTracingPassword: String {
|
||||
infoPlistValue(forKey: Keys.otlpTracingPassword)
|
||||
}
|
||||
|
||||
// MARK: - Mention Pills
|
||||
|
||||
/// Mention Pills UTType
|
||||
var pillsUTType: String {
|
||||
@@ -101,6 +122,8 @@ struct InfoPlistReader {
|
||||
}
|
||||
return utType
|
||||
}
|
||||
|
||||
// MARK: - Private
|
||||
|
||||
private func infoPlistValue<T>(forKey key: String) -> T {
|
||||
guard let result = bundle.object(forInfoDictionaryKey: key) as? T else {
|
||||
|
||||
@@ -43,6 +43,7 @@ enum MXLog {
|
||||
|
||||
static func configure(target: String? = nil,
|
||||
logLevel: TracingConfiguration.LogLevel,
|
||||
otlpConfiguration: OTLPConfiguration? = nil,
|
||||
redirectToFiles: Bool = Constants.redirectToFiles,
|
||||
maxLogFileCount: UInt = Constants.maxLogFileCount,
|
||||
logFileSizeLimit: UInt = Constants.logFilesSizeLimit) {
|
||||
@@ -58,7 +59,7 @@ enum MXLog {
|
||||
return
|
||||
}
|
||||
|
||||
setupTracing(configuration: .custom(logLevel: logLevel))
|
||||
setupTracing(configuration: .custom(logLevel: logLevel), otlpConfiguration: otlpConfiguration)
|
||||
|
||||
if let target {
|
||||
self.target = target
|
||||
|
||||
@@ -17,6 +17,12 @@
|
||||
import Collections
|
||||
import MatrixRustSDK
|
||||
|
||||
struct OTLPConfiguration {
|
||||
let url: String
|
||||
let username: String
|
||||
let password: String
|
||||
}
|
||||
|
||||
// This exposes the full Rust side tracing subscriber filter for more flexibility.
|
||||
// We can filter by level, crate and even file. See more details here:
|
||||
// https://docs.rs/tracing-subscriber/0.2.7/tracing_subscriber/filter/struct.EnvFilter.html#examples
|
||||
@@ -83,6 +89,18 @@ struct TracingConfiguration {
|
||||
}
|
||||
}
|
||||
|
||||
func setupTracing(configuration: TracingConfiguration) {
|
||||
setupTracing(config: .init(filter: configuration.filter, writeToStdoutOrSystem: true, writeToFiles: nil))
|
||||
func setupTracing(configuration: TracingConfiguration, otlpConfiguration: OTLPConfiguration?) {
|
||||
if let otlpConfiguration {
|
||||
setupOtlpTracing(config: .init(clientName: "ElementX-iOS",
|
||||
user: otlpConfiguration.username,
|
||||
password: otlpConfiguration.password,
|
||||
otlpEndpoint: otlpConfiguration.url,
|
||||
filter: configuration.filter,
|
||||
writeToStdoutOrSystem: true,
|
||||
writeToFiles: nil))
|
||||
} else {
|
||||
setupTracing(config: .init(filter: configuration.filter,
|
||||
writeToStdoutOrSystem: true,
|
||||
writeToFiles: nil))
|
||||
}
|
||||
}
|
||||
|
||||
+1
@@ -44,6 +44,7 @@ enum DeveloperOptionsScreenViewAction {
|
||||
|
||||
protocol DeveloperOptionsProtocol: AnyObject {
|
||||
var logLevel: TracingConfiguration.LogLevel { get set }
|
||||
var otlpTracingEnabled: Bool { get set }
|
||||
var shouldCollapseRoomStateEvents: Bool { get set }
|
||||
var userSuggestionsEnabled: Bool { get set }
|
||||
var readReceiptsEnabled: Bool { get set }
|
||||
|
||||
+13
-6
@@ -22,13 +22,20 @@ struct DeveloperOptionsScreen: View {
|
||||
|
||||
var body: some View {
|
||||
Form {
|
||||
Picker(selection: $context.logLevel) {
|
||||
ForEach(TracingConfiguration.LogLevel.allCases, id: \.self) { logLevel in
|
||||
Text(logLevel.rawValue.capitalized)
|
||||
Section("Logging") {
|
||||
Picker(selection: $context.logLevel) {
|
||||
ForEach(TracingConfiguration.LogLevel.allCases, id: \.self) { logLevel in
|
||||
Text(logLevel.rawValue.capitalized)
|
||||
}
|
||||
} label: {
|
||||
Text("Log level")
|
||||
Text("Requires app reboot")
|
||||
}
|
||||
|
||||
Toggle(isOn: $context.otlpTracingEnabled) {
|
||||
Text("OTLP tracing")
|
||||
Text("Requires app reboot")
|
||||
}
|
||||
} label: {
|
||||
Text("Log level")
|
||||
Text("Requires app reboot")
|
||||
}
|
||||
|
||||
Section("Timeline") {
|
||||
|
||||
Reference in New Issue
Block a user