Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
7 changes: 2 additions & 5 deletions .github/workflows/build-ios-release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -62,11 +62,8 @@ jobs:
env:
SENTRY_AUTH_TOKEN: ${{ secrets.SENTRY_AUTH_TOKEN }}
run: |
if [[ -n "$SENTRY_AUTH_TOKEN" ]]; then
brew install sentry-cli
else
echo "::warning::SENTRY_AUTH_TOKEN is missing. The iOS dSYMs will stay in the local archive."
fi
: "${SENTRY_AUTH_TOKEN:?SENTRY_AUTH_TOKEN is required to upload iOS release dSYMs}"
brew install sentry-cli

- name: Restore opam root
id: opam-root
Expand Down
11 changes: 6 additions & 5 deletions apple/App/fastlane/Fastfile
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ default_platform(:ios)
platform :ios do
desc "Push a new beta build to TestFlight"
lane :beta do
UI.user_error!("SENTRY_AUTH_TOKEN is required to upload iOS release dSYMs") if ENV["SENTRY_AUTH_TOKEN"].to_s.strip.empty?
setup_ci

app_store_connect_api_key(
Expand Down Expand Up @@ -55,7 +56,7 @@ platform :ios do
configuration: "Release",
archive_path: archive_path,
derived_data_path: File.join(repo_root, "apple/.build/archives", native_cache_key),
xcargs: "-allowProvisioningUpdates -skipPackagePluginValidation -skipMacroValidation CURRENT_PROJECT_VERSION=#{build_number} LOGSEQ_BUILD_REVISION=#{revision}"
xcargs: "-allowProvisioningUpdates -skipPackagePluginValidation -skipMacroValidation DEBUG_INFORMATION_FORMAT=dwarf-with-dsym CURRENT_PROJECT_VERSION=#{build_number} LOGSEQ_BUILD_REVISION=#{revision}"
}
build_app(**build_options, skip_package_ipa: true)

Expand All @@ -70,10 +71,10 @@ platform :ios do
sh("python3", verifier, ipa, *verification_args,
"--report", File.join(release_dir, "ipa-verification.json"))

unless ENV["SENTRY_AUTH_TOKEN"].to_s.strip.empty?
sh("sentry-cli", "debug-files", "upload", "--org", "logseq", "--project", "logseq-ios",
"--wait", File.join(archive_path, "dSYMs"))
end
dsym_dir = File.join(archive_path, "dSYMs")
UI.user_error!("Archive contains no app dSYM") unless File.directory?(File.join(dsym_dir, "Logseq.app.dSYM"))
sh("sentry-cli", "debug-files", "upload", "--org", "logseq", "--project", "logseq-ios",
"--include-sources", "--wait", dsym_dir)

upload_to_testflight(
ipa: ipa,
Expand Down
10 changes: 10 additions & 0 deletions apple/Sources/Logseq/LGRuntime.swift
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,9 @@ public final class LGRuntime {
authenticationCode: Int = 0
) throws {
guard !isStarted else { return }
#if os(iOS)
LogseqCrashReporting.runtime(.start)
#endif
lastAuthoritativeCoreResponse = nil
lastCoreSyncProjection = nil
authoritativeCoreResponseInvalidated = false
Expand All @@ -165,6 +168,9 @@ public final class LGRuntime {
invalidatePendingPatchApplies()
try apply(initialPatch)
isStarted = true
#if os(iOS)
LogseqCrashReporting.runtime(.started)
#endif
while !pendingCoreResponses.isEmpty {
let response = pendingCoreResponses.removeFirst()
try applyCoreResponse(response, synchronously: true)
Expand Down Expand Up @@ -436,6 +442,10 @@ public final class LGRuntime {
}

private func drainEffects() async {
#if os(iOS)
LogseqCrashReporting.runtime(.drainBegin)
defer { LogseqCrashReporting.runtime(.drainEnd) }
#endif
defer { isDrainingEffects = false }
let epoch = patchApplyEpoch
while true {
Expand Down
62 changes: 59 additions & 3 deletions apple/Sources/Logseq/LogseqCrashReporting.swift
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,72 @@ enum LogseqCrashReporting {
options.environment = environment
options.sendDefaultPii = false
options.enableAutoSessionTracking = false
options.enableAutoBreadcrumbTracking = false
options.enableNetworkBreadcrumbs = false
options.maxBreadcrumbs = 0
options.enableAutoBreadcrumbTracking = true
options.enableNetworkBreadcrumbs = true
options.maxBreadcrumbs = 50
options.beforeBreadcrumb = { breadcrumb in safeBreadcrumb(breadcrumb) }
options.beforeSend = scrub
}
if let revision = Bundle.main.object(forInfoDictionaryKey: "LogseqRevision") as? String {
SentrySDK.configureScope { $0.setTag(value: revision, key: "git_revision") }
}
}

nonisolated static func safeBreadcrumb(_ breadcrumb: Breadcrumb) -> Breadcrumb? {
let data = breadcrumb.data ?? [:]
var safe: [String: Any] = [:]
switch breadcrumb.category {
case "app.lifecycle":
guard let state = data["state"] as? String,
["foreground", "background", "active", "inactive"].contains(state) else { return nil }
safe["state"] = state
case "device.event":
guard data["action"] as? String == "LOW_MEMORY" else { return nil }
safe["action"] = "LOW_MEMORY"
case "device.connectivity":
guard let state = data["connectivity"] as? String,
["wifi", "cellular", "ethernet", "none", "offline"].contains(state) else { return nil }
safe["connectivity"] = state
case "ui.lifecycle":
guard let screen = data["screen"] as? String,
!screen.isEmpty, screen.count < 200,
screen.range(of: "^[A-Za-z_][A-Za-z0-9_.]*(?:<[A-Za-z0-9_., <>]+>)?$", options: .regularExpression) != nil else { return nil }
safe["screen"] = screen
case "http":
guard let method = data["method"] as? String,
["GET", "POST", "PUT", "PATCH", "DELETE", "HEAD", "OPTIONS"].contains(method),
let rawURL = data["url"] as? String,
let url = URLComponents(string: rawURL),
let scheme = url.scheme, ["https", "http"].contains(scheme),
let host = url.host else { return nil }
safe["method"] = method
safe["host"] = host
if let status = data["status_code"] as? Int, (100...599).contains(status) {
safe["status_code"] = status
}
case "runtime":
guard let state = data["state"] as? String,
["start", "started", "drain_begin", "drain_end"].contains(state) else { return nil }
safe["state"] = state
default:
return nil
}
let result = Breadcrumb(level: breadcrumb.level, category: breadcrumb.category)
result.timestamp = breadcrumb.timestamp
result.data = safe
return result
}

enum RuntimeState: String {
case start, started, drainBegin = "drain_begin", drainEnd = "drain_end"
}

nonisolated static func runtime(_ state: RuntimeState) {
let breadcrumb = Breadcrumb(level: .info, category: "runtime")
breadcrumb.data = ["state": state.rawValue]
SentrySDK.addBreadcrumb(breadcrumb)
}

nonisolated static func scrub(_ event: Event) -> Event? {
// Exception reasons can contain graph names, paths, or user content.
event.exceptions?.forEach { exception in
Expand Down
29 changes: 29 additions & 0 deletions apple/Tests/UI/sentry-callback-isolation.swift
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,35 @@ import SwiftUI
precondition(!Thread.isMainThread)
// Exercise the actual installed callback without uploading test events.
let callback = SentrySDK.internal.options.beforeSend!
let beforeBreadcrumb = SentrySDK.internal.options.beforeBreadcrumb!
let cases: [(String, [String: Any], [String: String]?)] = [
("app.lifecycle", ["state": "active", "title": "private"], ["state": "active"]),
("device.event", ["action": "LOW_MEMORY"], ["action": "LOW_MEMORY"]),
("device.connectivity", ["connectivity": "wifi"], ["connectivity": "wifi"]),
("ui.lifecycle", ["screen": "Logseq.Controller", "title": "private"], ["screen": "Logseq.Controller"]),
("ui.lifecycle", ["screen": "UIHostingController<ModifiedContent<AnyView, AnyView>>", "title": "private"], ["screen": "UIHostingController<ModifiedContent<AnyView, AnyView>>"]),
("http", ["method": "GET", "url": "https://user:token@example.com/private?q=secret#title"], ["method": "GET", "host": "example.com"]),
("runtime", ["state": "drain_begin"], ["state": "drain_begin"]),
("console", ["message": "private"], nil),
("ui.click", ["title": "private"], nil),
("unknown", [:], nil),
("app.lifecycle", [:], nil),
("http", ["method": "GET", "url": "not a URL"], nil),
("ui.lifecycle", ["screen": "private title"], nil)
]
for (category, data, expected) in cases {
let crumb = Breadcrumb(level: .info, category: category)
crumb.data = data
crumb.message = "private message"
let result = beforeBreadcrumb(crumb)
if let expected {
precondition(result?.data as? [String: String] == expected)
precondition(result?.message == nil)
} else {
precondition(result == nil)
}
}
print("PASS: background beforeBreadcrumb retains only allowlisted diagnostic fields; drops content, empty and malformed breadcrumbs")
SentrySDK.close()
let event = Event(level: .error)
let typed = Exception(value: "private graph/path", type: "ExampleError")
Expand Down
Loading