Skip to content

Commit df4cbe2

Browse files
committed
Revert scope data caching on Unreal's side
1 parent 7a0f5dc commit df4cbe2

File tree

4 files changed

+115
-40
lines changed

4 files changed

+115
-40
lines changed

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

Lines changed: 87 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,7 @@
1414
#if USE_SENTRY_NATIVE
1515

1616
FGenericPlatformSentryScope::FGenericPlatformSentryScope()
17-
{
18-
Scope = sentry_local_scope_new();
19-
}
20-
21-
FGenericPlatformSentryScope::FGenericPlatformSentryScope(sentry_scope_t* scope)
22-
: Scope(scope)
17+
: Level(ESentryLevel::Debug)
2318
{
2419
}
2520

@@ -29,11 +24,17 @@ FGenericPlatformSentryScope::~FGenericPlatformSentryScope()
2924

3025
void FGenericPlatformSentryScope::AddBreadcrumb(TSharedPtr<ISentryBreadcrumb> breadcrumb)
3126
{
32-
sentry_scope_add_breadcrumb(Scope, StaticCastSharedPtr<FGenericPlatformSentryBreadcrumb>(breadcrumb)->GetNativeObject());
27+
if (Breadcrumbs.Num() >= FSentryModule::Get().GetSettings()->MaxBreadcrumbs)
28+
{
29+
Breadcrumbs.PopFront();
30+
}
31+
32+
Breadcrumbs.Add(StaticCastSharedPtr<FGenericPlatformSentryBreadcrumb>(breadcrumb));
3333
}
3434

3535
void FGenericPlatformSentryScope::ClearBreadcrumbs()
3636
{
37+
Breadcrumbs.Empty();
3738
}
3839

3940
void FGenericPlatformSentryScope::AddAttachment(TSharedPtr<ISentryAttachment> attachment)
@@ -48,29 +49,31 @@ void FGenericPlatformSentryScope::ClearAttachments()
4849

4950
void FGenericPlatformSentryScope::SetTagValue(const FString& key, const FString& value)
5051
{
51-
sentry_scope_set_tag(Scope, TCHAR_TO_UTF8(*key), TCHAR_TO_UTF8(*value));
52+
Tags.Add(key, value);
53+
5254
}
5355

5456
FString FGenericPlatformSentryScope::GetTagValue(const FString& key) const
5557
{
56-
return FString();
58+
if (!Tags.Contains(key))
59+
return FString();
60+
61+
return Tags[key];
5762
}
5863

5964
void FGenericPlatformSentryScope::RemoveTag(const FString& key)
6065
{
66+
Tags.Remove(key);
6167
}
6268

6369
void FGenericPlatformSentryScope::SetTags(const TMap<FString, FString>& tags)
6470
{
65-
for (const auto& tagItem : tags)
66-
{
67-
SetTagValue(tagItem.Key, tagItem.Value);
68-
}
71+
Tags.Append(tags);
6972
}
7073

7174
TMap<FString, FString> FGenericPlatformSentryScope::GetTags() const
7275
{
73-
return TMap<FString, FString>();
76+
return Tags;
7477
}
7578

7679
void FGenericPlatformSentryScope::SetDist(const FString& dist)
@@ -95,62 +98,120 @@ FString FGenericPlatformSentryScope::GetEnvironment() const
9598

9699
void FGenericPlatformSentryScope::SetFingerprint(const TArray<FString>& fingerprint)
97100
{
98-
sentry_scope_set_fingerprints(Scope, FGenericPlatformSentryConverters::StringArrayToNative(fingerprint));
101+
Fingerprint = fingerprint;
99102
}
100103

101104
TArray<FString> FGenericPlatformSentryScope::GetFingerprint() const
102105
{
103-
return TArray<FString>();
106+
return Fingerprint;
104107
}
105108

106109
void FGenericPlatformSentryScope::SetLevel(ESentryLevel level)
107110
{
108-
sentry_scope_set_level(Scope, FGenericPlatformSentryConverters::SentryLevelToNative(level));
111+
Level = level;
109112
}
110113

111114
ESentryLevel FGenericPlatformSentryScope::GetLevel() const
112115
{
113-
return ESentryLevel::Debug;
116+
return Level;
114117
}
115118

116119
void FGenericPlatformSentryScope::SetContext(const FString& key, const TMap<FString, FString>& values)
117120
{
118-
sentry_scope_set_context(Scope, TCHAR_TO_UTF8(*key), FGenericPlatformSentryConverters::StringMapToNative(values));
121+
Contexts.Add(key, values);
119122
}
120123

121124
void FGenericPlatformSentryScope::RemoveContext(const FString& key)
122125
{
126+
if (!Contexts.Contains(key))
127+
return;
128+
129+
Contexts.Remove(key);
123130
}
124131

125132
void FGenericPlatformSentryScope::SetExtraValue(const FString& key, const FString& value)
126133
{
127-
sentry_scope_set_extra(Scope, TCHAR_TO_UTF8(*key), sentry_value_new_string(TCHAR_TO_UTF8(*value)));
134+
Extra.Add(key, value);
128135
}
129136

130137
FString FGenericPlatformSentryScope::GetExtraValue(const FString& key) const
131138
{
132-
return FString();
139+
if (!Extra.Contains(key))
140+
return FString();
141+
142+
return Extra[key];
133143
}
134144

135145
void FGenericPlatformSentryScope::RemoveExtra(const FString& key)
136146
{
147+
if (!Extra.Contains(key))
148+
return;
149+
150+
Extra.Remove(key);
137151
}
138152

139153
void FGenericPlatformSentryScope::SetExtras(const TMap<FString, FString>& extras)
140154
{
141-
for (const auto& extraItem : extras)
142-
{
143-
SetExtraValue(extraItem.Key, extraItem.Value);
144-
}
155+
Extra.Append(extras);
145156
}
146157

147158
TMap<FString, FString> FGenericPlatformSentryScope::GetExtras() const
148159
{
149-
return TMap<FString, FString>();
160+
return Extra;
150161
}
151162

152163
void FGenericPlatformSentryScope::Clear()
153164
{
165+
Dist = FString();
166+
Environment = FString();
167+
Fingerprint.Empty();
168+
Tags.Empty();
169+
Extra.Empty();
170+
Contexts.Empty();
171+
Breadcrumbs.Empty();
172+
Level = ESentryLevel::Debug;}
173+
174+
void FGenericPlatformSentryScope::Apply(sentry_scope_t* scope)
175+
{
176+
if (!Breadcrumbs.IsEmpty())
177+
{
178+
for (const auto& Breadcrumb : Breadcrumbs)
179+
{
180+
sentry_value_t nativeBreadcrumb = Breadcrumb->GetNativeObject();
181+
sentry_scope_add_breadcrumb(scope, nativeBreadcrumb);
182+
}
183+
}
184+
185+
if (Fingerprint.Num() > 0)
186+
{
187+
sentry_scope_set_fingerprints(scope, FGenericPlatformSentryConverters::StringArrayToNative(Fingerprint));
188+
}
189+
190+
if (Tags.Num() > 0)
191+
{
192+
for (const auto& TagItem : Tags)
193+
{
194+
sentry_scope_set_tag(scope, TCHAR_TO_UTF8(*TagItem.Key), TCHAR_TO_UTF8(*TagItem.Value));
195+
}
196+
}
197+
198+
if (Extra.Num() > 0)
199+
{
200+
for (const auto& ExtraItem : Extra)
201+
{
202+
sentry_scope_set_extra(scope, TCHAR_TO_UTF8(*ExtraItem.Key), sentry_value_new_string(TCHAR_TO_UTF8(*ExtraItem.Value)));
203+
}
204+
}
205+
206+
if (Contexts.Num() > 0)
207+
{
208+
for (const auto& ContextsItem : Contexts)
209+
{
210+
sentry_scope_set_context(scope, TCHAR_TO_UTF8(*ContextsItem.Key), FGenericPlatformSentryConverters::StringMapToNative(ContextsItem.Value));
211+
}
212+
}
213+
214+
sentry_scope_set_level(scope, FGenericPlatformSentryConverters::SentryLevelToNative(Level));
154215
}
155216

156217
#endif

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

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

33
#pragma once
44

5+
#include "Containers/RingBuffer.h"
56
#include "Convenience/GenericPlatformSentryInclude.h"
67

78
#include "Interface/SentryScopeInterface.h"
@@ -15,7 +16,6 @@ class FGenericPlatformSentryScope : public ISentryScope
1516
{
1617
public:
1718
FGenericPlatformSentryScope();
18-
FGenericPlatformSentryScope(sentry_scope_t* scope);
1919
virtual ~FGenericPlatformSentryScope() override;
2020

2121
virtual void AddBreadcrumb(TSharedPtr<ISentryBreadcrumb> breadcrumb) override;
@@ -44,8 +44,22 @@ class FGenericPlatformSentryScope : public ISentryScope
4444
virtual TMap<FString, FString> GetExtras() const override;
4545
virtual void Clear() override;
4646

47+
void Apply(sentry_scope_t* scope);
48+
4749
private:
48-
sentry_scope_t* Scope;
50+
FString Dist;
51+
FString Environment;
52+
53+
TArray<FString> Fingerprint;
54+
55+
TMap<FString, FString> Tags;
56+
TMap<FString, FString> Extra;
57+
58+
TMap<FString, TMap<FString, FString>> Contexts;
59+
60+
TRingBuffer<TSharedPtr<FGenericPlatformSentryBreadcrumb>> Breadcrumbs;
61+
62+
ESentryLevel Level;
4963
};
5064

5165
typedef FGenericPlatformSentryScope FPlatformSentryScope;

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

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -403,8 +403,9 @@ TSharedPtr<ISentryId> FGenericPlatformSentrySubsystem::CaptureMessageWithScope(c
403403

404404
sentry_scope_t* scope = sentry_local_scope_new();
405405

406-
TSharedPtr<FGenericPlatformSentryScope> NewLocalScope = MakeShareable(new FGenericPlatformSentryScope(scope));
406+
TSharedPtr<FGenericPlatformSentryScope> NewLocalScope = MakeShareable(new FGenericPlatformSentryScope());
407407
onConfigureScope.ExecuteIfBound(NewLocalScope);
408+
NewLocalScope->Apply(scope);
408409

409410
sentry_uuid_t id = sentry_capture_event_with_scope(nativeEvent, scope);
410411
return MakeShareable(new FGenericPlatformSentryId(id));
@@ -438,8 +439,9 @@ TSharedPtr<ISentryId> FGenericPlatformSentrySubsystem::CaptureEventWithScope(TSh
438439

439440
sentry_scope_t* scope = sentry_local_scope_new();
440441

441-
TSharedPtr<FGenericPlatformSentryScope> NewLocalScope = MakeShareable(new FGenericPlatformSentryScope(scope));
442+
TSharedPtr<FGenericPlatformSentryScope> NewLocalScope = MakeShareable(new FGenericPlatformSentryScope());
442443
onScopeConfigure.ExecuteIfBound(NewLocalScope);
444+
NewLocalScope->Apply(scope);
443445

444446
sentry_uuid_t id = sentry_capture_event_with_scope(nativeEvent, scope);
445447
return MakeShareable(new FGenericPlatformSentryId(id));

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

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,6 @@ void SentryScopeSpec::Define()
5454
TestFingerprint.Add(TEXT("F3"));
5555
});
5656

57-
#if (PLATFORM_APPLE || PLATFORM_ANDROID) && !USE_SENTRY_NATIVE
5857
Describe("Scope tags", [this]()
5958
{
6059
It("should persist value when single item set", [this]()
@@ -116,13 +115,13 @@ void SentryScopeSpec::Define()
116115
It("should persist their values", [this]()
117116
{
118117
SentryScope->SetLevel(ESentryLevel::Fatal);
119-
SentryScope->SetDist(TestDist);
120-
SentryScope->SetEnvironment(TestEnvironment);
118+
// SentryScope->SetDist(TestDist);
119+
// SentryScope->SetEnvironment(TestEnvironment);
121120
SentryScope->SetFingerprint(TestFingerprint);
122121

123122
TestEqual("Scope level", SentryScope->GetLevel(), ESentryLevel::Fatal);
124-
TestEqual("Scope dist", SentryScope->GetDist(), TestDist);
125-
TestEqual("Scope environment", SentryScope->GetEnvironment(), TestEnvironment);
123+
// TestEqual("Scope dist", SentryScope->GetDist(), TestDist);
124+
// TestEqual("Scope environment", SentryScope->GetEnvironment(), TestEnvironment);
126125
TestEqual("Scope fingerprint", SentryScope->GetFingerprint(), TestFingerprint);
127126
});
128127
});
@@ -131,22 +130,21 @@ void SentryScopeSpec::Define()
131130
{
132131
It("should be possible to clear", [this]()
133132
{
134-
SentryScope->SetDist(TestDist);
135-
SentryScope->SetEnvironment(TestEnvironment);
133+
// SentryScope->SetDist(TestDist);
134+
// SentryScope->SetEnvironment(TestEnvironment);
136135
SentryScope->SetFingerprint(TestFingerprint);
137136
SentryScope->SetTags(TestTags);
138137
SentryScope->SetExtras(TestExtras);
139138

140139
SentryScope->Clear();
141140

142-
TestTrue("Scope dist", SentryScope->GetDist().IsEmpty());
143-
TestTrue("Scope environment", SentryScope->GetEnvironment().IsEmpty());
141+
// TestTrue("Scope dist", SentryScope->GetDist().IsEmpty());
142+
// TestTrue("Scope environment", SentryScope->GetEnvironment().IsEmpty());
144143
TestTrue("Scope fingerprint", SentryScope->GetFingerprint().Num() == 0);
145144
TestTrue("Scope tags", SentryScope->GetTags().Num() == 0);
146145
TestTrue("Scope extras", SentryScope->GetExtras().Num() == 0);
147146
});
148147
});
149-
#endif
150148

151149
#if (PLATFORM_MICROSOFT || PLATFORM_LINUX) && USE_SENTRY_NATIVE
152150
Describe("Scope params", [this]()

0 commit comments

Comments
 (0)