---
title: "Native"
url: https://docs.sentry.io/platforms/native/
---

# Sentry for Native

The Sentry Native SDK is intended for C and C++. However, since it builds as a dynamic library and exposes C-bindings, it can be used by any language that supports interoperability with C, such as the Foreign Function Interface (FFI).

It also provides native crash reporting for other Sentry SDKs:

* [*Android (NDK)*](https://docs.sentry.io/platforms/android/configuration/using-ndk.md)
* [*Flutter*](https://docs.sentry.io/platforms/dart/guides/flutter.md)
* [*Godot*](https://docs.sentry.io/platforms/godot.md)
* [*.NET*](https://docs.sentry.io/platforms/dotnet.md)
* [*Unity*](https://docs.sentry.io/platforms/unity.md)
* [*Unreal Engine*](https://docs.sentry.io/platforms/unreal.md)

Sentry's console SDKs also build on the Native SDK. See the [Nintendo Switch](https://docs.sentry.io/platforms/nintendo-switch.md), [PlayStation](https://docs.sentry.io/platforms/playstation.md), and [Xbox](https://docs.sentry.io/platforms/xbox.md) documentation for details.

Sentry also offers higher-level SDKs for platforms with built-in support for native crashes:

* [*Android*](https://docs.sentry.io/platforms/android.md)
* [*Apple (Cocoa)*](https://docs.sentry.io/platforms/apple.md)
* [*Electron*](https://docs.sentry.io/platforms/javascript/guides/electron.md)

On this page, we get you up and running with Sentry's Native SDK.

##### Using a framework?

Check out the other SDKs we support in the left-hand dropdown.

## [Prerequisites](https://docs.sentry.io/platforms/native.md#prerequisites)

You need:

* A Sentry [account](https://sentry.io/signup/) and [project](https://docs.sentry.io/product/projects.md)
* Your application up and running

The SDK currently supports **Windows**, **macOS**, and **Linux**.

## [Install](https://docs.sentry.io/platforms/native.md#install)

To build the SDK, download the latest sources from the [Releases page](https://github.com/getsentry/sentry-native/releases). The SDK is managed as a [CMake](https://cmake.org/cmake/help/latest/) project, which additionally supports several configuration options, such as the backend to use.

For example, `CMake` can be used like this:

**macOS**

```shell
# When using CMake 4 ensure you have valid SDKROOT defined in your environment.
export SDKROOT=$(xcrun --sdk macosx --show-sdk-path)
# Configure the CMake build into the `build` directory with the desired backend.
# Specifying `RelWithDebInfo` as the `CMAKE_BUILD_TYPE` is optional because it
# is the default in sentry-native for all generators supporting it.
cmake -B build -D SENTRY_BACKEND=native -D CMAKE_BUILD_TYPE=RelWithDebInfo
# build the project
cmake --build build --parallel
# install the resulting artifacts into a specific prefix
cmake --install build --prefix install
# which will result in the following:
eza --tree install --level 2
install
├── bin
│  └── sentry-crash
├── include
│  └── sentry.h
└── lib
   ├── cmake
   ├── libsentry.dylib
   └── libsentry.dylib.dSYM
```

**Linux**

```shell
# Configure the CMake build into the `build` directory with the desired backend.
# Specifying `RelWithDebInfo` as the `CMAKE_BUILD_TYPE` is optional because it
# is the default in sentry-native for all generators supporting it.
cmake -B build -D SENTRY_BACKEND=native -D CMAKE_BUILD_TYPE=RelWithDebInfo
# build the project
cmake --build build --parallel
# install the resulting artifacts into a specific prefix
cmake --install build --prefix install
# which will result in the following:
tree install -L 2
install
├── bin
│   └── sentry-crash
├── include
│   └── sentry.h
└── lib
    ├── cmake
    └── libsentry.so

5 directories, 3 files
```

**Windows**

```shell
# The msbuild generator ignores the CMAKE_BUILD_TYPE because it contains all
# build-types.
cmake -B build -D SENTRY_BACKEND=native
# The actual build step then requires we specify which build-type we want
# to apply via the `--config` parameter. Please be aware that in msbuild
# projects, the `--parallel` option has no effect.
cmake --build build --config RelWithDebInfo
# install the resulting artifacts (again requiring build-type!)
cmake --install build --prefix install --config RelWithDebInfo
# which will result in the following output (ignoring non-essential lines):
tree /f install
├───bin
│       sentry-crash.exe
│       sentry-wer.dll
│       sentry-wer.pdb
│       sentry.dll
│       sentry.pdb
│
├───include
│       sentry.h
│
└───lib
    │   sentry.lib
    │
    └───cmake
```

For further details on the `SDKROOT` usage with CMake please consult the [macOS build section in the SDK README](https://github.com/getsentry/sentry-native?tab=readme-ov-file#building-and-installation).

##### Bundling out-of-process backends

The out-of-process *Native* and *Crashpad* backends require shipping `sentry-crash` or `crashpad_handler`, respectively, alongside the application binary. See the [Native](https://docs.sentry.io/platforms/native/configuration/backends/native.md) and [Crashpad](https://docs.sentry.io/platforms/native/configuration/backends/crashpad.md) backend documentation for more information.

## [Configure](https://docs.sentry.io/platforms/native.md#configure)

**Error Monitoring** starts working as soon as you call `sentry_init()`, capturing native crashes and the events you send manually. **Logs** and **Application Metrics** are enabled by default in current SDK versions, and you'll learn how to send them in [Send Logs](https://docs.sentry.io/platforms/native.md#send-logs) and [Send Application Metrics](https://docs.sentry.io/platforms/native.md#send-application-metrics-). This guide also enables **Tracing** and **Release Health**.

Want to learn more about these features?

* [**Issues**](https://docs.sentry.io/product/issues.md) (always enabled): Sentry's core error monitoring product that automatically reports errors, uncaught exceptions, and crashes. If you have something that looks like an exception, Sentry can capture it.
* [**Tracing**](https://docs.sentry.io/product/tracing.md): Track software performance while seeing the impact of errors across multiple systems. For example, distributed tracing allows you to follow a request from the frontend to the backend and back.
* [**Logs**](https://docs.sentry.io/product/logs.md): Centralize and analyze your application logs to correlate them with errors and performance issues. Search, filter, and visualize log data to understand what's happening in your applications.
* [**Application Metrics**](https://docs.sentry.io/product/metrics.md) (always enabled): Track and analyze custom application metrics, such as response times and database query durations, to understand trends and patterns in your application's performance and behavior over time.

Configuration should happen as early as possible in your application's lifecycle.

The snippet also turns on:

* Tracing: via [`traces_sample_rate`](https://docs.sentry.io/platforms/native/configuration/options.md#traces_sample_rate). You create transactions and spans with [custom instrumentation](https://docs.sentry.io/platforms/native/tracing/instrumentation/custom-instrumentation.md).
* Release Health: via [`release`](https://docs.sentry.io/platforms/native/configuration/options.md#release). The SDK starts a session on `sentry_init()` and ends it on `sentry_close()`.
* SDK debug output: via [`debug`](https://docs.sentry.io/platforms/native/configuration/options.md#debug). Turn this off in production.

Don't need a feature? Remove its options from the snippet.

```c
#include <sentry.h>

int main(void) {
  sentry_options_t *options = sentry_options_new();
  sentry_options_set_dsn(options, "https://<key>@o<orgId>.ingest.sentry.io/<projectId>");
  // This is also the default-path. For further information and recommendations:
  // https://docs.sentry.io/platforms/native/configuration/options/#database-path
  sentry_options_set_database_path(options, ".sentry-native");
  sentry_options_set_release(options, "my-project-name@2.3.12");
  sentry_options_set_debug(options, 1);
  // Enables Tracing.
  // Set to 1.0 to capture 100% of transactions for tracing.
  // We recommend reducing this value in production.
  sentry_options_set_traces_sample_rate(options, 1.0);
  sentry_init(options);

  /* ... */

  // make sure everything flushes
  sentry_close();
}
```

Alternatively, the DSN can be passed as `SENTRY_DSN` environment variable during runtime. This can be especially useful for server applications.

##### Important

Calling `sentry_close()` before exiting the application is critical. It ensures that events can be sent to Sentry before execution stops. Otherwise, event data may be lost.

### [Add Readable Stack Traces With Debug Information Files](https://docs.sentry.io/platforms/native.md#add-readable-stack-traces-with-debug-information-files)

To see symbolicated stack traces for native crashes, upload your application's debug information files to Sentry. See [Uploading Debug Information Files](https://docs.sentry.io/platforms/native/data-management/debug-files/upload.md) for how to do this with `sentry-cli`.

## [Send Logs](https://docs.sentry.io/platforms/native.md#send-logs)

Use the `sentry_log_*()` functions to send logs at different levels: `trace`, `debug`, `info`, `warn`, `error`, and `fatal`. The message is a printf-style format string. Logs require Native SDK 0.11.1 or later and are enabled by default since 0.13.9.

See [Set Up Logs](https://docs.sentry.io/platforms/native/logs.md) for attributes, `before_send_log`, and logging user-provided text safely.

```c
sentry_log_info("A simple log message");
sentry_log_error("A %s log message", "formatted");
```

## [Send Application Metrics NEW](https://docs.sentry.io/platforms/native.md#send-application-metrics-)

Use the `sentry_metrics_*()` functions to send counters, gauges, and distributions. You can pass attributes to search or filter by later, or `sentry_value_new_null()` when you don't need any. Application Metrics require Native SDK 0.12.6 or later and are enabled by default since 0.13.5.

See [Set Up Metrics](https://docs.sentry.io/platforms/native/metrics.md) for all available metric types, units, and configuration options.

```c
sentry_metrics_count("checkout.failed", 1, sentry_value_new_null());

sentry_metrics_gauge("active_connections", 42, NULL, sentry_value_new_null());

sentry_metrics_distribution("api_latency", 187.0, SENTRY_UNIT_MILLISECOND,
    sentry_value_new_null());
```

## [Verify Your Setup](https://docs.sentry.io/platforms/native.md#verify-your-setup)

Let's test your setup and confirm that Sentry is working correctly and sending data to your Sentry project.

Add this code snippet to capture a message:

```c
sentry_capture_event(sentry_value_new_message_event(
  /*   level */ SENTRY_LEVEL_INFO,
  /*  logger */ "custom",
  /* message */ "It works!"
));
```

### [View Captured Data in Sentry](https://docs.sentry.io/platforms/native.md#view-captured-data-in-sentry)

Now, head over to your project on [Sentry.io](https://sentry.io) to view the collected data (it takes a couple of moments for the data to appear).

Need help locating captured data in your Sentry project?

* Open the [**Issues**](https://sentry.io/orgredirect/organizations/:orgslug/issues/) page and select an error from the issues list to view the full details and context of this error. For more details, see the [Issue Details documentation](https://docs.sentry.io/product/issues/issue-details.md).
* Open the [**Traces**](https://sentry.io/orgredirect/organizations/:orgslug/explore/traces/) page and select a trace to reveal more information about each span, its duration, and any errors. For an interactive UI walkthrough, click [here](https://docs.sentry.io/product/sentry-basics/getting-started-tutorial/generate-first-error.md#ui-walkthrough).
* Open the [**Logs**](https://sentry.io/orgredirect/organizations/:orgslug/explore/logs/) page and filter by service, environment, or search keywords to view log entries from your application. For an interactive UI walkthrough, click [here](https://docs.sentry.io/product/logs.md#overview).
* Open the [**Application Metrics**](https://sentry.io/orgredirect/organizations/:orgslug/explore/metrics) page to view and analyze your metrics. For more details, see this [interactive walkthrough](https://docs.sentry.io/product/metrics.md#overview).

## [Next Steps](https://docs.sentry.io/platforms/native.md#next-steps)

At this point, you should have integrated Sentry into your application. Here's what to explore next:

* Explore [practical guides](https://docs.sentry.io/get-started/guides.md) on what to monitor, log, track, and investigate after setup
* Choose a [crash-handling backend](https://docs.sentry.io/platforms/native/configuration/backends.md) for your target platforms
* Detect unresponsive apps with [App Hangs](https://docs.sentry.io/platforms/native/app-hangs.md) (experimental)
* Collect Feedback via the [User Feedback API](https://docs.sentry.io/platforms/native/user-feedback.md)

Are you having problems setting up the SDK or integration?

* [Get support](https://www.sentry.help/en/)

## Frameworks

- [Google Breakpad](https://docs.sentry.io/platforms/native/guides/breakpad.md)
- [Google Crashpad](https://docs.sentry.io/platforms/native/guides/crashpad.md)
- [Minidumps](https://docs.sentry.io/platforms/native/guides/minidumps.md)
- [Qt](https://docs.sentry.io/platforms/native/guides/qt.md)
- [WebAssembly](https://docs.sentry.io/platforms/native/guides/wasm.md)

## Topics

- [Basic Configuration](https://docs.sentry.io/platforms/native/configuration.md)
- [Usage](https://docs.sentry.io/platforms/native/usage.md)
- [Advanced Usage](https://docs.sentry.io/platforms/native/advanced-usage.md)
- [Data Management](https://docs.sentry.io/platforms/native/data-management.md)
- [Security Policy Reporting](https://docs.sentry.io/platforms/native/security-policy-reporting.md)
- [App Hangs](https://docs.sentry.io/platforms/native/app-hangs.md)
- [Debug Information](https://docs.sentry.io/platforms/native/debug-information.md)
- [Enriching Events](https://docs.sentry.io/platforms/native/enriching-events.md)
- [Tracing](https://docs.sentry.io/platforms/native/tracing.md)
- [Logs](https://docs.sentry.io/platforms/native/logs.md)
- [Application Metrics](https://docs.sentry.io/platforms/native/metrics.md)
- [Feedback](https://docs.sentry.io/platforms/native/user-feedback.md)
- [Migration Guide](https://docs.sentry.io/platforms/native/migration.md)

---

Find other pages: [Sitemap](https://docs.sentry.io/sitemap.md) lists every page with a one-line summary, and [llms.txt](https://docs.sentry.io/llms.txt) gives an overview with guidance for agents.
