Skip to content

Commit 82b82bc

Browse files
authored
chore: Add log when a Swift Integration is loaded (#6976)
* chore: Add log when a Swift Integration is loaded * Remove unnecessary test * Move log message to `SentryHub` * Update test
1 parent b3b9593 commit 82b82bc

File tree

5 files changed

+74
-1
lines changed

5 files changed

+74
-1
lines changed

Sentry.xcodeproj/project.pbxproj

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -998,6 +998,7 @@
998998
F48F767C2E60B555009D4E7D /* SentryNSTimerFactory.swift in Sources */ = {isa = PBXBuildFile; fileRef = F48F767B2E60B555009D4E7D /* SentryNSTimerFactory.swift */; };
999999
F48F78692E61DE28009D4E7D /* SentryReachability.swift in Sources */ = {isa = PBXBuildFile; fileRef = F48F78682E61DE28009D4E7D /* SentryReachability.swift */; };
10001000
F49236EB2E5E4B2F00663673 /* SentryBinaryImageCache.swift in Sources */ = {isa = PBXBuildFile; fileRef = F49236EA2E5E4B2F00663673 /* SentryBinaryImageCache.swift */; };
1001+
F498EBA62EE0B8E400F57509 /* SentrySwiftIntegrationInstallerTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = F498EBA52EE0B8E400F57509 /* SentrySwiftIntegrationInstallerTests.swift */; };
10011002
F49D41982DEA27AF00D9244E /* SentryUseNSExceptionCallstackWrapperTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = F49D41972DEA27AF00D9244E /* SentryUseNSExceptionCallstackWrapperTests.swift */; };
10021003
F49D419A2DEA2FB000D9244E /* SentryCrashExceptionApplicationTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = F49D41992DEA2FB000D9244E /* SentryCrashExceptionApplicationTests.swift */; };
10031004
F49D419C2DEA30C300D9244E /* SentryCrashExceptionApplicationHelper.h in Headers */ = {isa = PBXBuildFile; fileRef = F49D419B2DEA30B800D9244E /* SentryCrashExceptionApplicationHelper.h */; };
@@ -2376,6 +2377,7 @@
23762377
F48F767B2E60B555009D4E7D /* SentryNSTimerFactory.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SentryNSTimerFactory.swift; sourceTree = "<group>"; };
23772378
F48F78682E61DE28009D4E7D /* SentryReachability.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SentryReachability.swift; sourceTree = "<group>"; };
23782379
F49236EA2E5E4B2F00663673 /* SentryBinaryImageCache.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SentryBinaryImageCache.swift; sourceTree = "<group>"; };
2380+
F498EBA52EE0B8E400F57509 /* SentrySwiftIntegrationInstallerTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SentrySwiftIntegrationInstallerTests.swift; sourceTree = "<group>"; };
23792381
F49D41972DEA27AF00D9244E /* SentryUseNSExceptionCallstackWrapperTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SentryUseNSExceptionCallstackWrapperTests.swift; sourceTree = "<group>"; };
23802382
F49D41992DEA2FB000D9244E /* SentryCrashExceptionApplicationTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SentryCrashExceptionApplicationTests.swift; sourceTree = "<group>"; };
23812383
F49D419B2DEA30B800D9244E /* SentryCrashExceptionApplicationHelper.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = SentryCrashExceptionApplicationHelper.h; path = include/SentryCrashExceptionApplicationHelper.h; sourceTree = "<group>"; };
@@ -3506,6 +3508,7 @@
35063508
7B944FA924697E9700A10721 /* Integrations */ = {
35073509
isa = PBXGroup;
35083510
children = (
3511+
F498EBA52EE0B8E400F57509 /* SentrySwiftIntegrationInstallerTests.swift */,
35093512
843FB3422D156B9900558F18 /* Feedback */,
35103513
7BF6505D292B77D100BBA5A8 /* MetricKit */,
35113514
D808FB85281AB2EF009A2A33 /* UIEvents */,
@@ -6372,6 +6375,7 @@
63726375
623E16C32D6C57C000CF1625 /* SentryANRTypeTests.swift in Sources */,
63736376
D80694C42B7CC9AE00B820E6 /* SentryReplayEventTests.swift in Sources */,
63746377
7B34721728086A9D0041F047 /* SentrySwizzleWrapperTests.swift in Sources */,
6378+
F498EBA62EE0B8E400F57509 /* SentrySwiftIntegrationInstallerTests.swift in Sources */,
63756379
8EC4CF5025C3A0070093DEE9 /* SentrySpanContextTests.swift in Sources */,
63766380
6281C5742D3E50DF009D0978 /* ArbitraryDataTests.swift in Sources */,
63776381
FAD882762EDA6EF50055AA44 /* SentrySDKInfo+Equality.swift in Sources */,

Sources/Sentry/SentryHub.m

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -657,6 +657,7 @@ - (void)addInstalledIntegration:(id<SentryIntegrationProtocol>)integration name:
657657
[_installedIntegrations addObject:integration];
658658
[_installedIntegrationNames addObject:name];
659659
}
660+
SENTRY_LOG_DEBUG(@"Integration installed: %@", name);
660661
}
661662

662663
- (void)removeAllIntegrations

Sources/Sentry/SentrySDKInternal.m

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -561,7 +561,6 @@ + (void)installIntegrations
561561
id<SentryObjCIntegrationProtocol> integrationInstance = [[integrationClass alloc] init];
562562
BOOL shouldInstall = [integrationInstance installWithOptions:options];
563563
if (shouldInstall) {
564-
SENTRY_LOG_DEBUG(@"Integration installed: %@", NSStringFromClass(integrationClass));
565564
[SentrySDKInternal.currentHub
566565
addInstalledIntegration:integrationInstance
567566
name:NSStringFromClass(integrationClass)];
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
@_spi(Private) @testable import Sentry
2+
@_spi(Private) import SentryTestUtils
3+
import XCTest
4+
5+
final class SentrySwiftIntegrationInstallerTests: XCTestCase {
6+
7+
override func tearDown() {
8+
SentrySDKInternal.setCurrentHub(nil)
9+
10+
super.tearDown()
11+
}
12+
13+
// We are not testing `SwiftAsyncIntegration`, but use it as an example for an installed integration
14+
func testInstall_AddsInstalledIntegrations() {
15+
// Arrange
16+
let options = Options()
17+
options.dsn = TestConstants.dsnAsString(username: "SentrySwiftIntegrationInstallerTests")
18+
options.debug = true
19+
options.swiftAsyncStacktraces = true
20+
21+
let testHub = TestHub(client: nil, andScope: nil)
22+
SentrySDKInternal.setCurrentHub(testHub)
23+
24+
// Act
25+
SentrySwiftIntegrationInstaller.install(with: options)
26+
27+
// Assert
28+
XCTAssertEqual(testHub.installedIntegrationNames().count, 1)
29+
XCTAssertEqual(try XCTUnwrap(testHub.installedIntegrationNames().first), "SentrySwiftAsyncIntegration")
30+
XCTAssertEqual(testHub.installedIntegrations().count, 1)
31+
}
32+
33+
func testInstall_WithDisabledIntegration_DoesNotAddIntegration() {
34+
// Arrange
35+
let options = Options()
36+
options.dsn = TestConstants.dsnAsString(username: "SentrySwiftIntegrationInstallerTests")
37+
options.debug = true
38+
options.swiftAsyncStacktraces = false
39+
40+
let testHub = TestHub(client: nil, andScope: nil)
41+
SentrySDKInternal.setCurrentHub(testHub)
42+
43+
// Act
44+
SentrySwiftIntegrationInstaller.install(with: options)
45+
46+
// Assert
47+
XCTAssertEqual(testHub.installedIntegrationNames().count, 0)
48+
XCTAssertEqual(testHub.installedIntegrations().count, 0)
49+
}
50+
}

Tests/SentryTests/SentryHubTests.swift

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1324,6 +1324,25 @@ class SentryHubTests: XCTestCase {
13241324
})
13251325
}
13261326

1327+
func testAddIntegration() {
1328+
let oldOutput = SentrySDKLog.getLogOutput()
1329+
defer {
1330+
SentrySDKLog.setOutput(oldOutput)
1331+
}
1332+
let logOutput = TestLogOutput()
1333+
SentrySDKLog.setLogOutput(logOutput)
1334+
SentrySDKLog.configureLog(true, diagnosticLevel: .debug)
1335+
1336+
let sut = fixture.getSut()
1337+
1338+
sut.addInstalledIntegration(EmptyIntegration(), name: "MyIntegrationName")
1339+
1340+
let logs = logOutput.loggedMessages.joined()
1341+
XCTAssertTrue(logs.contains("Integration installed: MyIntegrationName"), "Should log when MyIntegrationName is installed")
1342+
XCTAssertTrue(sut.hasIntegration("MyIntegrationName"))
1343+
XCTAssertNotNil(sut.getInstalledIntegration(EmptyIntegration.self))
1344+
}
1345+
13271346
func testModifyIntegrationsConcurrently() {
13281347

13291348
let sut = fixture.getSut()

0 commit comments

Comments
 (0)