Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -611,6 +611,9 @@ TSharedPtr<ISentryTransaction> FGenericPlatformSentrySubsystem::StartTransaction
{
if (sentry_transaction_t* nativeTransaction = sentry_transaction_start(platformTransactionContext->GetNativeObject(), sentry_value_new_null()))
{
// TODO: Replace this hack with a proper transaction binding to the current scope
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What does the hack do differently now?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Currently, span/transaction scope binding is hardcoded in the Unreal SDK version used in the demo project. Ideally, we should first introduce an API in sentry-unreal to handle this and then bump the plugin version in this repo accordingly.

sentry_set_transaction_object(nativeTransaction);

return MakeShareable(new FGenericPlatformSentryTransaction(nativeTransaction));
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ TSharedPtr<ISentrySpan> FGenericPlatformSentryTransaction::StartChildSpan(const
{
if (sentry_span_t* nativeSpan = sentry_transaction_start_child(Transaction, TCHAR_TO_ANSI(*operation), TCHAR_TO_ANSI(*description)))
{
// TODO: Replace this hack with a proper span binding to the current scope
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What does the hack do differently now?

sentry_set_span(nativeSpan);
return MakeShareable(new FGenericPlatformSentrySpan(nativeSpan));
}
else
Expand Down
61 changes: 57 additions & 4 deletions Source/SentryTower/SentryTowerGameInstance.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -69,9 +69,7 @@ void USentryTowerGameInstance::BuyUpgrade(const FOnBuyComplete& OnBuyComplete)

USentrySpan* ProcessSpan = CheckoutTransaction->StartChildSpan(TEXT("task"), TEXT("process_upgrade_data"));

TSharedPtr<FJsonObject> UpgradeDataJsonObject = MakeShareable(new FJsonObject());
UpgradeDataJsonObject->SetStringField(TEXT("UpgradeName"), TEXT("NewTower"));
UpgradeDataJsonObject->SetStringField(TEXT("PlayerEmail"), TEXT("[email protected]"));
TSharedPtr<FJsonObject> UpgradeDataJsonObject = BuildCheckoutRequestJson();

FString JsonString;
TSharedRef<TJsonWriter<>> Writer = TJsonWriterFactory<>::Create(&JsonString);
Expand All @@ -85,7 +83,7 @@ void USentryTowerGameInstance::BuyUpgrade(const FOnBuyComplete& OnBuyComplete)
ProcessSpan->Finish();

USentrySpan* CheckoutSpan = CheckoutTransaction->StartChildSpan(TEXT("task"), TEXT("checkout_request"));
FString Domain = TEXT("https://aspnetcore.empower-plant.com");
FString Domain = TEXT("https://flask.empower-plant.com");
FString Endpoint = TEXT("/checkout");
FString CheckoutURL = Domain + Endpoint;

Expand All @@ -96,6 +94,14 @@ void USentryTowerGameInstance::BuyUpgrade(const FOnBuyComplete& OnBuyComplete)
HttpRequest->SetVerb("POST");
HttpRequest->SetHeader(TEXT("Content-Type"), TEXT("application/json"));

FString TraceKey;
FString TraceValue;
CheckoutSpan->GetTrace(TraceKey, TraceValue);

UE_LOG(LogTemp, Log, TEXT("TraceValue - %s"), *TraceValue);

HttpRequest->SetHeader(TraceKey, TraceValue);

HttpRequest->SetContentAsString(JsonString);

HttpRequest->OnProcessRequestComplete().BindLambda([=](FHttpRequestPtr Request, FHttpResponsePtr Response, bool bWasSuccessful)
Expand All @@ -122,3 +128,50 @@ void USentryTowerGameInstance::BuyUpgrade(const FOnBuyComplete& OnBuyComplete)

HttpRequest->ProcessRequest();
}

TSharedPtr<FJsonObject> USentryTowerGameInstance::BuildCheckoutRequestJson()
{
TSharedPtr<FJsonObject> JsonObject = MakeShareable(new FJsonObject());

// Build cart object
TSharedPtr<FJsonObject> CartObject = MakeShareable(new FJsonObject());

// Build items array
TArray<TSharedPtr<FJsonValue>> ItemsArray;
TSharedPtr<FJsonObject> ItemObject = MakeShareable(new FJsonObject());
ItemObject->SetStringField(TEXT("description"), TEXT("The mood ring for plants."));
ItemObject->SetStringField(TEXT("descriptionfull"), TEXT("This is an example of what you can do with just a few things, a little imagination and a happy dream in your heart. I'm a water fanatic. I love water. There's not a thing in the world wrong with washing your brush. Everybody needs a friend. Here we're limited by the time we have."));
ItemObject->SetNumberField(TEXT("id"), 3);
ItemObject->SetStringField(TEXT("img"), TEXT("https://storage.googleapis.com/application-monitoring/mood-planter.jpg"));
ItemObject->SetStringField(TEXT("imgcropped"), TEXT("https://storage.googleapis.com/application-monitoring/mood-planter-cropped.jpg"));
ItemObject->SetNumberField(TEXT("price"), 155);
ItemObject->SetArrayField(TEXT("reviews"), TArray<TSharedPtr<FJsonValue>>());
ItemObject->SetStringField(TEXT("title"), TEXT("Plant Mood"));
ItemsArray.Add(MakeShareable(new FJsonValueObject(ItemObject)));
CartObject->SetArrayField(TEXT("items"), ItemsArray);

// Build quantities object
TSharedPtr<FJsonObject> QuantitiesObject = MakeShareable(new FJsonObject());
QuantitiesObject->SetNumberField(TEXT("3"), 3);
CartObject->SetObjectField(TEXT("quantities"), QuantitiesObject);
CartObject->SetNumberField(TEXT("total"), 465);

// Build form object
TSharedPtr<FJsonObject> FormObject = MakeShareable(new FJsonObject());
FormObject->SetStringField(TEXT("address"), TEXT(""));
FormObject->SetStringField(TEXT("city"), TEXT(""));
FormObject->SetStringField(TEXT("country"), TEXT(""));
FormObject->SetStringField(TEXT("email"), TEXT("[email protected]"));
FormObject->SetStringField(TEXT("firstName"), TEXT(""));
FormObject->SetStringField(TEXT("lastName"), TEXT(""));
FormObject->SetStringField(TEXT("state"), TEXT(""));
FormObject->SetStringField(TEXT("subscribe"), TEXT(""));
FormObject->SetStringField(TEXT("zipCode"), TEXT(""));

// Set all objects to main JSON
JsonObject->SetObjectField(TEXT("cart"), CartObject);
JsonObject->SetObjectField(TEXT("form"), FormObject);
JsonObject->SetStringField(TEXT("validate_inventory"), TEXT("true"));

return JsonObject;
}
3 changes: 3 additions & 0 deletions Source/SentryTower/SentryTowerGameInstance.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,7 @@ class SENTRYTOWER_API USentryTowerGameInstance : public UGameInstance

UFUNCTION(BlueprintCallable, Meta = (AutoCreateRefTerm = "OnBuyComplete"))
void BuyUpgrade(const FOnBuyComplete& OnBuyComplete);

private:
TSharedPtr<FJsonObject> BuildCheckoutRequestJson();
};