@@ -414,8 +414,9 @@ final class SentryLogBatcherTests: XCTestCase {
414414 XCTAssertNil ( attributes [ " user.email " ] )
415415 }
416416
417- func testAddLog_DoesNotAddUserAttributesWhenNoUser ( ) throws {
417+ func testAddLog_NoUserAtributesAreSetIfInstallationIdIsNotCached ( ) throws {
418418 // No user set on scope
419+ // InstallationId not cached
419420
420421 let log = createTestLog ( body: " Test log message without user " )
421422 sut. addLog ( log, scope: scope)
@@ -430,6 +431,25 @@ final class SentryLogBatcherTests: XCTestCase {
430431 XCTAssertNil ( attributes [ " user.email " ] )
431432 }
432433
434+ func testAddLog_OnlySetsUserIdToInstallationIdWhenNoUserIsSet( ) throws {
435+ // No user set on scope
436+ // Create and cache installationId
437+ _ = SentryInstallation . id ( withCacheDirectoryPath: options. cacheDirectoryPath)
438+
439+ let log = createTestLog ( body: " Test log message without user " )
440+ sut. addLog ( log, scope: scope)
441+ sut. captureLogs ( )
442+
443+ let capturedLogs = testDelegate. getCapturedLogs ( )
444+ let capturedLog = try XCTUnwrap ( capturedLogs. first)
445+ let attributes = capturedLog. attributes
446+
447+ XCTAssertNotNil ( attributes [ " user.id " ] )
448+ XCTAssertEqual ( attributes [ " user.id " ] ? . value as? String , SentryInstallation . id ( withCacheDirectoryPath: options. cacheDirectoryPath) )
449+ XCTAssertNil ( attributes [ " user.name " ] )
450+ XCTAssertNil ( attributes [ " user.email " ] )
451+ }
452+
433453 func testAddLog_AddsOSAndDeviceAttributes( ) throws {
434454 let osContext = [ " name " : " iOS " , " version " : " 16.0.1 " ]
435455 let deviceContext = [ " family " : " iOS " , " model " : " iPhone14,4 " ]
0 commit comments