Set Up Metrics for Godot EngineNEW
Metrics allow you to send, view, and query counters, gauges, and distributions from your Godot Engine game to track application health and drill down into related traces, logs, and errors.
Metrics for Godot Engine are supported in Sentry Godot SDK version 2.0.0 and above (previously experimental since 1.4.0).
Once metrics are enabled and the SDK is initialized, you can emit metrics using SentrySDK.metrics.
| Type | Use For |
|---|---|
Counter | Events (matches started, items purchased) |
Gauge | Current values (players online, memory usage) |
Distribution | Value ranges (load times, frame times) |
Track the number of times something happens. Each increment adds to a cumulative total:
# Increment by 1 (default)
SentrySDK.metrics.count("match_started")
# Increment by a specific amount with attributes
SentrySDK.metrics.count("in_app_purchase", 1, {"item": "sword_of_fire"})
# Increment by 1 (default)
SentrySDK.metrics.count("match_started")
# Increment by a specific amount with attributes
SentrySDK.metrics.count("in_app_purchase", 1, {"item": "sword_of_fire"})
// Increment by 1
SentrySdk.Metrics.EmitCounter("match_started", 1);
// Increment by a specific amount with attributes
SentrySdk.Metrics.EmitCounter("in_app_purchase", 1, new Dictionary<string, object>
{
["item"] = "sword_of_fire",
});
Track current values at a point in time, like a snapshot. Sentry computes aggregates like min, max, avg, sum, and count:
SentrySDK.metrics.gauge("players_online", lobby.get_player_count())
# With a unit
SentrySDK.metrics.gauge("memory_usage", OS.get_static_memory_usage(), SentryUnit.byte)
SentrySDK.metrics.gauge("players_online", lobby.get_player_count())
# With a unit
SentrySDK.metrics.gauge("memory_usage", OS.get_static_memory_usage(), SentryUnit.byte)
SentrySdk.Metrics.EmitGauge("players_online", lobby.GetPlayerCount());
// With a unit
SentrySdk.Metrics.EmitGauge("memory_usage", (long)OS.GetStaticMemoryUsage(), MeasurementUnit.Information.Byte);
Record numeric values to compute statistical aggregates such as p50, p95, avg, min, and max:
SentrySDK.metrics.distribution("level_load_time", load_time, SentryUnit.millisecond)
SentrySDK.metrics.distribution("level_load_time", load_time, SentryUnit.millisecond)
SentrySdk.Metrics.EmitDistribution("level_load_time", loadTime, MeasurementUnit.Duration.Millisecond);
Add attributes to filter and group metrics in Sentry:
SentrySDK.metrics.count("enemies_spawned", wave_size, {"level": "castle"})
SentrySDK.metrics.distribution("level_load_time", load_time, SentryUnit.millisecond, {
"scene": get_tree().current_scene.name
})
SentrySDK.metrics.count("enemies_spawned", wave_size, {"level": "castle"})
SentrySDK.metrics.distribution("level_load_time", load_time, SentryUnit.millisecond, {
"scene": get_tree().current_scene.name
})
SentrySdk.Metrics.EmitCounter("enemies_spawned", waveSize, new Dictionary<string, object>
{
["level"] = "castle",
});
SentrySdk.Metrics.EmitDistribution("level_load_time", loadTime, MeasurementUnit.Duration.Millisecond, new Dictionary<string, object>
{
["scene"] = GetTree().CurrentScene.Name,
});
Attributes support bool, int, float, and String data types. Other types will be converted to strings.
You can set global attributes that are automatically included in all metrics and logs. This is useful for attaching contextual information that should appear on every metric entry.
# Set global attributes that apply to all metrics and logs
SentrySDK.set_attribute("level", "castle")
SentrySDK.set_attribute("difficulty", "hard")
# All subsequent metrics will include these attributes
SentrySDK.metrics.count("enemy_defeated")
# Clear when returning to the main menu
SentrySDK.remove_attribute("level")
# Set global attributes that apply to all metrics and logs
SentrySDK.set_attribute("level", "castle")
SentrySDK.set_attribute("difficulty", "hard")
# All subsequent metrics will include these attributes
SentrySDK.metrics.count("enemy_defeated")
# Clear when returning to the main menu
SentrySDK.remove_attribute("level")
SentrySdk.Init(options =>
{
options.SetBeforeSendMetric(metric =>
{
metric.SetAttribute("level", "castle");
metric.SetAttribute("difficulty", "hard");
return metric;
});
});
// All subsequent metrics will include these attributes
SentrySdk.Metrics.EmitCounter("enemy_defeated", 1);
The C# SDK doesn't have a scope-level attribute API yet. The before-send hook is the closest equivalent: it applies attributes to every metric.
For gauge and distribution metrics, you can specify a unit to help Sentry display values in a human-readable format. The SentryUnit singleton provides predefined constants for common units. See supported units for the full list.
# Duration units
SentrySDK.metrics.distribution("level_load_time", load_time, SentryUnit.millisecond)
# Information units
SentrySDK.metrics.gauge("memory_usage", OS.get_static_memory_usage(), SentryUnit.byte)
# Custom units (as strings)
SentrySDK.metrics.gauge("items_in_inventory", item_count, "item")
# Duration units
SentrySDK.metrics.distribution("level_load_time", load_time, SentryUnit.millisecond)
# Information units
SentrySDK.metrics.gauge("memory_usage", OS.get_static_memory_usage(), SentryUnit.byte)
# Custom units (as strings)
SentrySDK.metrics.gauge("items_in_inventory", item_count, "item")
// Duration units
SentrySdk.Metrics.EmitDistribution("level_load_time", loadTime, MeasurementUnit.Duration.Millisecond);
// Information units
SentrySdk.Metrics.EmitGauge("memory_usage", (long)OS.GetStaticMemoryUsage(), MeasurementUnit.Information.Byte);
Automatic metrics help you compare frame performance, rendering load, memory use, and multiplayer connectivity across devices and scenes. Automatic metrics are disabled by default and independent of metrics you send manually.
Enable automatic metrics in the Project Settings under Sentry > Auto Metrics, or configure options.auto_metrics during programmatic initialization. See Options for available settings.
Collection pauses when the application loses focus or the operating system pauses it. Headless applications ignore focus changes but still respect OS pause. SceneTree.paused and Engine.time_scale don't affect collection.
Automatic metrics include the following attributes when available, in addition to the default attributes attached to every metric. These aren't added to manually emitted metrics.
| Attribute | Description |
|---|---|
gpu.name | GPU model name; omitted in headless mode |
cpu.cores | Logical CPU core count reported by Godot |
ram.gb | Physical RAM reported by the OS, in GiB; unavailable on Web |
res.x, res.y | Root viewport target width and height in pixels, before window stretching and after 3D scaling; omitted in headless mode |
scene | Full resource path of the current scene, such as res://levels/forest.tscn; falls back to the scene node name if no resource path is available |
Use these attributes to group performance data by hardware, resolution, or scene.
Available since: v2.4.0
Use frame metrics to track frame duration and frame rate across players' devices.
| Metric | Type | Description |
|---|---|---|
game.perf.frame_time | Distribution (ms) | Sampled elapsed time between process callbacks |
game.perf.fps | Gauge | Engine-reported frames per second |
The SDK randomly selects one frame from each collection interval and reports its frame time, including time spent waiting for VSync or frame limiting. Sampling may miss brief hitches.
Available since: v2.4.0
Rendering metrics help identify scenes with high rendering load or video memory use.
| Metric | Type | Description |
|---|---|---|
game.perf.render.draw_calls | Gauge | Draw calls in the last rendered frame |
game.perf.render.primitives | Gauge | Vertices or indices rendered in the last frame, including depth and shadow passes |
game.perf.render.video_mem_used | Gauge (bytes) | Total video memory used, including texture, buffer, and other allocations |
game.perf.render.texture_mem_used | Gauge (bytes) | Texture memory used |
game.perf.render.buffer_mem_used | Gauge (bytes) | Render buffer memory used |
Available since: v2.4.0
Memory metrics help track process memory use and growth in object and node counts. Process memory usage is unavailable on Web; object and node counts are still collected.
| Metric | Type | Description |
|---|---|---|
game.perf.used_memory | Gauge (bytes) | RAM used by the game process |
game.perf.object_count | Gauge | Instantiated objects, including nodes |
game.perf.node_count | Gauge | Nodes in the scene tree, including its root |
Available since: v2.5.0
Network metrics help diagnose multiplayer latency and traffic volume. Network metrics use only the default SceneTree multiplayer API; custom multiplayer APIs assigned to subtrees aren't monitored. Client, server, and mesh sessions are supported. No network metrics are emitted without an active multiplayer connection.
Peer counts work across all transports. All other measurements require ENet.
| Metric | Type | Description |
|---|---|---|
game.perf.net.num_peers | Gauge | Connected remote peers, excluding this instance; server and mesh only |
game.perf.net.ping | Gauge (ms) | Client round-trip time to the server |
game.perf.net.ping_peer_avg | Gauge (ms) | Average peer round-trip time; server and mesh only |
game.perf.net.ping_peer_max | Gauge (ms) | Highest peer round-trip time; server and mesh only |
game.perf.net.packet_loss_ratio | Gauge (ratio) | ENet's estimated outgoing packet-loss ratio toward the server; client only |
game.perf.net.in_rate | Gauge (bytes) | Bytes received per second; client and server only |
game.perf.net.out_rate | Gauge (bytes) | Bytes sent per second; client and server only |
game.perf.net.in_packets | Gauge | UDP datagrams received per second; client and server only |
game.perf.net.out_packets | Gauge | UDP datagrams sent per second; client and server only |
Ping includes Godot's network-processing delays, so it reflects latency experienced by the game rather than network delay alone. Traffic rates include ENet protocol traffic and retransmissions; packet rates count UDP datagrams, not RPCs or game messages.
Traffic collection resets ENet's shared byte and packet counters. Other code reading and resetting those counters affects these measurements, and vice versa.
Configure these properties on options.auto_metrics, or use the corresponding settings in the Project Settings under Sentry > Auto Metrics. Each interval applies only when the corresponding metrics are enabled.
| Option | Default | Available Since | Description |
|---|---|---|---|
enable_frame_metrics | false | 2.4.0 | Collect frame time and FPS |
enable_rendering_metrics | false | 2.4.0 | Collect rendering metrics |
enable_memory_metrics | false | 2.4.0 | Collect memory, object, and node metrics |
enable_network_metrics | false | 2.5.0 | Collect network metrics |
frame_metrics_interval_sec | 1.0 | 2.4.0 | Frame collection interval, in seconds |
rendering_metrics_interval_sec | 1.0 | 2.4.0 | Rendering collection interval, in seconds |
memory_metrics_interval_sec | 60.0 | 2.4.0 | Memory collection interval, in seconds |
network_metrics_interval_sec | 10.0 | 2.5.0 | Network collection interval, in seconds |
For example, enable automatic metrics and adjust the memory interval during initialization:
SentrySDK.init(func(options: SentryOptions) -> void:
options.auto_metrics.enable_frame_metrics = true
options.auto_metrics.enable_rendering_metrics = true
options.auto_metrics.enable_memory_metrics = true
options.auto_metrics.enable_network_metrics = true
options.auto_metrics.memory_metrics_interval_sec = 30.0
)
SentrySDK.init(func(options: SentryOptions) -> void:
options.auto_metrics.enable_frame_metrics = true
options.auto_metrics.enable_rendering_metrics = true
options.auto_metrics.enable_memory_metrics = true
options.auto_metrics.enable_network_metrics = true
options.auto_metrics.memory_metrics_interval_sec = 30.0
)
SentrySdk.Init(options =>
{
options.AutoMetrics.EnableFrameMetrics = true;
options.AutoMetrics.EnableRenderingMetrics = true;
options.AutoMetrics.EnableMemoryMetrics = true;
options.AutoMetrics.EnableNetworkMetrics = true;
options.AutoMetrics.MemoryMetricsIntervalSec = 30.0;
});
The following configuration options are available for Sentry's Application Metrics in Godot Engine:
| Option | Description | Default |
|---|---|---|
| before_send_metric | Callback to modify or filter metrics before sending | None |
To filter metrics or modify them before they are sent to Sentry, you can use the before_send_metric option:
SentrySDK.init(func(options: SentryOptions) -> void:
options.before_send_metric = _before_send_metric
)
func _before_send_metric(metric: SentryMetric) -> SentryMetric:
# Drop debug-only metrics in release builds.
if not OS.is_debug_build() and metric.name.begins_with("debug."):
return null
# Enrich with runtime context.
metric.set_attribute("current_scene", get_tree().current_scene.name)
return metric
SentrySDK.init(func(options: SentryOptions) -> void:
options.before_send_metric = _before_send_metric
)
func _before_send_metric(metric: SentryMetric) -> SentryMetric:
# Drop debug-only metrics in release builds.
if not OS.is_debug_build() and metric.name.begins_with("debug."):
return null
# Enrich with runtime context.
metric.set_attribute("current_scene", get_tree().current_scene.name)
return metric
SentrySdk.Init(options =>
{
options.SetBeforeSendMetric(metric =>
{
// Drop debug-only metrics in release builds.
if (!OS.IsDebugBuild() && metric.Name.StartsWith("debug."))
{
return null;
}
// Enrich with runtime context.
metric.SetAttribute("current_scene", GetTree().CurrentScene.Name);
return metric;
});
});
The before_send_metric callback receives a SentryMetric object, and should return either the same metric object (with or without modifications) or null to discard it.
The Godot SDK automatically attaches the following attributes to every metric:
environment: The environment set in the SDK if defined. This is sent from the SDK assentry.environment.release: The release set in the SDK if defined. This is sent from the SDK assentry.release.sdk.name: The name of the SDK that sent the metric. This is sent from the SDK assentry.sdk.name.sdk.version: The version of the SDK that sent the metric. This is sent from the SDK assentry.sdk.version.
If user information is available in the current scope, the following attributes are added to the metric:
user.id: The user ID.user.name: The username.user.email: The email address.
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").