Skip to content

Commit 311943f

Browse files
committed
Use variant for global context
1 parent aae4b98 commit 311943f

15 files changed

+94
-22
lines changed

CHANGELOG.md

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,12 @@
22

33
### Breaking Changes
44

5-
- The "Value" suffix has been removed from the get/set function names for tags and extras in `SentryScope`.
6-
- The get/set functions for contexts and extras in `SentryScope` now accept a variant type instead of string for the value.
7-
- The get/set functions for arbitrary data in `SentryBreadcrumb` now accept a variant type instead of string for the value.
5+
- "Value" suffix has been removed from the get/set function names for tags and extras in `SentryScope`.
6+
- Type of input parameters in certain public API functions was changed from `FString` to `FSentryVariant`:
7+
- Get/Set functions for contexts and extras in `SentryScope`
8+
- Get/Set functions for arbitrary data in `SentryBreadcrumb`
9+
- `AddBreadcrumbWithParams` and `SentContext` functions in `SentrySubsystem`
10+
- `CreateSentryBreadcrumb` function in `SentryLibrary`
811

912
## 1.0.0-beta.3
1013

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -196,10 +196,10 @@ void FAndroidSentrySubsystem::RemoveUser()
196196
FSentryJavaObjectWrapper::CallStaticMethod<void>(SentryJavaClasses::Sentry, "setUser", "(Lio/sentry/protocol/User;)V", nullptr);
197197
}
198198

199-
void FAndroidSentrySubsystem::SetContext(const FString& key, const TMap<FString, FString>& values)
199+
void FAndroidSentrySubsystem::SetContext(const FString& key, const TMap<FString, FSentryVariant>& values)
200200
{
201201
FSentryJavaObjectWrapper::CallStaticMethod<void>(SentryJavaClasses::SentryBridgeJava, "setContext", "(Ljava/lang/String;Ljava/util/HashMap;)V",
202-
*FSentryJavaObjectWrapper::GetJString(key), FAndroidSentryConverters::StringMapToNative(values)->GetJObject());
202+
*FSentryJavaObjectWrapper::GetJString(key), FAndroidSentryConverters::VariantMapToNative(values)->GetJObject());
203203
}
204204

205205
void FAndroidSentrySubsystem::SetTag(const FString& key, const FString& value)

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ class FAndroidSentrySubsystem : public ISentrySubsystem
2222
virtual void CaptureUserFeedback(TSharedPtr<ISentryUserFeedback> userFeedback) override;
2323
virtual void SetUser(TSharedPtr<ISentryUser> user) override;
2424
virtual void RemoveUser() override;
25-
virtual void SetContext(const FString& key, const TMap<FString, FString>& values) override;
25+
virtual void SetContext(const FString& key, const TMap<FString, FSentryVariant>& values) override;
2626
virtual void SetTag(const FString& key, const FString& value) override;
2727
virtual void RemoveTag(const FString& key) override;
2828
virtual void SetLevel(ESentryLevel level) override;

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -289,10 +289,10 @@ void FAppleSentrySubsystem::RemoveUser()
289289
[SentrySDK setUser:nil];
290290
}
291291

292-
void FAppleSentrySubsystem::SetContext(const FString& key, const TMap<FString, FString>& values)
292+
void FAppleSentrySubsystem::SetContext(const FString& key, const TMap<FString, FSentryVariant>& values)
293293
{
294294
[SentrySDK configureScope:^(SentryScope* scope) {
295-
[scope setContextValue:FAppleSentryConverters::StringMapToNative(values) forKey:key.GetNSString()];
295+
[scope setContextValue:FAppleSentryConverters::VariantMapToNative(values) forKey:key.GetNSString()];
296296
}];
297297
}
298298

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ class FAppleSentrySubsystem : public ISentrySubsystem
2222
virtual void CaptureUserFeedback(TSharedPtr<ISentryUserFeedback> userFeedback) override;
2323
virtual void SetUser(TSharedPtr<ISentryUser> user) override;
2424
virtual void RemoveUser() override;
25-
virtual void SetContext(const FString& key, const TMap<FString, FString>& values) override;
25+
virtual void SetContext(const FString& key, const TMap<FString, FSentryVariant>& values) override;
2626
virtual void SetTag(const FString& key, const FString& value) override;
2727
virtual void RemoveTag(const FString& key) override;
2828
virtual void SetLevel(ESentryLevel level) override;

plugin-dev/Source/Sentry/Private/GenericPlatform/CrashReporter/GenericPlatformSentryCrashReporter.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
#include "GenericPlatform/CrashReporter/GenericPlatformSentryCrashContext.h"
66
#include "GenericPlatform/GenericPlatformSentryUser.h"
7+
#include "GenericPlatform/Infrastructure/GenericPlatformSentryConverters.h"
78

89
#include "SentryDefines.h"
910

@@ -70,13 +71,13 @@ void FGenericPlatformSentryCrashReporter::RemoveUser()
7071
UpdateCrashReporterConfig();
7172
}
7273

73-
void FGenericPlatformSentryCrashReporter::SetContext(const FString& key, const TMap<FString, FString>& values)
74+
void FGenericPlatformSentryCrashReporter::SetContext(const FString& key, const TMap<FString, FSentryVariant>& values)
7475
{
7576
TSharedPtr<FJsonObject> valuesConfig = MakeShareable(new FJsonObject);
7677

7778
for (auto it = values.CreateConstIterator(); it; ++it)
7879
{
79-
valuesConfig->SetStringField(it.Key(), it.Value());
80+
valuesConfig->Values.Add(it.Key(), FGenericPlatformSentryConverters::VariantToJsonValue(it.Value()));
8081
}
8182

8283
TSharedPtr<FJsonObject> contextConfig;

plugin-dev/Source/Sentry/Private/GenericPlatform/CrashReporter/GenericPlatformSentryCrashReporter.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
#pragma once
44

55
#include "CoreMinimal.h"
6+
#include "SentryVariant.h"
67

78
#if USE_SENTRY_NATIVE
89

@@ -19,7 +20,7 @@ class FGenericPlatformSentryCrashReporter
1920
void SetEnvironment(const FString& environment);
2021
void SetUser(TSharedPtr<FGenericPlatformSentryUser> user);
2122
void RemoveUser();
22-
void SetContext(const FString& key, const TMap<FString, FString>& values);
23+
void SetContext(const FString& key, const TMap<FString, FSentryVariant>& values);
2324
void SetTag(const FString& key, const FString& value);
2425
void RemoveTag(const FString& key);
2526

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -499,9 +499,9 @@ void FGenericPlatformSentrySubsystem::RemoveUser()
499499
}
500500
}
501501

502-
void FGenericPlatformSentrySubsystem::SetContext(const FString& key, const TMap<FString, FString>& values)
502+
void FGenericPlatformSentrySubsystem::SetContext(const FString& key, const TMap<FString, FSentryVariant>& values)
503503
{
504-
sentry_set_context(TCHAR_TO_UTF8(*key), FGenericPlatformSentryConverters::StringMapToNative(values));
504+
sentry_set_context(TCHAR_TO_UTF8(*key), FGenericPlatformSentryConverters::VariantMapToNative(values));
505505

506506
if (crashReporter)
507507
{

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ class FGenericPlatformSentrySubsystem : public ISentrySubsystem
3333
virtual void CaptureUserFeedback(TSharedPtr<ISentryUserFeedback> userFeedback) override;
3434
virtual void SetUser(TSharedPtr<ISentryUser> user) override;
3535
virtual void RemoveUser() override;
36-
virtual void SetContext(const FString& key, const TMap<FString, FString>& values) override;
36+
virtual void SetContext(const FString& key, const TMap<FString, FSentryVariant>& values) override;
3737
virtual void SetTag(const FString& key, const FString& value) override;
3838
virtual void RemoveTag(const FString& key) override;
3939
virtual void SetLevel(ESentryLevel level) override;

plugin-dev/Source/Sentry/Private/GenericPlatform/Infrastructure/GenericPlatformSentryConverters.cpp

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -361,4 +361,66 @@ ELogVerbosity::Type FGenericPlatformSentryConverters::SentryLevelToLogVerbosity(
361361
return LogVerbosity;
362362
}
363363

364+
TSharedPtr<FJsonValue> FGenericPlatformSentryConverters::VariantToJsonValue(const FSentryVariant& variant)
365+
{
366+
switch (variant.GetType())
367+
{
368+
case ESentryVariantType::Integer:
369+
return MakeShareable(new FJsonValueNumber(variant.GetValue<int32>()));
370+
case ESentryVariantType::Float:
371+
return MakeShareable(new FJsonValueNumber(variant.GetValue<float>()));
372+
case ESentryVariantType::Bool:
373+
return MakeShareable(new FJsonValueBoolean(variant.GetValue<bool>()));
374+
case ESentryVariantType::String:
375+
return MakeShareable(new FJsonValueString(variant.GetValue<FString>()));
376+
case ESentryVariantType::Array:
377+
return VariantArrayToJsonValue(variant.GetValue<TArray<FSentryVariant>>());
378+
case ESentryVariantType::Map:
379+
return VariantMapToJsonValue(variant.GetValue<TMap<FString, FSentryVariant>>());
380+
default:
381+
return MakeShareable(new FJsonValueNull());
382+
}
383+
}
384+
385+
TSharedPtr<FJsonValue> FGenericPlatformSentryConverters::VariantArrayToJsonValue(const TArray<FSentryVariant>& array)
386+
{
387+
TArray<TSharedPtr<FJsonValue>> jsonArray;
388+
389+
for (auto it = array.CreateConstIterator(); it; ++it)
390+
{
391+
const FSentryVariant& variant = *it;
392+
TSharedPtr<FJsonValue> jsonValue = VariantToJsonValue(variant);
393+
if (jsonValue.IsValid())
394+
{
395+
jsonArray.Add(jsonValue);
396+
}
397+
}
398+
399+
return MakeShareable(new FJsonValueArray(jsonArray));
400+
}
401+
402+
TSharedPtr<FJsonValue> FGenericPlatformSentryConverters::VariantMapToJsonValue(const TMap<FString, FSentryVariant>& map)
403+
{
404+
TSharedPtr<FJsonObject> jsonObject = MakeShareable(new FJsonObject);
405+
406+
for (auto it = map.CreateConstIterator(); it; ++it)
407+
{
408+
const FString& key = it.Key();
409+
const FSentryVariant& variant = it.Value();
410+
411+
if (variant.GetType() == ESentryVariantType::Empty)
412+
{
413+
continue;
414+
}
415+
416+
TSharedPtr<FJsonValue> jsonValue = VariantToJsonValue(variant);
417+
if (jsonValue.IsValid())
418+
{
419+
jsonObject->SetField(key, jsonValue);
420+
}
421+
}
422+
423+
return MakeShareable(new FJsonValueObject(jsonObject));
424+
}
425+
364426
#endif

0 commit comments

Comments
 (0)