Sentry
Send errors and diagnostic messages from your app to your Sentry project. Connect it and write the code now; the SDK runs only in a native build.
- Asks for
- Sentry project address (DSN)
- Runs in
- Native development and release builds
On this page
What the connector does
Sentry collects your app's errors in your Sentry dashboard. The connector captures errors and diagnostic messages, records breadcrumbs that lead up to them, sets a pseudonymous user ID and flushes reports waiting to be sent.
The public DSN only lets your app send events. Issue administration, account access and Sentry auth tokens are not supported.
What you need
- Sentry project address (DSN)
- Required. The public DSN from your Sentry project's settings, under Client Keys (DSN): an HTTPS address made of a 32-character public key, Sentry's host and a numeric project ID. The field hides it until you choose to show it.
Connectors refuses auth tokens, a DSN that contains a secret, passwords, local hosts, query strings and custom paths. If you have no project yet, create a React Native project in Sentry. Only one Sentry connection can be enabled in a project at a time.
Add Sentry
- In Sentry, open your project's settings, then Client Keys (DSN), and copy the public DSN.
- Choose Connect in the rail, then Connect Sentry, and enter the Sentry project address (DSN) under Test details.
- Choose Check connection, then Connect.
The check confirms the DSN's form; after Connect, the status reads Saved · further testing needed. It does not contact Sentry or send a test event. The steps every connector shares are in Connectors.
What you can request
| Operation | What it does | Parameters | Returns |
|---|---|---|---|
status | Starts error monitoring and reports whether it is ready on the device. It does not contact Sentry to confirm delivery. | None | initialized, deliveryVerified |
captureException | Captures an error built from a safe message and an optional name. | message (required), name | eventId, deliveryVerified |
captureMessage | Queues a diagnostic message with a severity. | message (required), level | eventId, deliveryVerified |
addBreadcrumb | Attaches a short step to later errors. It sends nothing on its own. | message (required), category, level | status |
setUser | Sets a pseudonymous user ID on diagnostics. It does not sign anyone in or grant access. | id (required) | status |
clearUser | Removes the user ID, for example at sign-out. | None | status |
flush | Waits up to timeoutMs for the queue on the device. | timeoutMs | flushed, deliveryVerified |
message: up to 2,000 characters, without spaces at either end.nameandcategory: up to 100 characters.level:fatal,error,warning,infoordebug. The default isinfo.id: up to 128 letters, digits, dots, colons, underscores and hyphens, starting with a letter or digit, so an email address or a URL is refused.timeoutMs: 1 to 10,000 milliseconds. The default is 2,000.
deliveryVerified is always false: an event ID or a flush result shows what the device queued, not what Sentry received.
Use it in code
Import getConnector from @appsanic/connectors with your connection's id, shown under How to use Sentry in the connection's settings. Check availability?.supported before every operation. Where the SDK cannot run, a request throws availability.reason, so a reporting helper can skip the report instead.
import { getConnector } from "@appsanic/connectors";
// Use the id of your own connection, shown under How to use Sentry.
const monitoring = getConnector("sentry-e15b7c3a");
const canReport = () => monitoring.availability?.supported === true;
// Keep passwords, keys and personal details out of every message.
export async function noteStep(message: string) {
if (!canReport()) return;
await monitoring.request("addBreadcrumb", {
message,
category: "navigation",
level: "info",
});
}
export async function reportError(message: string, name: string) {
if (!canReport()) return null; // Nothing is reported without the native SDK.
return monitoring.request("captureException", { message, name });
}
export async function forgetUser() {
if (canReport()) await monitoring.request("clearUser");
}reportError returns the reply with its eventId. Confirm the event itself in your Sentry dashboard, from an installed app. On a paid plan, Build with Sanic AI in the connection's settings starts a Sanic AI draft that names this connection, so you can ask for useful error reports. See With Sanic AI.
Where it runs
| Where | Mode | Can the SDK run? |
|---|---|---|
| Browser preview | browser | No. Requests throw availability.reason. |
| Expo Go | expo-go | No. Requests throw availability.reason. |
| Native development or release build | native | Yes, when the build was made with this connection enabled. |
In a native build the SDK starts with the app, and each report carries the environment test or production, following the details your app uses. A native build made without this connection reports that the native SDK is unavailable. While the connection is enabled, Problems in Code shows an Android/iOS warning that Sentry needs a native build; the rest of your app still runs in the preview and in Expo Go.
Privacy and limits
- Personal-data collection, screenshots, session replay, performance tracing and automatic network or console breadcrumbs are off. Only breadcrumbs you add are kept, up to 50.
- Keep passwords, keys and personal information out of messages, names and breadcrumbs.
- Source map and debug-symbol upload is off. Set it up in your own trusted build system, and never save a Sentry auth token in your app.
- Test still sends real reports to Sentry. Use a separate Sentry project under Test details to keep test errors away from customer reports.
