Usage

Sentry's SDK hooks into your runtime environment and automatically reports errors, uncaught exceptions, and unhandled rejections as well as other types of errors depending on the platform.

The most common form of capturing is to capture errors. What can be captured as an error varies by platform. In general, if you have something that looks like an exception, it can be captured. For some SDKs, you can also omit the argument to CaptureException and Sentry will attempt to capture the current exception. It is also useful for manual reporting of errors or messages to Sentry.

While capturing an event, you can also record the breadcrumbs that lead up to that event. Breadcrumbs are different from events: they will not create an event in Sentry, but will be buffered until the next event is sent. Learn more about breadcrumbs in our Breadcrumbs documentation.

Another common operation is to capture a bare message. A message is textual information that should be sent to Sentry. Typically, our SDKs don't automatically capture messages, but you can capture them manually.

To simplify creating events, there are shorthand functions that construct prepopulated event objects. The most important one is CaptureMessage. The Level parameter is optional:

Copied
USentrySubsystem* SentrySubsystem = GEngine->GetEngineSubsystem<USentrySubsystem>();

SentrySubsystem->CaptureMessage("Message", ESentryLevel::Info);

There is also the option to configure scope for some specific messages:

Copied
USentrySubsystem* SentrySubsystem = GEngine->GetEngineSubsystem<USentrySubsystem>();

FConfigureScopeDelegate ScopeDelegate;
ScopeDelegate.BindDynamic(this, &USomeClass::HandleScopeDelegate);

SentrySubsystem->CaptureMessageWithScope("Message", ScopeDelegate, ESentryLevel::Info);

// Put scope configuration logic here
void USomeClass::HandleScopeDelegate(USentryScope* Scope)
{
    Scope->SetTagValue("Module", "Test");
    ...
}

The same result can be achieved by calling corresponding functions in blueprint:

Capture message

To create and capture a manual event:

  1. Create an event, USentryEvent. This internally creates an object and initializes it with common event attributes, like timestamp and event_id.
  2. Set custom attributes of the event, like Message or Level.
  3. Send the event to Sentry by invoking the CaptureEvent method USentrySubsystem.

In a simplest case, it looks like this:

Copied
USentrySubsystem* SentrySubsystem = GEngine->GetEngineSubsystem<USentrySubsystem>();

USentryEvent* Event = NewObject<USentryEvent>();
Event->SetMessage("Message");
Event->SetLevel(ESentryLevel::Info);

SentrySubsystem->CaptureEvent(Event);

You can also configure scope for some specific events:

Copied
USentrySubsystem* SentrySubsystem = GEngine->GetEngineSubsystem<USentrySubsystem>();

USentryEvent* Event = NewObject<USentryEvent>();
Event->SetMessage("Message");
Event->SetLevel(ESentryLevel::Info);

FConfigureScopeDelegate ScopeDelegate;
ScopeDelegate.BindDynamic(this, &USomeClass::HandleScopeDelegate);

SentrySubsystem->CaptureEventWithScope(Event, ScopeDelegate, ESentryLevel::Info);

// Put scope configuration logic here
void USomeClass::HandleScopeDelegate(USentryScope* Scope)
{
    Scope->SetTagValue("Module", "Test");
    ...
}

The same result can be achieved by calling corresponding functions in blueprint:

Capture event

For the full list of supported values, check out Event Payloads and linked documents.

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").