Skip to content

Commit 60946db

Browse files
authored
Merge pull request #232 from TelemetryDeck/feature/namespace
Add namespace support (for advanced customization)
2 parents b2540c2 + 74c35e8 commit 60946db

File tree

2 files changed

+24
-6
lines changed

2 files changed

+24
-6
lines changed

Sources/TelemetryDeck/Signals/SignalManager.swift

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -224,8 +224,13 @@ private extension SignalManager {
224224
private extension SignalManager {
225225
private func send(_ signalPostBodies: [SignalPostBody], completionHandler: @escaping @Sendable (Data?, URLResponse?, Error?) -> Void) {
226226
DispatchQueue.global(qos: .utility).async {
227-
let path = "/v2/"
228-
let url = self.configuration.apiBaseURL.appendingPathComponent(path)
227+
let subpath: String
228+
if let namespace = self.configuration.namespace, !namespace.isEmpty {
229+
subpath = "/v2/namespace/\(namespace)/"
230+
} else {
231+
subpath = "/v2/"
232+
}
233+
let url = self.configuration.apiBaseURL.appendingPathComponent(subpath)
229234

230235
var urlRequest = URLRequest(url: url)
231236
urlRequest.httpMethod = "POST"

Sources/TelemetryDeck/TelemetryClient.swift

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,10 @@ public final class TelemetryManagerConfiguration: @unchecked Sendable {
2525
/// (Don't change this unless you know exactly what you're doing)
2626
public let apiBaseURL: URL
2727

28+
/// The namespace to send signals to. Defaults to the default Telemetry API server namespace.
29+
/// (Don't change this unless you know exactly what you're doing)
30+
public let namespace: String?
31+
2832
/// This string will be appended to to all user identifiers before hashing them.
2933
///
3034
/// Set the salt to a random string of 64 letters, integers and special characters to prevent the unlikely
@@ -162,15 +166,24 @@ public final class TelemetryManagerConfiguration: @unchecked Sendable {
162166
/// Defaults to an empty array.
163167
public var metadataEnrichers: [SignalEnricher] = []
164168

165-
public init(appID: String, salt: String? = nil, baseURL: URL? = nil) {
166-
telemetryAppID = appID
169+
/// Creates a new configuration for the TelemetryDeck analytics service.
170+
///
171+
/// - Parameters:
172+
/// - appID: Your application's unique identifier for TelemetryDeck
173+
/// - salt: A string used to salt user identifiers before hashing. If not provided, an empty string will be used.
174+
/// - baseURL: The base URL for the TelemetryDeck API. Defaults to the standard TelemetryDeck server if not specified.
175+
/// - namespace: An optional namespace for segregating signals. Do not specify unless you know what you're doing.
176+
public init(appID: String, salt: String? = nil, baseURL: URL? = nil, namespace: String? = nil) {
177+
self.telemetryAppID = appID
167178

168179
if let baseURL = baseURL {
169-
apiBaseURL = baseURL
180+
self.apiBaseURL = baseURL
170181
} else {
171-
apiBaseURL = URL(string: "https://nom.telemetrydeck.com")!
182+
self.apiBaseURL = URL(string: "https://nom.telemetrydeck.com")!
172183
}
173184

185+
self.namespace = namespace
186+
174187
if let salt = salt {
175188
self.salt = salt
176189
} else {

0 commit comments

Comments
 (0)