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

fix: Build visionOS project with static Sentry SDK #4462

Merged
merged 10 commits into from
Oct 24, 2024
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
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

## Unreleased

### Fixes

- Build visionOS project with static Sentry SDK (#4462)

### Improvements

- Log a warning when dropping envelopes due to rate-limiting (#4463)
Expand Down
1 change: 1 addition & 0 deletions Sources/Configuration/SDK.xcconfig
Original file line number Diff line number Diff line change
Expand Up @@ -47,3 +47,4 @@ GCC_PREPROCESSOR_DEFINITIONS_TestCI = DEBUG=1 TEST=1 TESTCI=1
GCC_PREPROCESSOR_DEFINITIONS_Release = RELEASE=1
GCC_PREPROCESSOR_DEFINITIONS_ReleaseWithoutUIKit = RELEASE=1 SENTRY_NO_UIKIT=1
GCC_PREPROCESSOR_DEFINITIONS = $(GCC_PREPROCESSOR_DEFINITIONS_$(CONFIGURATION))
SWIFT_OBJC_INTEROP_MODE[sdk=xr*]=objcxx
brustolin marked this conversation as resolved.
Show resolved Hide resolved
3 changes: 2 additions & 1 deletion Sources/Sentry/SentryHttpTransport.m
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,8 @@ - (SentryFlushResult)flush:(NSTimeInterval)timeout
- (void)envelopeItemDropped:(SentryEnvelopeItem *)envelopeItem
withCategory:(SentryDataCategory)dataCategory;
{
SENTRY_LOG_WARN(@"Envelope item dropped due to exceeding rate limit. Category: %@", nameForSentryDataCategory(dataCategory));
SENTRY_LOG_WARN(@"Envelope item dropped due to exceeding rate limit. Category: %@",
nameForSentryDataCategory(dataCategory));
[self recordLostEvent:dataCategory reason:kSentryDiscardReasonRateLimitBackoff];
[self recordLostSpans:envelopeItem reason:kSentryDiscardReasonRateLimitBackoff];
}
Expand Down
5 changes: 3 additions & 2 deletions Sources/Sentry/SentryLevelHelper.m
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
#import "SentryLevelHelper.h"
#import "SentryBreadcrumb+Private.h"

NSUInteger
sentry_breadcrumbLevel(SentryBreadcrumb *breadcrumb)
@implementation SentryLevelBridge : NSObject
+ (NSUInteger)breadcrumbLevel:(SentryBreadcrumb *)breadcrumb
brustolin marked this conversation as resolved.
Show resolved Hide resolved
{
return breadcrumb.level;
}
@end
6 changes: 4 additions & 2 deletions Sources/Sentry/SentryLogC.m
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#import "SentryLogC.h"
#import "SentryAsyncSafeLog.h"
#import "SentryFileManager.h"
#import "SentryInternalCDefines.h"
Expand All @@ -6,8 +7,8 @@

NS_ASSUME_NONNULL_BEGIN

void
sentry_initializeAsyncLogFile(void)
@implementation SentryAsyncLogWrapper
+ (void)initializeAsyncLogFile
{
const char *asyncLogPath =
[[sentryStaticCachesPath() stringByAppendingPathComponent:@"async.log"] UTF8String];
Expand All @@ -25,5 +26,6 @@
@"Could not open a handle to specified path for async logging %s", asyncLogPath);
};
}
@end

NS_ASSUME_NONNULL_END
1 change: 1 addition & 0 deletions Sources/Sentry/SentrySDK.m
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
#import "SentryHub+Private.h"
#import "SentryInternalDefines.h"
#import "SentryLog.h"
#import "SentryLogC.h"
#import "SentryMeta.h"
#import "SentryOptions+Private.h"
#import "SentryProfilingConditionals.h"
Expand Down
4 changes: 3 additions & 1 deletion Sources/Sentry/include/SentryLevelHelper.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ NS_ASSUME_NONNULL_BEGIN
/**
* This is a workaround to access SentryLevel value from swift
*/
NSUInteger sentry_breadcrumbLevel(SentryBreadcrumb *breadcrumb);
@interface SentryLevelBridge : NSObject
+ (NSUInteger)breadcrumbLevel:(SentryBreadcrumb *)breadcrumb;
@end

NS_ASSUME_NONNULL_END
7 changes: 6 additions & 1 deletion Sources/Sentry/include/SentryLogC.h
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
#ifndef SentryLogC_h
#define SentryLogC_h
void sentry_initializeAsyncLogFile(void);
#import <Foundation/Foundation.h>

@interface SentryAsyncLogWrapper : NSObject
+ (void)initializeAsyncLogFile;
@end

#endif
2 changes: 1 addition & 1 deletion Sources/Swift/Helper/Log/SentryLevel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,6 @@ class SentryLevelHelper: NSObject {
}

static func breadcrumbLevel(_ breadcrumb: Breadcrumb) -> SentryLevel? {
SentryLevel(rawValue: sentry_breadcrumbLevel(breadcrumb))
SentryLevel(rawValue: SentryLevelBridge.breadcrumbLevel(breadcrumb))
}
}
2 changes: 1 addition & 1 deletion Sources/Swift/Tools/SentryLog.swift
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ class SentryLog: NSObject {
self.isDebug = isDebug
self.diagnosticLevel = diagnosticLevel
}
sentry_initializeAsyncLogFile()
SentryAsyncLogWrapper.initializeAsyncLogFile()
brustolin marked this conversation as resolved.
Show resolved Hide resolved
}

@objc
Expand Down
10 changes: 10 additions & 0 deletions develop-docs/DECISIONS.md
Original file line number Diff line number Diff line change
Expand Up @@ -226,3 +226,13 @@ please refer to this [PR](https://github.com/getsentry/sentry-cocoa/pull/3623).
When coding with Swift be aware of two things:
1. If you want to use swift code in an Objc file: `#import "SentrySwift.h"`
2. If you want to use Objc code from Swift, first add the desired header file to `SentryInternal.h`, then, in your Swift file, `@_implementationOnly import _SentryPrivate` (the underscore makes auto-complete ignore it since we dont want users importing this module).

## Enabling C++/Objective-c++ interoperability for visionOS
brustolin marked this conversation as resolved.
Show resolved Hide resolved

Date: October 23, 2024
Contributors: @brustolin, @philipphofmann

To enable visionOS support with the Sentry static framework, you need to set the `SWIFT_OBJC_INTEROP_MODE` build setting to `objcxx`. This setting will only be applied for visionOS, but because much of the codebase is shared across platforms, this change introduces a limitation: we won’t be able to call C functions directly from Swift code.

However, C functions can still be accessed from code that is conditionally compiled using directives, such as `#if os(iOS)`.