Skip to content

Commit c7b6130

Browse files
tustanivskygetsentry-bot
authored andcommitted
Add traces sampling function support for Windows and Linux (#1057)
* Rework creating transaction with options * Add trace sampler support for Windows/Linux * Format code * Move global ref under platform define * Clean up * Update changelog * Update package snapshot * Reset global static pointer on subsystem close * Remove static global subsystem pointer * Format code * Add engine null check * Format code * Add tests * Update packeage snapshot * Format code --------- Co-authored-by: Sentry Github Bot <bot+github-bot@sentry.io>
1 parent 2b6c58b commit c7b6130

32 files changed

+386
-38
lines changed

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,14 @@
1010
- `CaptureUserFeedback` function in `SentrySubsystem` replaced with `CaptureFeedback`
1111
- `CreateSentryUserFeedback` function in `SentryLibrary` replaced with `CreateSentryFeedback`
1212
- On Windows and Linux, `ToString` function of `SentryId` class now returns the ID without dashes
13+
- `StartTransactionWithContextAndOptions` function in `SentrySubsystem` now accepts `FSentryTransactionOptions` struct instead of string map
14+
- `GetCustomSamplingContext` function in `SentrySamplingContext` now returns `TMap<FString, FSentryVariant>` instead of string map
1315

1416
### Features
1517

1618
- Add functionality to give/revoke user consent for crash uploads ([#1053](https://github.com/getsentry/sentry-unreal/pull/1053))
1719
- Add new API for capturing user feedback ([#1051](https://github.com/getsentry/sentry-unreal/pull/1051))
20+
- Add Traces sampling function support for Windows and Linux ([#1057](https://github.com/getsentry/sentry-unreal/pull/1057))
1821
- Read `DSN`, `Environment` and `Release` options from environment variables ([#1054](https://github.com/getsentry/sentry-unreal/pull/1054))
1922

2023
### Dependencies

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,15 +24,15 @@ TSharedPtr<ISentryTransactionContext> FAndroidSentrySamplingContext::GetTransact
2424
return MakeShareable(new FAndroidSentryTransactionContext(*transactionContext));
2525
}
2626

27-
TMap<FString, FString> FAndroidSentrySamplingContext::GetCustomSamplingContext() const
27+
TMap<FString, FSentryVariant> FAndroidSentrySamplingContext::GetCustomSamplingContext() const
2828
{
2929
auto customSamplingContext = CallObjectMethod<jobject>(GetCustomSamplingContextMethod);
3030
if (!customSamplingContext)
31-
return TMap<FString, FString>();
31+
return TMap<FString, FSentryVariant>();
3232

3333
FSentryJavaObjectWrapper NativeCustomSamplingContext(SentryJavaClasses::CustomSamplingContext, *customSamplingContext);
3434
FSentryJavaMethod GetDataMethod = NativeCustomSamplingContext.GetMethod("getData", "()Ljava/util/Map;");
3535

3636
auto data = NativeCustomSamplingContext.CallObjectMethod<jobject>(GetDataMethod);
37-
return FAndroidSentryConverters::StringMapToUnreal(*data);
37+
return FAndroidSentryConverters::VariantMapToUnreal(*data);
3838
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ class FAndroidSentrySamplingContext : public ISentrySamplingContext, public FSen
1414
void SetupClassMethods();
1515

1616
virtual TSharedPtr<ISentryTransactionContext> GetTransactionContext() const override;
17-
virtual TMap<FString, FString> GetCustomSamplingContext() const override;
17+
virtual TMap<FString, FSentryVariant> GetCustomSamplingContext() const override;
1818

1919
private:
2020
FSentryJavaMethod GetTransactionContextMethod;

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -297,12 +297,12 @@ TSharedPtr<ISentryTransaction> FAndroidSentrySubsystem::StartTransactionWithCont
297297
return StartTransactionWithContext(context);
298298
}
299299

300-
TSharedPtr<ISentryTransaction> FAndroidSentrySubsystem::StartTransactionWithContextAndOptions(TSharedPtr<ISentryTransactionContext> context, const TMap<FString, FString>& options)
300+
TSharedPtr<ISentryTransaction> FAndroidSentrySubsystem::StartTransactionWithContextAndOptions(TSharedPtr<ISentryTransactionContext> context, const FSentryTransactionOptions& options)
301301
{
302302
TSharedPtr<FAndroidSentryTransactionContext> transactionContextAndroid = StaticCastSharedPtr<FAndroidSentryTransactionContext>(context);
303303

304304
TSharedPtr<FAndroidSentryTransactionOptions> transactionOptionsAndroid = MakeShareable(new FAndroidSentryTransactionOptions());
305-
transactionOptionsAndroid->SetCustomSamplingContext(options);
305+
transactionOptionsAndroid->SetCustomSamplingContext(options.CustomSamplingContext);
306306

307307
auto transaction = FSentryJavaObjectWrapper::CallStaticObjectMethod<jobject>(SentryJavaClasses::Sentry, "startTransaction", "(Lio/sentry/TransactionContext;Lio/sentry/TransactionOptions;)Lio/sentry/ITransaction;",
308308
transactionContextAndroid->GetJObject(), transactionOptionsAndroid->GetJObject());

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ class FAndroidSentrySubsystem : public ISentrySubsystem
3737
virtual TSharedPtr<ISentryTransaction> StartTransaction(const FString& name, const FString& operation) override;
3838
virtual TSharedPtr<ISentryTransaction> StartTransactionWithContext(TSharedPtr<ISentryTransactionContext> context) override;
3939
virtual TSharedPtr<ISentryTransaction> StartTransactionWithContextAndTimestamp(TSharedPtr<ISentryTransactionContext> context, int64 timestamp) override;
40-
virtual TSharedPtr<ISentryTransaction> StartTransactionWithContextAndOptions(TSharedPtr<ISentryTransactionContext> context, const TMap<FString, FString>& options) override;
40+
virtual TSharedPtr<ISentryTransaction> StartTransactionWithContextAndOptions(TSharedPtr<ISentryTransactionContext> context, const FSentryTransactionOptions& options) override;
4141
virtual TSharedPtr<ISentryTransactionContext> ContinueTrace(const FString& sentryTrace, const TArray<FString>& baggageHeaders) override;
4242

4343
virtual void HandleAssert() override;

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,14 @@ void FAndroidSentryTransactionOptions::SetupClassMethods()
1616
SetCustomSamplingContextMethod = GetMethod("setCustomSamplingContext", "(Lio/sentry/CustomSamplingContext;)V");
1717
}
1818

19-
void FAndroidSentryTransactionOptions::SetCustomSamplingContext(const TMap<FString, FString>& data)
19+
void FAndroidSentryTransactionOptions::SetCustomSamplingContext(const TMap<FString, FSentryVariant>& data)
2020
{
2121
FSentryJavaObjectWrapper NativeCustomSamplingContext(SentryJavaClasses::CustomSamplingContext, "()V");
2222
FSentryJavaMethod SetMethod = NativeCustomSamplingContext.GetMethod("set", "(Ljava/lang/String;Ljava/lang/Object;)V");
2323

2424
for (const auto& dataItem : data)
2525
{
26-
NativeCustomSamplingContext.CallMethod<void>(SetMethod, *GetJString(dataItem.Key), *GetJString(dataItem.Value));
26+
NativeCustomSamplingContext.CallMethod<void>(SetMethod, *GetJString(dataItem.Key), FAndroidSentryConverters::VariantToNative(dataItem.Value)->GetJObject());
2727
}
2828

2929
CallMethod<void>(SetCustomSamplingContextMethod, NativeCustomSamplingContext.GetJObject());

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
#pragma once
44

5+
#include "SentryVariant.h"
6+
57
#include "Infrastructure/AndroidSentryJavaObjectWrapper.h"
68

79
class FAndroidSentryTransactionOptions : public FSentryJavaObjectWrapper
@@ -11,7 +13,7 @@ class FAndroidSentryTransactionOptions : public FSentryJavaObjectWrapper
1113

1214
void SetupClassMethods();
1315

14-
void SetCustomSamplingContext(const TMap<FString, FString>& data);
16+
void SetCustomSamplingContext(const TMap<FString, FSentryVariant>& data);
1517

1618
private:
1719
FSentryJavaMethod SetCustomSamplingContextMethod;

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,9 @@ TSharedPtr<ISentryTransactionContext> FAppleSentrySamplingContext::GetTransactio
2222
return MakeShareable(new FAppleSentryTransactionContext(SamplingContext.transactionContext));
2323
}
2424

25-
TMap<FString, FString> FAppleSentrySamplingContext::GetCustomSamplingContext() const
25+
TMap<FString, FSentryVariant> FAppleSentrySamplingContext::GetCustomSamplingContext() const
2626
{
27-
return FAppleSentryConverters::StringMapToUnreal(SamplingContext.customSamplingContext);
27+
return FAppleSentryConverters::VariantMapToUnreal(SamplingContext.customSamplingContext);
2828
}
2929

3030
SentrySamplingContext* FAppleSentrySamplingContext::GetNativeObject()

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ class FAppleSentrySamplingContext : public ISentrySamplingContext
1313
virtual ~FAppleSentrySamplingContext() override;
1414

1515
virtual TSharedPtr<ISentryTransactionContext> GetTransactionContext() const override;
16-
virtual TMap<FString, FString> GetCustomSamplingContext() const override;
16+
virtual TMap<FString, FSentryVariant> GetCustomSamplingContext() const override;
1717

1818
SentrySamplingContext* GetNativeObject();
1919

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -387,12 +387,12 @@ TSharedPtr<ISentryTransaction> FAppleSentrySubsystem::StartTransactionWithContex
387387
return StartTransactionWithContext(context);
388388
}
389389

390-
TSharedPtr<ISentryTransaction> FAppleSentrySubsystem::StartTransactionWithContextAndOptions(TSharedPtr<ISentryTransactionContext> context, const TMap<FString, FString>& options)
390+
TSharedPtr<ISentryTransaction> FAppleSentrySubsystem::StartTransactionWithContextAndOptions(TSharedPtr<ISentryTransactionContext> context, const FSentryTransactionOptions& options)
391391
{
392392
TSharedPtr<FAppleSentryTransactionContext> transactionContextIOS = StaticCastSharedPtr<FAppleSentryTransactionContext>(context);
393393

394394
id<SentrySpan> transaction = [SENTRY_APPLE_CLASS(SentrySDK) startTransactionWithContext:transactionContextIOS->GetNativeObject()
395-
customSamplingContext:FAppleSentryConverters::StringMapToNative(options)];
395+
customSamplingContext:FAppleSentryConverters::VariantMapToNative(options.CustomSamplingContext)];
396396

397397
return MakeShareable(new FAppleSentryTransaction(transaction));
398398
}

0 commit comments

Comments
 (0)