boltZharp Docs
memorySDKs

Native (C and C++)

For C and C++ apps, games and services on Windows, macOS and Linux: crashes through Crashpad, the errors you handle, breadcrumbs, logs and spans, each read as functions, files and lines from your build's debug files.

The SDK is a C library with a small C++ layer, built with CMake. Crashes are written by Crashpad's handler, a separate process that watches your app, so a crash is reported even when the heap or the stack is corrupt. Everything else goes to Zharp over OTLP from a background thread.

Apps that already run their own Crashpad or Breakpad only need the upload URL: see MiniDump.

Install

Create an app from the Native tile under Add app (under Server for a daemon or service). CMake 3.16 or later and a C++17 compiler (MSVC, Clang or GCC). On Linux the SDK uses libcurl (libcurl4-openssl-dev to build).

include(FetchContent)
FetchContent_Declare(zharp
    GIT_REPOSITORY https://github.com/zharp-io/zharp-native-lib.git
    GIT_TAG v0.1.0)
FetchContent_MakeAvailable(zharp)

add_executable(shop main.cpp cart.cpp)
target_link_libraries(shop PRIVATE zharp::zharp)
zharp_add_crash_handler(shop)          # crashpad_handler next to shop after each build
zharp_upload_debug_files(shop APP <application id> INCLUDE_SOURCES)

Or with vcpkg:

vcpkg add port zharp

# CMakeLists.txt
find_package(zharp CONFIG REQUIRED)
target_link_libraries(shop PRIVATE zharp::zharp)
zharp_add_crash_handler(shop)

Ship crashpad_handler (crashpad_handler.exe on Windows) next to your executable: that is where the SDK looks for it. In your install step:

install(TARGETS shop DESTINATION bin)
install(PROGRAMS $<TARGET_FILE:zharp::crashpad_handler> DESTINATION bin)

Initialize

First thing in main:

#include <zharp.hpp>

int main(int argc, char **argv) {
    zharp_options_t options;
    zharp_options_init(&options);
    options.key = "zpk_…";                  // or ZHARP_KEY in the environment
    options.environment = "production";
    options.release = "1.4.2";
    zharp::Init zharp(&options);            // sends what's left when main returns

    run_app();
}

From C, with the settings in the environment:

#include <zharp.h>

int main(void) {
    zharp_init(NULL);                       /* everything from ZHARP_* variables */
    run_service();
    zharp_shutdown();                       /* sends what's queued */
    return 0;
}

For a daemon or service, turn sessions off:

zharp_options_t options;
zharp_options_init(&options);
options.sessions = 0;                       // a daemon or service: no sessions or device ID
zharp_init(&options);

Options

Each option falls back to its environment variable, then to its default.

OptionVariableDefault
keyZHARP_KEYNone: without a key nothing is sent
serviceZHARP_SERVICEThe executable's name
environmentZHARP_ENVIRONMENTNone
releaseZHARP_RELEASENone
logsZHARP_LOGSOff
crash_reportingZHARP_CRASH_REPORTINGOn
sessionsZHARP_SESSIONSOn: a session per launch, or after 30 minutes idle
tracingZHARP_TRACINGOn
sample_rateZHARP_SAMPLE_RATE1: every trace
handler_pathZHARP_HANDLER_PATHcrashpad_handler next to the executable
database_pathZHARP_DATABASE_PATHThe user's cache folder, then zharp/<service>
disabledZHARP_DISABLEDOff
debugZHARP_DEBUGOff: prints what the SDK does to stderr

Crashes

Null pointers, access violations, abort(), failed assertions and stack overflows: Crashpad writes a minidump and sends it, with the release, environment, session, device, user, your tags and the last 100 breadcrumbs. An uncaught C++ exception arrives as itself, with its type and what():

std::runtime_error: inventory file is corrupt
#0  load_inventory() (src/main.cpp:32) [shop +0x7dc4]
#1  run(char const*) (src/main.cpp:48) [shop +0x7ddc]
#2  main (src/main.cpp:77) [shop +0xbb26]
#3  libc.so.6 +0x27249
  • Crashes group by function names, so the same bug in two builds is one issue once both have symbols.
  • System libraries and Zharp's own frames are named but never count as your code.
  • Under Advanced on the issue: the OS and CPU, the other threads, the loaded modules, and Download minidump for WinDbg, Visual Studio or lldb. Dumps are kept 30 days.
  • A report that can't be sent waits in the database folder and goes out with the next launch.

Errors

Report the errors you handle. Each is one issue, marked handled, with the stack where you report it:

try {
    load_level(path);
} catch (const std::exception &e) {
    zharp::capture_exception(e);            // "std::runtime_error: file missing", handled
}

// From C, or for errors that aren't exceptions:
zharp_capture_error("ConfigError", "config file missing");
zharp_capture_message(ZHARP_LEVEL_WARN, "checkout took 12 s");
info
The stack is where you report it
C++ keeps no stack for a thrown exception. Report it in the catch nearest to the throw, and the issue points there.

User, tags and breadcrumbs

zharp::set_user("u_42", "ada@example.com", "Ada");
zharp::set_tag("store", "berlin");
zharp_add_breadcrumb("ui", "opened the settings window");

They go with every error, log and span after the call, and with a crash.

Traces

Spans for long work: loading a level, a nightly job, a request your service handles.

{
    zharp::Span span("load level");
    span.set("level.id", "3");
    load_level(3);
}   // the span ends here; an exception leaving the scope marks it failed

A request that arrives with a traceparent header continues its trace: zharp::Span span("GET /orders", traceparent). zharp_traceparent() gives the header for an outgoing call. With libcurl, one call does both, and records the request and response headers, with authorization, cookies, tokens and API keys kept as [REDACTED]:

#include <curl/curl.h>
#include <zharp_curl.h>

struct curl_slist *headers = curl_slist_append(NULL, "Accept: application/json");
curl_easy_setopt(curl, CURLOPT_URL, "https://api.example.com/orders");
CURLcode code = zharp_curl_perform(curl, headers);   // in place of curl_easy_perform

Logs

Logs are off by default: the Zharp agent brings in the log files your app writes. zharp_log lines are kept as breadcrumbs either way, and sent as logs with ZHARP_LOGS=true. For your own logger, end each line with zharp_log_correlation() so the agent links it to its trace:

zharp_log(ZHARP_LEVEL_INFO, "level loaded");    // a breadcrumb; a log only with ZHARP_LOGS=true

// Your own logger: end each line with the span it belongs to
fprintf(log, "level loaded%s\n", zharp_log_correlation());
// level loaded trace_id=4bf92f3577b34da6a3ce929d0e0e4736 span_id=00f067aa0ba902b7

Readable stack traces

Crashes and errors hold addresses, not names. Build with debug information: RelWithDebInfo, or /Zi with /DEBUG on MSVC; you don't ship it. zharp_upload_debug_files then uploads each release build's symbols after it links, with ZHARP_AUTH_TOKEN (a workspace API key with the Build uploads scope) and Node.js in the build's environment. Without them the build goes on and says it skipped the upload. In CI you can run it yourself:

npx @zharp/cli debug-files upload build/ --app <application id> --include-sources
  • The CLI turns PDBs (Windows), ELF files with debug info (Linux) and dSYMs (macOS) into Breakpad symbol files with Mozilla's dump_syms, under each module's debug ID, the same ID the crash records.
  • --include-sources (INCLUDE_SOURCES) uploads the source files the symbols name, so each frame shows the code that ran in that build.
  • Symbols that arrive after a crash still count: the issue is read again when you open it.

Troubleshooting

  • "crash reporting is off: Crashpad's handler isn't at …": ship crashpad_handler next to the executable, or set ZHARP_HANDLER_PATH.
  • Nothing arrives: run with ZHARP_DEBUG=true; the SDK prints what it sends and any refusal. A refused key is reported once.
  • Frames read as addresses: upload the debug files of the exact build you shipped; the issue lists the modules it is waiting for.