Skip to content

Commit

Permalink
Merge pull request #232 from TelemetryDeck/feature/namespace
Browse files Browse the repository at this point in the history
Add namespace support (for advanced customization)
  • Loading branch information
Jeehut authored Feb 17, 2025
2 parents b2540c2 + 74c35e8 commit 60946db
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 6 deletions.
9 changes: 7 additions & 2 deletions Sources/TelemetryDeck/Signals/SignalManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -224,8 +224,13 @@ private extension SignalManager {
private extension SignalManager {
private func send(_ signalPostBodies: [SignalPostBody], completionHandler: @escaping @Sendable (Data?, URLResponse?, Error?) -> Void) {
DispatchQueue.global(qos: .utility).async {
let path = "/v2/"
let url = self.configuration.apiBaseURL.appendingPathComponent(path)
let subpath: String
if let namespace = self.configuration.namespace, !namespace.isEmpty {
subpath = "/v2/namespace/\(namespace)/"
} else {
subpath = "/v2/"
}
let url = self.configuration.apiBaseURL.appendingPathComponent(subpath)

var urlRequest = URLRequest(url: url)
urlRequest.httpMethod = "POST"
Expand Down
21 changes: 17 additions & 4 deletions Sources/TelemetryDeck/TelemetryClient.swift
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,10 @@ public final class TelemetryManagerConfiguration: @unchecked Sendable {
/// (Don't change this unless you know exactly what you're doing)
public let apiBaseURL: URL

/// The namespace to send signals to. Defaults to the default Telemetry API server namespace.
/// (Don't change this unless you know exactly what you're doing)
public let namespace: String?

/// This string will be appended to to all user identifiers before hashing them.
///
/// Set the salt to a random string of 64 letters, integers and special characters to prevent the unlikely
Expand Down Expand Up @@ -162,15 +166,24 @@ public final class TelemetryManagerConfiguration: @unchecked Sendable {
/// Defaults to an empty array.
public var metadataEnrichers: [SignalEnricher] = []

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

if let baseURL = baseURL {
apiBaseURL = baseURL
self.apiBaseURL = baseURL
} else {
apiBaseURL = URL(string: "https://nom.telemetrydeck.com")!
self.apiBaseURL = URL(string: "https://nom.telemetrydeck.com")!
}

self.namespace = namespace

if let salt = salt {
self.salt = salt
} else {
Expand Down

0 comments on commit 60946db

Please sign in to comment.