Skip to content

Commit 1449f36

Browse files
authored
Add API allowing to get/set event fingerprint (#920)
* Add API allowing to get/set event fingerprint * Update changelog * Fix var name * Fix clang format * Fix test
1 parent a22b515 commit 1449f36

12 files changed

+101
-1
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@
22

33
## Unreleased
44

5+
### Features
6+
7+
- Add API allowing to get/set event fingerprint ([#920](https://github.com/getsentry/sentry-unreal/pull/920))
8+
59
### Dependencies
610

711
- Bump Java SDK (Android) from v8.11.1 to v8.12.0 ([#911](https://github.com/getsentry/sentry-unreal/pull/911))

plugin-dev/Source/Sentry/Private/Android/AndroidSentryEvent.cpp

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@ void FAndroidSentryEvent::SetupClassMethods()
2626
GetMessageMethod = GetMethod("getMessage", "()Lio/sentry/protocol/Message;");
2727
SetLevelMethod = GetMethod("setLevel", "(Lio/sentry/SentryLevel;)V");
2828
GetLevelMethod = GetMethod("getLevel", "()Lio/sentry/SentryLevel;");
29+
SetFingerprintMethod = GetMethod("setFingerprints", "(Ljava/util/List;)V");
30+
GetFingerprintMethod = GetMethod("getFingerprints()", "()Ljava/util/List;");
2931
IsCrashMethod = GetMethod("isCrashed", "()Z");
3032
}
3133

@@ -57,6 +59,17 @@ ESentryLevel FAndroidSentryEvent::GetLevel() const
5759
return FAndroidSentryConverters::SentryLevelToUnreal(*level);
5860
}
5961

62+
void FAndroidSentryEvent::SetFingerprint(const TArray<FString>& fingerprint)
63+
{
64+
CallMethod<void>(SetFingerprintMethod, FAndroidSentryConverters::StringArrayToNative(fingerprint)->GetJObject());
65+
}
66+
67+
TArray<FString> FAndroidSentryEvent::GetFingerprint()
68+
{
69+
auto fingerprint = CallObjectMethod<jobject>(GetFingerprintMethod);
70+
return FAndroidSentryConverters::StringListToUnreal(*fingerprint);
71+
}
72+
6073
bool FAndroidSentryEvent::IsCrash() const
6174
{
6275
return CallMethod<bool>(IsCrashMethod);

plugin-dev/Source/Sentry/Private/Android/AndroidSentryEvent.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@ class FAndroidSentryEvent : public ISentryEvent, public FSentryJavaObjectWrapper
1919
virtual FString GetMessage() const override;
2020
virtual void SetLevel(ESentryLevel level) override;
2121
virtual ESentryLevel GetLevel() const override;
22+
virtual void SetFingerprint(const TArray<FString>& fingerprint) override;
23+
virtual TArray<FString> GetFingerprint() override;
2224
virtual bool IsCrash() const override;
2325
virtual bool IsAnr() const override;
2426

@@ -28,6 +30,8 @@ class FAndroidSentryEvent : public ISentryEvent, public FSentryJavaObjectWrapper
2830
FSentryJavaMethod GetMessageMethod;
2931
FSentryJavaMethod SetLevelMethod;
3032
FSentryJavaMethod GetLevelMethod;
33+
FSentryJavaMethod SetFingerprintMethod;
34+
FSentryJavaMethod GetFingerprintMethod;
3135
FSentryJavaMethod IsCrashMethod;
3236
};
3337

plugin-dev/Source/Sentry/Private/Apple/AppleSentryEvent.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,16 @@ ESentryLevel FAppleSentryEvent::GetLevel() const
5656
return FAppleSentryConverters::SentryLevelToUnreal(EventApple.level);
5757
}
5858

59+
void FAppleSentryEvent::SetFingerprint(const TArray<FString>& fingerprint)
60+
{
61+
EventApple.fingerprint = FAppleSentryConverters::StringArrayToNative(fingerprint);
62+
}
63+
64+
TArray<FString> FAppleSentryEvent::GetFingerprint()
65+
{
66+
return FAppleSentryConverters::StringArrayToUnreal(EventApple.fingerprint);
67+
}
68+
5969
bool FAppleSentryEvent::IsCrash() const
6070
{
6171
return EventApple.error != nullptr;

plugin-dev/Source/Sentry/Private/Apple/AppleSentryEvent.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ class FAppleSentryEvent : public ISentryEvent
2020
virtual FString GetMessage() const override;
2121
virtual void SetLevel(ESentryLevel level) override;
2222
virtual ESentryLevel GetLevel() const override;
23+
virtual void SetFingerprint(const TArray<FString>& fingerprint) override;
24+
virtual TArray<FString> GetFingerprint() override;
2325
virtual bool IsCrash() const override;
2426
virtual bool IsAnr() const override;
2527

plugin-dev/Source/Sentry/Private/GenericPlatform/GenericPlatformSentryEvent.cpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,17 @@ ESentryLevel FGenericPlatformSentryEvent::GetLevel() const
6464
return FGenericPlatformSentryConverters::SentryLevelToUnreal(level);
6565
}
6666

67+
void FGenericPlatformSentryEvent::SetFingerprint(const TArray<FString>& fingerprint)
68+
{
69+
sentry_value_set_by_key(Event, "fingerprint", FGenericPlatformSentryConverters::StringArrayToNative(fingerprint));
70+
}
71+
72+
TArray<FString> FGenericPlatformSentryEvent::GetFingerprint()
73+
{
74+
sentry_value_t fingerprint = sentry_value_get_by_key(Event, "fingerprint");
75+
return FGenericPlatformSentryConverters::StringArrayToUnreal(fingerprint);
76+
}
77+
6778
bool FGenericPlatformSentryEvent::IsCrash() const
6879
{
6980
return IsCrashEvent;

plugin-dev/Source/Sentry/Private/GenericPlatform/GenericPlatformSentryEvent.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@ class FGenericPlatformSentryEvent : public ISentryEvent
2222
virtual FString GetMessage() const override;
2323
virtual void SetLevel(ESentryLevel level) override;
2424
virtual ESentryLevel GetLevel() const override;
25+
virtual void SetFingerprint(const TArray<FString>& fingerprint) override;
26+
virtual TArray<FString> GetFingerprint() override;
2527
virtual bool IsCrash() const override;
2628
virtual bool IsAnr() const override;
2729

plugin-dev/Source/Sentry/Private/Interface/SentryEventInterface.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ class ISentryEvent
1818
virtual FString GetMessage() const = 0;
1919
virtual void SetLevel(ESentryLevel level) = 0;
2020
virtual ESentryLevel GetLevel() const = 0;
21+
virtual void SetFingerprint(const TArray<FString>& fingerprint) = 0;
22+
virtual TArray<FString> GetFingerprint() = 0;
2123
virtual bool IsCrash() const = 0;
2224
virtual bool IsAnr() const = 0;
2325
};

plugin-dev/Source/Sentry/Private/SentryEvent.cpp

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
#include "SentryEvent.h"
44

5+
#include "Algo/Find.h"
56
#include "HAL/PlatformSentryEvent.h"
67
#include "Interface/SentryIdInterface.h"
78

@@ -54,6 +55,22 @@ ESentryLevel USentryEvent::GetLevel() const
5455
return NativeImpl->GetLevel();
5556
}
5657

58+
void USentryEvent::SetFingerprint(const TArray<FString>& Fingerprint)
59+
{
60+
if (!NativeImpl)
61+
return;
62+
63+
return NativeImpl->SetFingerprint(Fingerprint);
64+
}
65+
66+
TArray<FString> USentryEvent::GetFingerprint() const
67+
{
68+
if (!NativeImpl)
69+
return TArray<FString>();
70+
71+
return NativeImpl->GetFingerprint();
72+
}
73+
5774
bool USentryEvent::IsCrash() const
5875
{
5976
if (!NativeImpl)

plugin-dev/Source/Sentry/Private/Tests/SentryEvent.spec.cpp

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,33 @@ void SentryEventSpec::Define()
3434
TestFalse("Event ID is non-empty", SentryEvent->GetId().IsEmpty());
3535
});
3636
});
37+
38+
Describe("Event fingerprint", [this]()
39+
{
40+
It("should persist its value", [this]()
41+
{
42+
TArray<FString> InFingerprint = { TEXT("F1"), TEXT("F2"), TEXT("F3") };
43+
44+
SentryEvent->SetFingerprint(InFingerprint);
45+
TArray<FString> OutFingerprint = SentryEvent->GetFingerprint();
46+
47+
TestEqual("Fingerprint elements count", OutFingerprint.Num(), InFingerprint.Num());
48+
TestEqual("Fingerprint first element", OutFingerprint[0], InFingerprint[0]);
49+
TestEqual("Fingerprint second element", OutFingerprint[1], InFingerprint[1]);
50+
TestEqual("Fingerprint third element", OutFingerprint[2], InFingerprint[2]);
51+
});
52+
53+
It("can be emptry", [this]()
54+
{
55+
TArray<FString> InFingerprint = {};
56+
57+
SentryEvent->SetFingerprint(InFingerprint);
58+
TArray<FString> OutFingerprint = SentryEvent->GetFingerprint();
59+
60+
TestEqual("Fingerprint elements count", OutFingerprint.Num(), InFingerprint.Num());
61+
TestEqual("Fingerprint is empty", OutFingerprint.Num(), 0);
62+
});
63+
});
3764
}
3865

3966
#endif

plugin-dev/Source/Sentry/Private/Utils/SentryScreenshotUtils.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ bool SentryScreenshotUtils::CaptureScreenshot(const FString& ScreenshotSavePath)
5757

5858
#if UE_VERSION_OLDER_THAN(5, 0, 0)
5959
GetHighResScreenshotConfig().MergeMaskIntoAlpha(*Bitmap);
60-
TArray<uint8> *CompressedBitmap = new TArray<uint8>();
60+
TArray<uint8>* CompressedBitmap = new TArray<uint8>();
6161
FImageUtils::CompressImageArray(ViewportSize.X, ViewportSize.Y, *Bitmap, *CompressedBitmap);
6262
#else
6363
GetHighResScreenshotConfig().MergeMaskIntoAlpha(*Bitmap, FIntRect());

plugin-dev/Source/Sentry/Public/SentryEvent.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,14 @@ class SENTRY_API USentryEvent : public UObject, public TSentryImplWrapper<ISentr
4343
UFUNCTION(BlueprintPure, Category = "Sentry")
4444
ESentryLevel GetLevel() const;
4545

46+
/** Sets fingerprint of the event. */
47+
UFUNCTION(BlueprintCallable, Category = "Sentry")
48+
void SetFingerprint(const TArray<FString>& Fingerprint);
49+
50+
/** Gets fingerprint of the event. */
51+
UFUNCTION(BlueprintCallable, Category = "Sentry")
52+
TArray<FString> GetFingerprint() const;
53+
4654
/** Gets flag indicating whether the event is a crash. */
4755
UFUNCTION(BlueprintPure, Category = "Sentry")
4856
bool IsCrash() const;

0 commit comments

Comments
 (0)