From caafeee31676605a514628d51418a5ee21623380 Mon Sep 17 00:00:00 2001 From: Cameron Carmichael Alonso Date: Mon, 13 Nov 2023 18:17:08 +0000 Subject: [PATCH] fix: Support for CaptureFailedRequests on iOS (#2826) --- CHANGELOG.md | 5 +++++ src/Sentry/Platforms/iOS/SentrySdk.cs | 14 ++++++++++++++ 2 files changed, 19 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 2915ba7317..45817071c3 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -11,6 +11,11 @@ - [changelog](https://github.com/getsentry/sentry-cli/blob/master/CHANGELOG.md#2213) - [diff](https://github.com/getsentry/sentry-cli/compare/2.21.2...2.21.3) +### Fixes + + - Fixed CaptureFailedRequests and FailedRequestStatusCodes not affecting the Cocoa layer ([#2744](https://github.com/getsentry/sentry-dotnet/issues/2744)) + + ## 3.41.0 - Speed up SDK init ([#2784](https://github.com/getsentry/sentry-dotnet/pull/2784)) diff --git a/src/Sentry/Platforms/iOS/SentrySdk.cs b/src/Sentry/Platforms/iOS/SentrySdk.cs index 729bdb37f6..2a7d600283 100644 --- a/src/Sentry/Platforms/iOS/SentrySdk.cs +++ b/src/Sentry/Platforms/iOS/SentrySdk.cs @@ -27,6 +27,8 @@ private static void InitSentryCocoaSdk(SentryOptions options) cocoaOptions.DiagnosticLevel = options.DiagnosticLevel.ToCocoaSentryLevel(); cocoaOptions.Dsn = options.Dsn; cocoaOptions.EnableAutoSessionTracking = options.AutoSessionTracking; + cocoaOptions.EnableCaptureFailedRequests = options.CaptureFailedRequests; + cocoaOptions.FailedRequestStatusCodes = GetFailedRequestStatusCodes(options.FailedRequestStatusCodes); cocoaOptions.MaxAttachmentSize = (nuint) options.MaxAttachmentSize; cocoaOptions.MaxBreadcrumbs = (nuint) options.MaxBreadcrumbs; cocoaOptions.MaxCacheItems = (nuint) options.MaxCacheItems; @@ -201,4 +203,16 @@ private static string GetDefaultReleaseString() private static string GetDefaultDistributionString() => GetBundleValue("CFBundleVersion"); private static string GetBundleValue(string key) => NSBundle.MainBundle.ObjectForInfoDictionary(key).ToString(); + + private static CocoaSdk.SentryHttpStatusCodeRange[] GetFailedRequestStatusCodes(IList httpStatusCodeRanges) + { + var nativeRanges = new CocoaSdk.SentryHttpStatusCodeRange[httpStatusCodeRanges.Count]; + for (var i = 0; i < httpStatusCodeRanges.Count; i++) + { + var range = httpStatusCodeRanges[i]; + nativeRanges[i] = new CocoaSdk.SentryHttpStatusCodeRange(range.Start, range.End); + } + + return nativeRanges; + } }