Add Sentry breadcrumb for instance software/version

This commit is contained in:
Shadowfacts 2022-12-04 18:26:06 -05:00
parent 5f3d9da9f8
commit 581f4b24bd
1 changed files with 19 additions and 0 deletions

View File

@ -8,6 +8,7 @@
import Foundation import Foundation
import Pachyderm import Pachyderm
import Sentry
struct InstanceFeatures { struct InstanceFeatures {
private static let pleromaVersionRegex = try! NSRegularExpression(pattern: "\\(compatible; pleroma (.*)\\)", options: .caseInsensitive) private static let pleromaVersionRegex = try! NSRegularExpression(pattern: "\\(compatible; pleroma (.*)\\)", options: .caseInsensitive)
@ -136,6 +137,8 @@ struct InstanceFeatures {
} }
maxStatusChars = instance.maxStatusCharacters ?? 500 maxStatusChars = instance.maxStatusCharacters ?? 500
setInstanceBreadcrumb(instance: instance, nodeInfo: nodeInfo)
} }
func hasMastodonVersion(_ major: Int, _ minor: Int, _ patch: Int) -> Bool { func hasMastodonVersion(_ major: Int, _ minor: Int, _ patch: Int) -> Bool {
@ -244,3 +247,19 @@ extension InstanceFeatures {
} }
} }
} }
private func setInstanceBreadcrumb(instance: Instance, nodeInfo: NodeInfo?) {
let crumb = Breadcrumb(level: .info, category: "MastodonController")
crumb.data = [
"instance": [
"version": instance.version
],
]
if let nodeInfo {
crumb.data!["nodeInfo"] = [
"version": nodeInfo.version,
"software": nodeInfo.software,
]
}
SentrySDK.addBreadcrumb(crumb: crumb)
}