Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CRCID Support when reporting crashes #3653

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from
Draft
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
10 changes: 10 additions & 0 deletions DuckDuckGo.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -1335,6 +1335,8 @@
37FC2A1C2CF903A70048E226 /* NewTabPagePrivacyStatsClientTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 37FC2A1A2CF903A70048E226 /* NewTabPagePrivacyStatsClientTests.swift */; };
37FD78112A29EBD100B36DB1 /* SyncErrorHandler.swift in Sources */ = {isa = PBXBuildFile; fileRef = 37FD78102A29EBD100B36DB1 /* SyncErrorHandler.swift */; };
37FD78122A29EBD100B36DB1 /* SyncErrorHandler.swift in Sources */ = {isa = PBXBuildFile; fileRef = 37FD78102A29EBD100B36DB1 /* SyncErrorHandler.swift */; };
467D16672D0C98D5007C020A /* CrashReportSenderExtensions.swift in Sources */ = {isa = PBXBuildFile; fileRef = 467D16662D0C98D5007C020A /* CrashReportSenderExtensions.swift */; };
467D16682D0C98D5007C020A /* CrashReportSenderExtensions.swift in Sources */ = {isa = PBXBuildFile; fileRef = 467D16662D0C98D5007C020A /* CrashReportSenderExtensions.swift */; };
4B0135CE2729F1AA00D54834 /* NSPasteboardExtension.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4B0135CD2729F1AA00D54834 /* NSPasteboardExtension.swift */; };
4B02198925E05FAC00ED7DEA /* FireproofingURLExtensions.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4B02197F25E05FAC00ED7DEA /* FireproofingURLExtensions.swift */; };
4B02198A25E05FAC00ED7DEA /* FireproofDomains.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4B02198125E05FAC00ED7DEA /* FireproofDomains.swift */; };
Expand Down Expand Up @@ -3827,6 +3829,7 @@
37FC2A172CF903060048E226 /* MockPrivacyStats.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MockPrivacyStats.swift; sourceTree = "<group>"; };
37FC2A1A2CF903A70048E226 /* NewTabPagePrivacyStatsClientTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NewTabPagePrivacyStatsClientTests.swift; sourceTree = "<group>"; };
37FD78102A29EBD100B36DB1 /* SyncErrorHandler.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SyncErrorHandler.swift; sourceTree = "<group>"; };
467D16662D0C98D5007C020A /* CrashReportSenderExtensions.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CrashReportSenderExtensions.swift; sourceTree = "<group>"; };
4B0135CD2729F1AA00D54834 /* NSPasteboardExtension.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = NSPasteboardExtension.swift; sourceTree = "<group>"; };
4B02197F25E05FAC00ED7DEA /* FireproofingURLExtensions.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = FireproofingURLExtensions.swift; sourceTree = "<group>"; };
4B02198125E05FAC00ED7DEA /* FireproofDomains.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = FireproofDomains.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -8698,6 +8701,7 @@
AAC30A27268E045400D2D9CD /* CrashReportReader.swift */,
AAC30A2D268F1EE300D2D9CD /* CrashReportPromptPresenter.swift */,
AAC30A29268E239100D2D9CD /* CrashReport.swift */,
467D16662D0C98D5007C020A /* CrashReportSenderExtensions.swift */,
);
path = Model;
sourceTree = "<group>";
Expand Down Expand Up @@ -11606,6 +11610,7 @@
3706FB39293F65D500E42796 /* PrivacyDashboardPopover.swift in Sources */,
372ED7C32CDD481B002287EC /* NewTabPageUserContentController.swift in Sources */,
3706FB3B293F65D500E42796 /* RootView.swift in Sources */,
467D16672D0C98D5007C020A /* CrashReportSenderExtensions.swift in Sources */,
3706FB3C293F65D500E42796 /* AddressBarTextField.swift in Sources */,
3706FB3D293F65D500E42796 /* FocusRingView.swift in Sources */,
3706FB3E293F65D500E42796 /* BookmarksBarViewModel.swift in Sources */,
Expand Down Expand Up @@ -13140,6 +13145,7 @@
AABEE6A524AA0A7F0043105B /* SuggestionViewController.swift in Sources */,
1D6216B229069BBF00386B2C /* BWKeyStorage.swift in Sources */,
AA7E919F287872EA00AB6B62 /* VisitViewModel.swift in Sources */,
467D16682D0C98D5007C020A /* CrashReportSenderExtensions.swift in Sources */,
7BD7B0012C19D3830039D20A /* VPNIPCResources.swift in Sources */,
C1935A1B2C88F9ED001AD72D /* SyncPromoViewModel.swift in Sources */,
B6676BE12AA986A700525A21 /* AddressBarTextEditor.swift in Sources */,
Expand Down Expand Up @@ -14499,6 +14505,10 @@
isa = XCBuildConfiguration;
baseConfigurationReference = 37DD516C296EAEDC00837F27 /* DuckDuckGoAppStore.xcconfig */;
buildSettings = {
CODE_SIGN_IDENTITY = "Apple Development";
CODE_SIGN_STYLE = Automatic;
DEVELOPMENT_TEAM = HKE973VLUW;
PROVISIONING_PROFILE_SPECIFIER = "";
};
name = Release;
};
Expand Down
2 changes: 1 addition & 1 deletion DuckDuckGo/Application/AppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,8 @@
let fileStore: FileStore

#if APPSTORE
private let crashCollection = CrashCollection(platform: .macOSAppStore)
private let crashCollection = CrashCollection(CrashReportSender(platform: .macOSAppStore))
#else

Check failure on line 74 in DuckDuckGo/Application/AppDelegate.swift

View workflow job for this annotation

GitHub Actions / Test (Sandbox)

missing argument label 'platform:' in call

Check failure on line 74 in DuckDuckGo/Application/AppDelegate.swift

View workflow job for this annotation

GitHub Actions / Test (Sandbox)

cannot convert value of type 'CrashReportSender' to expected argument type 'CrashCollectionPlatform'
private let crashReporter = CrashReporter()
#endif

Expand Down
44 changes: 44 additions & 0 deletions DuckDuckGo/CrashReports/Model/CrashReportSenderExtensions.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
//

Check failure on line 1 in DuckDuckGo/CrashReports/Model/CrashReportSenderExtensions.swift

View workflow job for this annotation

GitHub Actions / SwiftLint

Header comments should be consistent with project patterns (file_header)
// CrashReportSenderExtensions.swift
// DuckDuckGo
//
// Copyright © 2024 DuckDuckGo. All rights reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//

import Crashes
import Common
import PixelKit

extension CrashReportSender {

static let pixelEvents: EventMapping<CrashReportSenderError> = .init { event, _, _, _ in

Check failure on line 26 in DuckDuckGo/CrashReports/Model/CrashReportSenderExtensions.swift

View workflow job for this annotation

GitHub Actions / Test (Non-Sandbox)

cannot find type 'CrashReportSenderError' in scope

Check failure on line 26 in DuckDuckGo/CrashReports/Model/CrashReportSenderExtensions.swift

View workflow job for this annotation

GitHub Actions / Make Release Build

cannot find type 'CrashReportSenderError' in scope

Check failure on line 26 in DuckDuckGo/CrashReports/Model/CrashReportSenderExtensions.swift

View workflow job for this annotation

GitHub Actions / Make Release Build

cannot find type 'CrashReportSenderError' in scope
switch event {
case CrashReportSenderError.crcidMissing:
PixelKit.fire(GeneralPixel.crashReportCRCIDMissing)

case CrashReportSenderError.submissionFailed(let error):
if let error {

Check failure on line 32 in DuckDuckGo/CrashReports/Model/CrashReportSenderExtensions.swift

View workflow job for this annotation

GitHub Actions / SwiftLint

Lines should not have trailing whitespace (trailing_whitespace)
PixelKit.fire(DebugEvent(GeneralPixel.crashReportingSubmissionFailed),
frequency: .standard,
withHeaders: [:],
withAdditionalParameters: ["HTTPStatusCode": "\(error.statusCode)"],
withError: nil,
allowedQueryReservedCharacters: nil)
} else {
PixelKit.fire(GeneralPixel.crashReportingSubmissionFailed)
}
}
}
}
7 changes: 5 additions & 2 deletions DuckDuckGo/CrashReports/Model/CrashReporter.swift
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@
final class CrashReporter {

private let reader = CrashReportReader()
private lazy var sender = CrashReportSender(platform: .macOS)
private lazy var sender = CrashReportSender(platform: .macOS, pixelEvents: CrashReportSender.pixelEvents)

Check failure on line 27 in DuckDuckGo/CrashReports/Model/CrashReporter.swift

View workflow job for this annotation

GitHub Actions / Test (Non-Sandbox)

extra argument 'pixelEvents' in call

Check failure on line 27 in DuckDuckGo/CrashReports/Model/CrashReporter.swift

View workflow job for this annotation

GitHub Actions / Make Release Build

extra argument 'pixelEvents' in call

Check failure on line 27 in DuckDuckGo/CrashReports/Model/CrashReporter.swift

View workflow job for this annotation

GitHub Actions / Make Release Build

extra argument 'pixelEvents' in call
private lazy var crcidManager = CRCIDManager()

Check failure on line 28 in DuckDuckGo/CrashReports/Model/CrashReporter.swift

View workflow job for this annotation

GitHub Actions / Test (Non-Sandbox)

cannot find 'CRCIDManager' in scope

Check failure on line 28 in DuckDuckGo/CrashReports/Model/CrashReporter.swift

View workflow job for this annotation

GitHub Actions / Make Release Build

cannot find 'CRCIDManager' in scope

Check failure on line 28 in DuckDuckGo/CrashReports/Model/CrashReporter.swift

View workflow job for this annotation

GitHub Actions / Make Release Build

cannot find 'CRCIDManager' in scope
private lazy var promptPresenter = CrashReportPromptPresenter()

@UserDefaultsWrapper(key: .lastCrashReportCheckDate, defaultValue: nil)
Expand Down Expand Up @@ -56,7 +57,9 @@
return
}
Task {
await self.sender.send(contentData)
let crcid = self.crcidManager.crcid
let result = await self.sender.send(contentData, crcid: crcid)
self.crcidManager.handleCrashSenderResult(result: result.result, response: result.response)
}
}

Expand Down
8 changes: 8 additions & 0 deletions DuckDuckGo/Statistics/GeneralPixel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ enum GeneralPixel: PixelKitEventV2 {

case crash
case crashOnCrashHandlersSetUp
case crashReportingSubmissionFailed // crashreporting_submission-failed
case crashReportCRCIDMissing // crashreporting_crcid-missing
case compileRulesWait(onboardingShown: OnboardingShown, waitTime: CompileRulesWaitTime, result: WaitResult)
case launchInitial(cohort: String)
case launch(isDefault: Bool)
Expand Down Expand Up @@ -475,6 +477,12 @@ enum GeneralPixel: PixelKitEventV2 {
case .crashOnCrashHandlersSetUp:
return "m_mac_crash_on_handlers_setup"

case .crashReportCRCIDMissing:
return "crashreporting_crcid-missing"

case .crashReportingSubmissionFailed:
return "crashreporting_submission-failed"

case .compileRulesWait(onboardingShown: let onboardingShown, waitTime: let waitTime, result: let result):
return "m_mac_cbr-wait_\(onboardingShown)_\(waitTime)_\(result)"

Expand Down
Loading