forked from getsentry/unreal-tower
-
Notifications
You must be signed in to change notification settings - Fork 2
Fix distributed tracing example #5
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Draft
tustanivsky
wants to merge
3
commits into
main
Choose a base branch
from
fix/distributed-tracing
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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); | ||
|
@@ -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; | ||
|
||
|
@@ -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) | ||
|
@@ -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; | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.