Skip to content

Commit 3f5560d

Browse files
tustanivskyjaffrepaul
authored andcommitted
feat(unreal): Add metrics documentation (#16285)
This PR adds documentation for the Sentry Metrics feature in the Unreal Engine SDK. Related to: - getsentry/sentry-unreal#1214
1 parent 8ee2c3d commit 3f5560d

File tree

7 files changed

+185
-0
lines changed

7 files changed

+185
-0
lines changed
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
---
2+
title: Set Up Metrics
3+
sidebar_title: Metrics
4+
description: "Metrics allow you to send, view and query counters, gauges and distributions from your Unreal Engine game to track application health and drill down into related traces, logs, and errors."
5+
sidebar_order: 5700
6+
beta: true
7+
---
8+
9+
With Sentry Metrics, you can send counters, gauges, and distributions from your Unreal Engine game to Sentry. Once in Sentry, these metrics can be viewed alongside relevant errors, and searched using their individual attributes.
10+
11+
<Alert>
12+
This feature is currently in open beta. Features in beta are still in progress
13+
and may have bugs.
14+
</Alert>
15+
16+
## Requirements
17+
18+
<PlatformContent includePath="metrics/requirements" />
19+
20+
## Setup
21+
22+
<PlatformContent includePath="metrics/setup" />
23+
24+
## Usage
25+
26+
<PlatformContent includePath="metrics/usage" />
27+
28+
## Options
29+
30+
<PlatformContent includePath="metrics/options" />
31+
32+
## Default Attributes
33+
34+
<PlatformContent includePath="metrics/default-attributes" />

docs/product/explore/metrics/getting-started/index.mdx

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -306,6 +306,14 @@ To set up Sentry Metrics, use the links below for supported SDKs. After it's bee
306306
url="/platforms/go/metrics/"
307307
/>
308308

309+
### Gaming
310+
311+
- <LinkWithPlatformIcon
312+
platform="unreal"
313+
label="Unreal Engine"
314+
url="/platforms/unreal/metrics/"
315+
/>
316+
309317
## Upcoming SDKs
310318

311319
We're actively working on adding Metrics functionality to additional SDKs. Check out these GitHub issues for the latest updates:
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
The Unreal Engine SDK automatically attaches the following attributes to every metric:
2+
3+
<Include name="metrics/default-attributes/core" />
4+
5+
<Include name="metrics/default-attributes/user" />
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
The following configuration options are available for Sentry Metrics in Unreal Engine:
2+
3+
| Option | Description | Default |
4+
|--------|-------------|---------|
5+
| **Enable Metrics** | Master toggle for the metrics feature | `false` |
6+
| **Before Metric Handler** | Handler to modify or filter metrics before sending | None |
7+
8+
### Before-Metric Handler
9+
10+
To filter metrics or modify them before they are sent to Sentry, create a custom before-metric handler class:
11+
12+
```cpp
13+
UCLASS()
14+
class UCustomMetricFilter : public USentryBeforeMetricHandler
15+
{
16+
GENERATED_BODY()
17+
public:
18+
virtual USentryMetric* HandleBeforeMetric_Implementation(USentryMetric* Metric) override
19+
{
20+
// Drop metrics with specific names
21+
if (Metric->GetName().Contains(TEXT("debug")))
22+
{
23+
return nullptr; // Return null to prevent sending
24+
}
25+
26+
// Modify metric attributes
27+
Metric->SetAttribute(TEXT("build"), FSentryVariant(TEXT("production")));
28+
29+
return Metric; // Return the metric to send it
30+
}
31+
};
32+
```
33+
34+
Configure the handler in project settings under **Hooks > Custom `beforeMetric` event handler**, or set it programmatically:
35+
36+
```cpp
37+
SentrySubsystem->InitializeWithSettings(FConfigureSettingsNativeDelegate::CreateLambda([=](USentrySettings* Settings)
38+
{
39+
Settings->EnableMetrics = true;
40+
Settings->BeforeMetricHandler = UCustomMetricFilter::StaticClass();
41+
}));
42+
```
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Metrics for Unreal Engine are supported in Sentry Unreal Engine SDK version `1.7.0` and above.
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
To enable metrics in your Unreal Engine project, you need to configure the Sentry SDK with metrics enabled.
2+
3+
### Project Settings Configuration
4+
5+
1. Open your project settings: **Project Settings > Plugins > Sentry**
6+
2. Check the **Enable Metrics** option
7+
8+
### Programmatic Configuration
9+
10+
Alternatively, you can enable metrics programmatically when initializing the SDK:
11+
12+
```cpp
13+
#include "SentrySubsystem.h"
14+
15+
void ConfigureSentryWithMetrics()
16+
{
17+
USentrySubsystem* SentrySubsystem = GEngine->GetEngineSubsystem<USentrySubsystem>();
18+
19+
SentrySubsystem->InitializeWithSettings(FConfigureSettingsNativeDelegate::CreateLambda([=](USentrySettings* Settings)
20+
{
21+
Settings->EnableMetrics = true;
22+
}));
23+
}
24+
```
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
Once metrics are enabled, you can emit metrics using the Sentry subsystem.
2+
3+
### Metric Types
4+
5+
| Type | Use For |
6+
| -------------- | -------------------------------------------- |
7+
| `Counter` | Events (orders, clicks, API calls) |
8+
| `Gauge` | Current values (queue depth, connections) |
9+
| `Distribution` | Value ranges (response times, payload sizes) |
10+
11+
### Counters
12+
13+
Track the number of times something happens:
14+
15+
```cpp
16+
#include "SentrySubsystem.h"
17+
18+
USentrySubsystem* SentrySubsystem = GEngine->GetEngineSubsystem<USentrySubsystem>();
19+
20+
SentrySubsystem->AddCount(TEXT("api.requests"), 1);
21+
```
22+
23+
### Gauges
24+
25+
Track current values that can go up or down:
26+
27+
```cpp
28+
SentrySubsystem->AddGauge(TEXT("active_connections"), 42, USentryUnitHelper::MakeSentryUnit(ESentryUnit::None));
29+
```
30+
31+
### Distributions
32+
33+
Track a range of values (e.g., response times):
34+
35+
```cpp
36+
SentrySubsystem->AddDistribution(TEXT("response.time"), 150.5f, USentryUnitHelper::MakeSentryUnit(ESentryUnit::Millisecond));
37+
```
38+
39+
### Custom Attributes
40+
41+
Add attributes to filter and group metrics in Sentry:
42+
43+
```cpp
44+
TMap<FString, FSentryVariant> Attributes;
45+
Attributes.Add(TEXT("endpoint"), FSentryVariant(TEXT("/api/orders")));
46+
Attributes.Add(TEXT("region"), FSentryVariant(TEXT("us-west")));
47+
48+
SentrySubsystem->AddCountWithAttributes(TEXT("api.calls"), 1, Attributes);
49+
```
50+
51+
All metric methods have a `WithAttributes` variant:
52+
- `AddCountWithAttributes()`
53+
- `AddDistributionWithAttributes()`
54+
- `AddGaugeWithAttributes()`
55+
56+
### Units
57+
58+
For gauge and distribution metrics, specify a unit to help Sentry display values in a human-readable format. The SDK provides the `ESentryUnit` enum with predefined units for duration, information, and fraction categories:
59+
60+
```cpp
61+
// Using predefined units
62+
SentrySubsystem->AddGauge(TEXT("memory.usage"), 1024.0f, USentryUnitHelper::MakeSentryUnit(ESentryUnit::Byte));
63+
SentrySubsystem->AddDistribution(TEXT("latency"), 42.5f, USentryUnitHelper::MakeSentryUnit(ESentryUnit::Millisecond));
64+
65+
// Using a custom unit
66+
SentrySubsystem->AddDistribution(TEXT("frame.rate"), 60.0f, USentryUnitHelper::MakeSentryCustomUnit(TEXT("fps")));
67+
```
68+
69+
### Blueprint Support
70+
71+
You can also emit metrics from Blueprints by calling the **Add Count**, **Add Distribution**, or **Add Gauge** nodes on the Sentry subsystem. Use the **Make Sentry Unit** node to specify measurement units.

0 commit comments

Comments
 (0)