Custom Instrumentation
Learn how to capture performance data on any action in your app.
To capture transactions and spans customized to your organization's needs, you must first set up tracing.
To instrument certain parts of your code, you can create transactions to capture them.
Copied
USentrySubsystem* SentrySubsystem = GEngine->GetEngineSubsystem<USentrySubsystem>();
// Transactions can be started by providing the name and the operation
USentryTransaction* transaction = SentrySubsystem->StartTransaction(
TEXT("transaction name"),
TEXT("transaction operation")
);
// Transactions can have child spans (and those spans can have child spans as well)
USentrySpan* span = transaction->StartChild(
TEXT("span name"),
TEXT("span description")
);
// ...
// (Perform the operation represented by the span/transaction)
// ...
span->Finish();
transaction->Finish();
For example, if you want to create a transaction for a user interaction in your application:
Copied
// Let's say this method is called in a background thread when a user clicks on the checkout button.
void perform_checkout() {
USentrySubsystem* SentrySubsystem = GEngine->GetEngineSubsystem<USentrySubsystem>();
// This will create a new Transaction for you
USentryTransactionContext* transactionContext = NewObject<USentryTransactionContext>();
transactionContext->Initialize(
TEXT("checkout"),
TEXT("perform-checkout")
);
USentryTransaction* transaction =
SentrySubsystem->StartTransactionWithContext(transactionContext);
// Validate the cart
USentrySpan* validationSpan = transaction->StartChild(
TEXT("validation"),
TEXT("validating shopping cart")
);
validate_shopping_cart(); // Some long process, maybe a sync http request.
validationSpan->Finish();
// Process the order
SentrySpan* processSpan = transaction->StartChild(
TEXT("process"),
TEXT("processing shopping cart")
);
process_shopping_cart(); // Another time consuming process.
processSpan->Finish();
transaction->Finish();
}
This example will send a transaction named checkout
to Sentry. The transaction will contain a validation
span that measures how long validate_shopping_cart()
took and a process
span that measures process_shopping_cart()
. Finally, the transaction->Finish()
call will finish the transaction and send it to Sentry.
In order to use distributed tracing, follow the custom instrumentation steps.
Help improve this content
Our documentation is open source and available on GitHub. Your contributions are welcome, whether fixing a typo (drat!) or suggesting an update ("yeah, this would be better").
Our documentation is open source and available on GitHub. Your contributions are welcome, whether fixing a typo (drat!) or suggesting an update ("yeah, this would be better").