From eea1f96e2707275a55eb244061cd9ea31d40b578 Mon Sep 17 00:00:00 2001 From: Andrew McKnight Date: Fri, 15 Nov 2024 17:29:16 -0900 Subject: [PATCH] fix headerdoc in SentrySDK.h; use new SDK capture method in form submission --- Sources/Sentry/Public/SentrySDK.h | 34 ++++++++++------ Sources/Sentry/Public/SentryUserFeedback.h | 12 +++++- Sources/Sentry/SentryUserFeedback.m | 40 +++++++++++++++---- Sources/Sentry/include/SentryPrivate.h | 1 + .../UserFeedback/SentryFeedback.swift | 2 +- .../UserFeedback/SentryUserFeedbackForm.swift | 12 +----- 6 files changed, 70 insertions(+), 31 deletions(-) diff --git a/Sources/Sentry/Public/SentrySDK.h b/Sources/Sentry/Public/SentrySDK.h index d11431f7074..409cb08e713 100644 --- a/Sources/Sentry/Public/SentrySDK.h +++ b/Sources/Sentry/Public/SentrySDK.h @@ -6,11 +6,18 @@ @protocol SentrySpan; -@class SentryOptions, SentryEvent, SentryBreadcrumb, SentryScope, SentryUser, SentryId, - SentryUserFeedback, SentryTransactionContext; +@class SentryBreadcrumb; +@class SentryEvent; +@class SentryFeedback; +@class SentryId; @class SentryMetricsAPI; -@class UIView; +@class SentryOptions; @class SentryReplayApi; +@class SentryScope; +@class SentryTransactionContext; +@class SentryUser; +@class SentryUserFeedback; +@class UIView; NS_ASSUME_NONNULL_BEGIN @@ -246,25 +253,28 @@ SENTRY_NO_INIT /** * Captures user feedback that was manually gathered and sends it to Sentry. * @param userFeedback The user feedback to send to Sentry. + * @note This method will be deprecated in a future release; use `captureFeedback` instead. + */ ++ (void)captureUserFeedback:(SentryUserFeedback *)userFeedback + NS_SWIFT_NAME(capture(userFeedback:)); + +/** + * Captures user feedback that was manually gathered and sends it to Sentry. + * @param feedback The feedback to send to Sentry. * @note If you'd prefer not to have to build the UI required to gather the feedback from the user, * consider using `showUserFeedbackForm`, which delivers a prepackaged user feedback experience. See * @c SentryOptions.configureUserFeedback to customize a fully managed integration. See - * https://docs.sentry.io/platforms/apple/user-feedback/#user-feedback-api and (TODO: add link to - * new docs) for more information on each approach. + * https://docs.sentry.io/platforms/apple/user-feedback/ for more information. */ -+ (void)captureUserFeedback:(SentryUserFeedback *)userFeedback - NS_SWIFT_NAME(capture(userFeedback:)); ++ (void)captureFeedback:(SentryFeedback *)feedback NS_SWIFT_NAME(capture(feedback:)); /** * Display a form to gather information from an end user in the app to send to Sentry as a user * feedback event. - * @see @c SentryOptions.enableUserFeedbackIntegration and @c SentryOptions.configureUserFeedback to - * enable the functionality and customize the experience. - * @note If @c SentryOptions.enableUserFeedbackIntegration is @c NO, this method is a no-op. + * @see @c SentryOptions.configureUserFeedback to customize the experience. * @note This is a fully managed user feedback flow; there will be no need to call * @c SentrySDK.captureUserFeedback . See - * https://docs.sentry.io/platforms/apple/user-feedback/#user-feedback-api and (TODO: add link to - * new docs) for more information on each approach. + * https://docs.sentry.io/platforms/apple/user-feedback/ for more information. */ + (void)showUserFeedbackForm; diff --git a/Sources/Sentry/Public/SentryUserFeedback.h b/Sources/Sentry/Public/SentryUserFeedback.h index 6bd777f1285..e915b18a6d5 100644 --- a/Sources/Sentry/Public/SentryUserFeedback.h +++ b/Sources/Sentry/Public/SentryUserFeedback.h @@ -15,14 +15,24 @@ NS_ASSUME_NONNULL_BEGIN */ NS_SWIFT_NAME(UserFeedback) @interface SentryUserFeedback : NSObject -SENTRY_NO_INIT /** * Initializes SentryUserFeedback and sets the required eventId. * @param eventId The eventId of the event to which the user feedback is associated. + * @note Uses the old envelope format descried at + * https://develop.sentry.dev/sdk/data-model/envelope-items/#user-feedback and will be deprecated in + * the future. */ - (instancetype)initWithEventId:(SentryId *)eventId; +/** + * Initializes a new `SentryUserFeedback` as its own event, instead of one attached to a transaction + * or error event. + * @note Uses the new envelope format described at + * https://develop.sentry.dev/application/feedback-architecture/#feedback-events. + */ +- (instancetype)init; + /** * The eventId of the event to which the user feedback is associated. */ diff --git a/Sources/Sentry/SentryUserFeedback.m b/Sources/Sentry/SentryUserFeedback.m index fc43f4bb2c8..f25e35b904a 100644 --- a/Sources/Sentry/SentryUserFeedback.m +++ b/Sources/Sentry/SentryUserFeedback.m @@ -2,7 +2,25 @@ #import "SentrySwift.h" #import -@implementation SentryUserFeedback +typedef enum : NSUInteger { + /** A user feedback attached to a transaction or error event. */ + kSentryUserFeedbackTypeAttached, + + /** A user feedback sent as its own event independent of any other event. */ + kSentryUserFeedbackTypeStandalone, +} SentryUserFeedbackType; + +@implementation SentryUserFeedback { + SentryUserFeedbackType _type; +} + +- (instancetype)init { + if (self = [super init]) { + _type = kSentryUserFeedbackTypeStandalone; + _eventId = [[SentryId alloc] init]; + } + return self; +} - (instancetype)initWithEventId:(SentryId *)eventId { @@ -11,18 +29,26 @@ - (instancetype)initWithEventId:(SentryId *)eventId _email = @""; _name = @""; _comments = @""; + _type = kSentryUserFeedbackTypeAttached; } return self; } - (NSDictionary *)serialize { - return @{ - @"event_id" : self.eventId.sentryIdString, - @"email" : self.email, - @"name" : self.name, - @"comments" : self.comments - }; + switch (_type) { + case kSentryUserFeedbackTypeAttached: + return @{ + @"event_id" : self.eventId.sentryIdString, + @"email" : self.email, + @"name" : self.name, + @"comments" : self.comments + }; + case kSentryUserFeedbackTypeStandalone: + return @{ + + }; + } } @end diff --git a/Sources/Sentry/include/SentryPrivate.h b/Sources/Sentry/include/SentryPrivate.h index 28d51908195..d9db51fcc7e 100644 --- a/Sources/Sentry/include/SentryPrivate.h +++ b/Sources/Sentry/include/SentryPrivate.h @@ -4,6 +4,7 @@ #import "SentryNSDataUtils.h" #import "SentryRandom.h" #import "SentryTime.h" +#import "SentrySDK+Private.h" // Headers that also import SentryDefines should be at the end of this list // otherwise it wont compile diff --git a/Sources/Swift/Integrations/UserFeedback/SentryFeedback.swift b/Sources/Swift/Integrations/UserFeedback/SentryFeedback.swift index df2a4b451c7..c052cb0b8f7 100644 --- a/Sources/Swift/Integrations/UserFeedback/SentryFeedback.swift +++ b/Sources/Swift/Integrations/UserFeedback/SentryFeedback.swift @@ -24,7 +24,7 @@ class SentryFeedback: NSObject, SentrySerializable { /// The event id that this feedback is associated with, like a crash report. var associatedEventId: String? - init(name: String?, email: String?, message: String, hints: [String: Any]?, source: Source, associatedEventId: String?) { + init(name: String?, email: String?, message: String, hints: [String: Any]? = nil, source: Source = .widget, associatedEventId: String? = nil) { self.eventId = SentryId() self.name = name self.email = email diff --git a/Sources/Swift/Integrations/UserFeedback/SentryUserFeedbackForm.swift b/Sources/Swift/Integrations/UserFeedback/SentryUserFeedbackForm.swift index 8a4d4cd4d1f..4ee2abca66a 100644 --- a/Sources/Swift/Integrations/UserFeedback/SentryUserFeedbackForm.swift +++ b/Sources/Swift/Integrations/UserFeedback/SentryUserFeedbackForm.swift @@ -108,16 +108,8 @@ class SentryUserFeedbackForm: UIViewController { } func submitFeedbackButtonTapped() { - guard let name = fullNameTextField.text, let email = emailTextField.text else { - return - } - let error = NSError(domain: "user-feedback", code: 1) - let eventId = SentrySDK.capture(error: error) - let uf = UserFeedback(eventId: eventId) - uf.name = name - uf.email = email - uf.comments = messageTextView.text - SentrySDK.capture(userFeedback: uf) + let feedback = SentryFeedback(name: fullNameTextField.text, email: emailTextField.text, message: messageTextView.text, hints: nil) + SentrySDK.capture(feedback: feedback) delegate?.finished() }