boltZharp Docs
sports_esportsSDKs

Godot

The Zharp addon reports a Godot game's script and engine errors with their backtraces and the code that ran, engine crashes on the next launch, hangs, and the session, scene and player they happened to.

info
Zharp for Godot 0.1.0

This SDK is new, and its API may still change before 1.0. Requires Godot 4.5 or later (GDScript; C# with Zharp.Godot).

Install

In the project folder (the one with project.godot):

npm init zharp@latest

It copies the addon into addons/zharp, enables it and writes your key. By hand: install Zharp from the editor's AssetLib tab (or copy addons/zharp from github.com/zharp-io/zharp-godot), then tick it in Project Settings → Plugins. It's plain GDScript: nothing to compile, on every platform Godot exports to, the web included.

Initialize

Put the app's key in Project Settings → Zharp, or straight into project.godot. The Zharp autoload the plugin adds starts with the game; there is no code to write.

; project.godot
[zharp]
key="zpk_…"
service="shop-quest"
environment="production"

The key is safe to ship in the game: it can only send. Each setting can also come from the environment (ZHARP_KEY, ZHARP_ENVIRONMENT…) on desktop. To start it yourself — with a key fetched at runtime, say — turn zharp/auto_start off:

Zharp.start({"key": key, "environment": "beta"})   # with zharp/auto_start off

Logs

Zharp.log_info("Checkout opened", {"items": 3})   # also log_debug, log_warn, log_error

Each log carries the session, player, device, scene and trace. By default only what you send with Zharp.log_* goes to Zharp. Turn zharp/logs on (or set ZHARP_LOGS=true) to also send what the game prints: print() as info, printerr() as errors, warnings as warnings.

Logs only

If you only want logs, turn tracing off. Logs, errors, and the user and session they belong to are still sent; no spans are recorded and no trace headers are added to outgoing requests.

; project.godot
[zharp]
key="zpk_…"
service="shop-quest"
tracing=false

The logs show on the Logs page under the service name, and on the app's Logs tab with the user and session of each line. The key comes from an app — see Get a key. To add tracing later, remove the option; nothing else changes.

Errors

The addon registers a Logger (the class Godot 4.5 added), so every script error, push_error() and engine error reaches Zharp with its backtrace, and the lines around your scripts' frames:

ScriptError: Invalid call. Nonexistent function 'append' in base 'Nil'.
[0] add_to_cart (res://shop/checkout.gd:36)
[1] _ready (res://shop/checkout.gd:12)
  • Each is sent once: the same error from the same place at most once a minute, so an error in _process doesn't send sixty a second.
  • Warnings (push_warning()) become breadcrumbs on the next error.
  • An engine error (get_node on a missing node, say) shows where the engine noticed it, then the script that called it; the issue is named after your script.
  • Frames from res://addons/ and the engine are folded away as library frames.

Report one you handled yourself:

var err := save_game(slot)
if err != OK:
    Zharp.capture_error("Save failed: %s" % error_string(err), {"slot": slot})   # handled

Crashes

When the engine itself crashes, nothing more can run in the game. Godot's crash handler writes the backtrace to the log file, and on the next launch the addon reads the previous run's log and sends the crash, with that run's session, scene, player and release:

SIGSEGV: Index out of bounds (Program crashed with signal 11)
[0] explode (res://shop/checkout.gd:40)
[1] _ready (res://shop/checkout.gd:29)
[2] /lib/x86_64-linux-gnu/libc.so.6(+0x3c050) [0x7f98e9289050] (??:0)
[3] shop_quest.x86_64() [0x41e2dda] (??:0)

The official release export templates have no crash handler. There, a run that ended without shutting down is sent as UncleanExit, with the error Godot logged just before the end and its backtrace (an OS.crash() message, a failed check). Runs stopped from the editor, and games the OS stopped in the background, aren't reported. Crash reports need file logging, which enabling the plugin turns on for every platform.

Hangs

The main thread not getting through a frame for 5 seconds (zharp/hang_threshold) is reported once per freeze, as ApplicationNotResponding with the scene it froze on. A watchdog thread writes it straight to disk, so it's sent even if the player kills the game. Not on web exports without threads, nor while the debugger is attached.

Readable stack traces

Nothing to upload: GDScript frames name the script, function and line as they are.

  • Release exports keep their backtraces: enabling the plugin turns on debug/settings/gdscript/always_track_call_stacks, which release builds otherwise leave off (it costs a little speed). Turn zharp/release_backtraces off to leave it alone.
  • The code that ran: Godot 4.3+ exports scripts as compiled tokens, so the addon's export plugin adds each script's text to the export, and errors show the lines around each of your frames as that build had them. zharp/source_context off keeps your export as it was.
  • What release builds don't report: Godot checks GDScript runtime errors (a call on null, a bad index) only in debug builds; release templates skip the call without a word. push_error(), engine errors, crashes and hangs are reported in release exports too.
  • Engine frames are addresses with the official templates, grouped by binary and offset. They read as functions and lines with export templates built with debug_symbols=yes.

Tracing

Scenes

The current scene is the screen: everything recorded carries it as screen.name (the scene file's name, from the moment it's added), and each scene shown is a screen <name> span. For a menu inside one scene, Zharp.set_screen("settings").

HTTP

Make requests through Zharp.request instead of HTTPRequest.request. Each becomes a client span with the method, URL (secret query values filtered), status and headers — secret ones like authorization recorded as [Filtered] — and carries traceparent and baggage, so your API's spans join the same trace.

Zharp.request($HTTPRequest, "https://api.example.com/scores")
var result = await $HTTPRequest.request_completed

Spans of your own

var span := Zharp.start_span("load_level", {"level": 3})
await load_level(3)
span.end()

Zharp.set_tag("difficulty", "hard")   # on everything after

User context

Zharp.set_user(player.id, player.email, player.name)   # once someone signs in
Zharp.clear_user()                                      # on sign-out: also starts a new session
  • A session ID on everything: a new session after 30 minutes in the background, and on clear_user(). A game started again sooner keeps it.
  • OS and version, device model, architecture, Godot version and renderer, and a device.id — a random ID created on first launch and kept in user://zharp/. It isn't a hardware ID.

C#

Godot .NET games keep the addon — it reports script and engine errors, crashes, hangs and scenes, and the C# exceptions Godot catches in your callbacks (_Ready, _Process, signals), with their .NET stack. Add the Zharp.Godot package for the rest of the C# side:

dotnet add package Zharp.Godot
using Zharp.Godot;

public partial class Main : Node
{
    public override void _Ready()
    {
        ZharpGodot.Start(this);
        ZharpGodot.SetUser(player.Id, player.Email);
    }
}

try { inventory.Save(); }
catch (Exception e) { ZharpGodot.CaptureException(e); }

var http = new HttpClient(ZharpGodot.HttpHandler());   // requests as spans, with traceparent
  • Exceptions that end the game, on any thread, are saved to disk first and sent at once or on the next launch.
  • Exceptions you catch come with their .NET stack and the code that ran.
  • Everything carries the addon's session, device, scene and player; SetUser and ClearUser set both sides.
  • Godot loads the game into its own load context, where the runtime's own HttpClient diagnostics can't be seen: trace requests with ZharpGodot.HttpHandler().

It reads the same [zharp] settings, and runs on the .NET SDK (.NET 8).

Options

SettingDefaultNotes
zharp/key—Required; ZHARP_KEY
zharp/serviceThe game's nameAs Zharp names an app: shop-quest
zharp/environmentnone; development from the editordeployment.environment.name
zharp/releaseapplication/config/version
zharp/logsoffSend what the game prints; ZHARP_LOGS
zharp/tracingonOff is logs and errors only
zharp/traces_sample_rate1.0Share of traces kept; errors and logs are always sent
zharp/detect_hangson
zharp/hang_threshold5 s
zharp/source_contextonShip the scripts' text for the code that ran
zharp/release_backtracesonLets the plugin turn on call stacks and file logging
zharp/enabledon
zharp/auto_startonOff: call Zharp.start() yourself
zharp/debugoffPrint what the addon does
zharp/endpointZharpFor a local or self-hosted Zharp

Every batch is written to user://zharp/outbox/ before it's sent and deleted once Zharp has it: what couldn't be sent — no network, a crash, a quit — goes on the next launch. Batches go every 5 seconds or 100 records, gzipped, retried with backoff. Zharp.flush() sends now. The addon never throws into your game.

info

Godot 3 and 4.0–4.4 aren't supported: the Logger class arrived in 4.5.

Troubleshooting

Nothing arrives

On the app's setup page (Applications → the app → settings → Setup instructions), the verify step shows the first event as soon as it lands, and Send a test event checks the key on its own. If the test event arrives but your app's don't, the SDK isn't starting or isn't reaching Zharp:

  • Is init called, and before the code you expect to see? Without a key, the SDK starts nothing and says so once.
  • Does the service name match? With an app key everything goes to that app whatever it says; with a workspace key, service decides the app — see Keys.
  • Data is sent in batches every few seconds. A process that exits straight away should call flush first.
  • Logs and errors arrive but no traces? Check that tracing isn't turned off — see Logs only.
  • Is the plugin enabled? Without it there is no Zharp autoload; the output says [Zharp] started with zharp/debug on.
  • A web export sends from the player's browser: add the game's origin to the key's allowed origins, or leave them empty.

401 or 403

Ingest answers 401 when the key is missing, mistyped, revoked or rolled, and 403 when the request comes from an origin or IP address the key doesn't allow. Neither is retried: the SDK warns once and drops what was refused, and it never throws into your code. Copy the key again from the app's settings.

Allowed origins

A browser sends an Origin header, and when the app has Allowed origins, only those may send with its key. An origin is the scheme, host and port, exactly — https://shop.example.com, not shop.example.com or a URL with a path. Add http://localhost:3000 for local development, or leave the list empty.

Ad blockers

Some browser extensions block requests to monitoring services. If it works in a private window with extensions off, that's the cause — your users with the same extension won't be reported either.