Skip to content

Commit

Permalink
feat: Add application version to HeaderEvent
Browse files Browse the repository at this point in the history
The Trap version constant was also renamed from App.version to
Trap.version to distinguish the two.
  • Loading branch information
Denes committed Jun 11, 2024
1 parent 0c14f27 commit 2526763
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 3 deletions.
2 changes: 1 addition & 1 deletion Sources/Trap/Constants.swift
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
struct Constants {
struct App {
struct Trap {
static let version = "1.1.4"
}
}
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 2526763

Please sign in to comment.