Skip to content

Commit

Permalink
Merge 1744321 into f278bab
Browse files Browse the repository at this point in the history
  • Loading branch information
brustolin authored Jan 2, 2025
2 parents f278bab + 1744321 commit 37adb91
Show file tree
Hide file tree
Showing 8 changed files with 72 additions and 3 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@

## Unreleased

### Improvements

- Add native SDK information in the replay option event (#4663)
### Features

- Session replay GA (#4662)
Expand Down
23 changes: 21 additions & 2 deletions Sources/Sentry/SentryMeta.m
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,20 @@

@implementation SentryMeta

const NSString *const sentryVersionString = @"8.43.0-beta.1";
const NSString *const sentrySdkName = @"sentry.cocoa";

// Don't remove the static keyword. If you do the compiler adds the constant name to the global
// symbol table and it might clash with other constants. When keeping the static keyword the
// compiler replaces all occurrences with the value.
static NSString *versionString = @"8.43.0-beta.1";
static NSString *sdkName = @"sentry.cocoa";
static NSString *versionString;
static NSString *sdkName;

+ (void)initialize
{
versionString = sentryVersionString.copy;
sdkName = sentrySdkName.copy;
}

+ (NSString *)versionString
{
Expand All @@ -28,4 +37,14 @@ + (void)setSdkName:(NSString *)value
sdkName = value;
}

+ (NSString *)nativeSdkName
{
return sentrySdkName.copy;
}

+ (NSString *)nativeVersionString
{
return sentryVersionString.copy;
}

@end
15 changes: 15 additions & 0 deletions Sources/Sentry/include/SentryMeta.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,21 @@ NS_ASSUME_NONNULL_BEGIN
*/
@property (nonatomic, class, copy) NSString *sdkName;

/**
* Return a version string e.g: 1.2.3 (3)
* This always report the version of Sentry.cocoa,
* `versionString` can be changed by hybrid SDKs.
* We can use this property to get which version of Sentry cocoa
* the hybrid SDK is using.
*/
@property (nonatomic, class, readonly) NSString *nativeVersionString;

/**
* Returns "sentry.cocoa"
* `sdkName` can be changed by hybrid SDKs.
*/
@property (nonatomic, class, readonly) NSString *nativeSdkName;

@end

NS_ASSUME_NONNULL_END
1 change: 1 addition & 0 deletions Sources/Sentry/include/SentryPrivate.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
#import "SentryDisplayLinkWrapper.h"
#import "SentryLevelHelper.h"
#import "SentryLogC.h"
#import "SentryMeta.h"
#import "SentryRandom.h"
#import "SentrySdkInfo.h"
#import "SentrySession.h"
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@ import Foundation
"errorSampleRate": options.onErrorSampleRate,
"maskAllText": options.maskAllText,
"maskAllImages": options.maskAllImages,
"quality": String(describing: options.quality)
"quality": String(describing: options.quality),
"nativeSdkName": SentryMeta.nativeSdkName,
"nativeSdkVersion": SentryMeta.nativeVersionString
]

if !options.maskedViewClasses.isEmpty {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
@_implementationOnly import _SentryPrivate
import Foundation

@objcMembers
Expand Down Expand Up @@ -146,6 +147,11 @@ public class SentryReplayOptions: NSObject, SentryRedactOptions {
*/
let maximumDuration = TimeInterval(3_600)

/**
* Used by hybrid SDKs to be able to configure SDK info for Session Replay
*/
var sdkInfo: [String: Any]?

/**
* Inittialize session replay options disabled
*/
Expand Down Expand Up @@ -183,5 +189,6 @@ public class SentryReplayOptions: NSObject, SentryRedactOptions {
if let quality = SentryReplayQuality(rawValue: dictionary["quality"] as? Int ?? -1) {
self.quality = quality
}
sdkInfo = dictionary["sdkInfo"] as? [String: Any]
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -248,6 +248,7 @@ class SentrySessionReplay: NSObject {
private func captureSegment(segment: Int, video: SentryVideoInfo, replayId: SentryId, replayType: SentryReplayType) {
let replayEvent = SentryReplayEvent(eventId: replayId, replayStartTimestamp: video.start, replayType: replayType, segmentId: segment)

replayEvent.sdk = self.replayOptions.sdkInfo
replayEvent.timestamp = video.end
replayEvent.urls = video.screens

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -253,6 +253,25 @@ class SentrySessionReplayTests: XCTestCase {
XCTAssertFalse(fixture.displayLink.isRunning())
}

func testSdkInfoIsSet() throws {
let fixture = Fixture()
let options = SentryReplayOptions(sessionSampleRate: 1, onErrorSampleRate: 1)
options.sdkInfo = ["version": "6.0.1", "name": "sentry.test"]

let sut = fixture.getSut(options: options)
sut.start(rootView: fixture.rootView, fullSession: true)

fixture.dateProvider.advance(by: 1)
Dynamic(sut).newFrame(nil)
fixture.dateProvider.advance(by: 5)
Dynamic(sut).newFrame(nil)

let event = try XCTUnwrap(fixture.lastReplayEvent)

XCTAssertEqual(event.sdk?["version"] as? String, "6.0.1")
XCTAssertEqual(event.sdk?["name"] as? String, "sentry.test")
}

func testSaveScreenShotInBufferMode() {
let fixture = Fixture()

Expand Down Expand Up @@ -428,6 +447,8 @@ class SentrySessionReplayTests: XCTestCase {
XCTAssertNil(options["maskedViewClasses"])
XCTAssertNil(options["unmaskedViewClasses"])
XCTAssertEqual(options["quality"] as? String, "medium")
XCTAssertEqual(options["nativeSdkName"] as? String, SentryMeta.nativeSdkName)
XCTAssertEqual(options["nativeSdkVersion"] as? String, SentryMeta.nativeVersionString)
}

func testOptionsInTheEventAllChanged() throws {
Expand Down

0 comments on commit 37adb91

Please sign in to comment.