Skip to content
This repository has been archived by the owner on Aug 11, 2024. It is now read-only.

Integrate NoosphereService with Sentry logging #922

Merged
merged 3 commits into from
Oct 3, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion xcode/Subconscious/Shared/Components/AppView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -2554,12 +2554,15 @@ struct AppEnvironment {
)
let defaultGateway = GatewayURL(AppDefaults.standard.gatewayURL)
let defaultSphereIdentity = AppDefaults.standard.sphereIdentity

let sentry = SentryIntegration()

let noosphere = NoosphereService(
globalStorageURL: globalStorageURL,
sphereStorageURL: sphereStorageURL,
gatewayURL: defaultGateway,
sphereIdentity: defaultSphereIdentity
sphereIdentity: defaultSphereIdentity,
errorLoggingService: sentry
)
self.noosphere = noosphere

Expand Down
25 changes: 25 additions & 0 deletions xcode/Subconscious/Shared/Library/Sentry.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,33 @@ import os
import OSLog
import Sentry

// Create a generic protocol for an error-capturing service.
// We can use this instead of referencing the Sentry SDK directly.
protocol ErrorLoggingServiceProtocol {
func capture(error: Error)
}

extension ErrorLoggingServiceProtocol {
/// Run an async throwing closure, logging any errors as a side-effect
/// before re-throwing.
func capturing<T>(_ perform: () async throws -> T) async throws -> T {
do {
return try await perform()
} catch {
capture(error: error)
throw error
}
}
}

struct SentryIntegration {}

extension SentryIntegration: ErrorLoggingServiceProtocol {
func capture(error: Error) {
SentrySDK.capture(error: error)
}
}

extension SentryIntegration {
public static func start() {
// If we're in test mode we skip sentry initialization altogether
Expand Down
Loading