|
| 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