@@ -494,6 +494,47 @@ final class SentryLogBatcherTests: XCTestCase {
494494 XCTAssertNil ( attributes [ " device.family " ] )
495495 }
496496
497+ func testAddLog_AddsScopeAttributes( ) throws {
498+ let scope = Scope ( )
499+ scope. setAttribute ( value: " aString " , key: " string-attribute " )
500+ scope. setAttribute ( value: false , key: " bool-attribute " )
501+ scope. setAttribute ( value: 1.765 , key: " double-attribute " )
502+ scope. setAttribute ( value: 5 , key: " integer-attribute " )
503+
504+ let log = createTestLog ( body: " Test log message with user " )
505+ sut. addLog ( log, scope: scope)
506+ sut. captureLogs ( )
507+
508+ let capturedLogs = testDelegate. getCapturedLogs ( )
509+ let capturedLog = try XCTUnwrap ( capturedLogs. first)
510+ let attributes = capturedLog. attributes
511+
512+ XCTAssertEqual ( attributes [ " string-attribute " ] ? . value as? String , " aString " )
513+ XCTAssertEqual ( attributes [ " string-attribute " ] ? . type, " string " )
514+ XCTAssertEqual ( attributes [ " bool-attribute " ] ? . value as? Bool , false )
515+ XCTAssertEqual ( attributes [ " bool-attribute " ] ? . type, " boolean " )
516+ XCTAssertEqual ( attributes [ " double-attribute " ] ? . value as? Double , 1.765 )
517+ XCTAssertEqual ( attributes [ " double-attribute " ] ? . type, " double " )
518+ XCTAssertEqual ( attributes [ " integer-attribute " ] ? . value as? Int , 5 )
519+ XCTAssertEqual ( attributes [ " integer-attribute " ] ? . type, " integer " )
520+ }
521+
522+ func testAddLog_ScopeAttributesDoNotOverrideLogAttribute( ) throws {
523+ let scope = Scope ( )
524+ scope. setAttribute ( value: true , key: " log-attribute " )
525+
526+ let log = createTestLog ( body: " Test log message with user " , attributes: [ " log-attribute " : . init( value: false ) ] )
527+ sut. addLog ( log, scope: scope)
528+ sut. captureLogs ( )
529+
530+ let capturedLogs = testDelegate. getCapturedLogs ( )
531+ let capturedLog = try XCTUnwrap ( capturedLogs. first)
532+ let attributes = capturedLog. attributes
533+
534+ XCTAssertEqual ( attributes [ " log-attribute " ] ? . value as? Bool , false )
535+ XCTAssertEqual ( attributes [ " log-attribute " ] ? . type, " boolean " )
536+ }
537+
497538 // MARK: - Replay Attributes Tests
498539
499540#if canImport(UIKit) && !SENTRY_NO_UIKIT
0 commit comments