Skip to content

Commit

Permalink
Merge pull request #18 from cursorinsight/denes-app-version
Browse files Browse the repository at this point in the history
feat: Add application version to HeaderEvent
  • Loading branch information
denessapi authored Jun 12, 2024
2 parents 0c14f27 + bdd4b3b commit 971f414
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 4 deletions.
4 changes: 2 additions & 2 deletions Sources/Trap/Constants.swift
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
struct Constants {
struct App {
static let version = "1.1.4"
struct Trap {
static let version = "1.1.5"
}
}
21 changes: 19 additions & 2 deletions Sources/Trap/Manager/Reporter.swift
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@ class TrapReporter {
/// The endpoint of the reporter to use
private let config: TrapConfig

/// Application version (for the embedding application)
private let appVersion: String

/// The streamId of this continuous data stream.
private var streamId = UUID()

Expand All @@ -42,6 +45,7 @@ class TrapReporter {
self.storage = storage
self.config = config
self.transport = nil
self.appVersion = Bundle.main.appVersion
}

deinit {
Expand Down Expand Up @@ -92,7 +96,7 @@ class TrapReporter {
}
let group = DispatchGroup()
group.enter()

let data = this.storage
.sorted { $0.0 < $1.0 }
.map(\.1)
Expand Down Expand Up @@ -140,11 +144,24 @@ class TrapReporter {
DataType.string(streamId.uuidString),
DataType.int(sequenceId),
DataType.dict(["version": DataType.string("20230706T094422Z")]),
DataType.string(Constants.App.version)
DataType.string(Constants.Trap.version),
DataType.string(appVersion)
])

sequenceId += 1

return header
}
}

extension Bundle {
/// Gets the application version
var appVersion: String {
if let infoDictionary = Bundle.main.infoDictionary,
let name = infoDictionary["CFBundleName"],
let version = infoDictionary["CFBundleVersion"] {
return "\(name) (\(version))"
}
return "Unknown"
}
}

0 comments on commit 971f414

Please sign in to comment.