@tailcove/react-native
v0.2.0
Published
React Native client for Tailcove: logs and JavaScript errors from iOS and Android apps, batched, retried and kept across restarts.
Maintainers
Readme
Install
npm install @tailcove/react-native @react-native-async-storage/async-storagePlain JavaScript, no native module: it works in Expo (managed and bare) and in bare React Native 0.70 and later. AsyncStorage is optional; with it, logs written offline or just before a crash are sent on the next launch.
Quick start
1. Get an app key. In your Tailcove dashboard, open your source's Settings tab, generate a key under Mobile apps, and add your app's iOS bundle id or Android package name (for example com.acme.shop, or com.acme.* for all of them).
The app key ships inside your app, so it is public by design. It only works for the app ids you allowed, and it has its own rate limit, so a copied key cannot use up your source's quota. It is not the server-side ingest token, which must stay secret.
2. Start the client once, as early as possible (for example in index.js or your root layout):
import AsyncStorage from '@react-native-async-storage/async-storage';
import { Tailcove } from '@tailcove/react-native';
export const tailcove = Tailcove.init({
appKey: 'tca_your_app_key',
appId: 'com.acme.shop',
release: '2.4.0',
environment: 'production',
storage: AsyncStorage,
});3. Log.
tailcove.info('Checkout opened', { items: 3 });
tailcove.warning('Slow image load', { ms: 2400 });
tailcove.error('Payment failed', { provider: 'stripe' });Anywhere else in the app, Tailcove.instance is the same client.
Errors and crashes
Uncaught JavaScript errors (the red screen in development, a crash in release builds) and promise rejections nothing handled are reported on their own, as error lines, or critical when the error is fatal. Each carries the exception (class, message, location, stack) and the last 20 log calls before it, and Tailcove groups them into issues. A fatal error is saved and sent before the app goes down, and if the app dies first, it is sent on the next launch.
Report an error you caught yourself:
try {
await placeOrder();
} catch (error) {
tailcove.captureException(error, { orderId });
}Add a step to the trail without sending a line: tailcove.addBreadcrumb('Tapped pay').
Promise rejections are tracked through Hermes, React Native's default engine. On JavaScriptCore, report them in your own .catch().
Native crashes (in Swift, Objective-C, Kotlin or Java code) are outside JavaScript. For those, add a Sentry SDK and point it at the DSN from your source's Error tracking section.
Users and context
tailcove.setUser(user.id); // only the id is sent, never a name or email
tailcove.setContext({ plan: 'pro' }); // on every following line
tailcove.setUser(null); // on sign-outWhat gets added automatically
app.idandapp.version: your app id andreleaseos.nameandos.version:iosorandroidand the OS versiondevice: the model, brand and manufacturer on Android,phoneorpadon iOSenvironment: when you set itsession_id: a random id for this launch, so one session's lines are easy to find togetherhost:iosorandroid
Secrets stay on the phone
Before a line is queued, the client masks anything that looks like a secret, so it never leaves the device. This covers your own log calls and the errors it reports by itself.
- In the context, the value of a key like
password,api_key,client_secret,Authorization,Set-Cookieorcookiesbecomes[redacted], nested objects included.nullandtrue/falsestay, sohas_password: truestill reads fine. - In the message and in every string in the context, the value after such a name becomes
[redacted]:token=abc123,"password": "hunter2",Authorization: Bearer .... Prose likepassword: too shortis left alone. - Credentials we can spot by their shape become
[key]: JWTs, AWS access key ids, Stripe secret and webhook keys, GitHub and Slack tokens, Google API keys andPRIVATE KEYblocks. Public keys and Stripepk_keys stay.
The client's own fields (session_id, app, os, device) aren't touched. Tailcove can mask on the server as well, but masking here means the secret never crosses the network.
Add your own key names with secretKeys, or turn masking off with maskSecrets: false. For anything else, beforeSend sees each line after masking and can change it or drop it:
Tailcove.init({
appKey: 'tca_your_app_key',
appId: 'com.acme.shop',
secretKeys: ['customer_ssn'],
beforeSend: (line) => {
if (line.message.startsWith('Health check')) {
return null; // dropped
}
delete line.context.email;
return line;
},
});If beforeSend throws, the line is still sent, masked as it was, and the error goes to onError.
Options
appKey(required): the source's app key.appId(required): the app's bundle id or package name, as allowed in Settings.endpoint: defaults tohttps://ingest.tailcove.dev/api/v1/app/logs. Change it only if you self-host.storage: an AsyncStorage-like object (getItem,setItem,removeItem). Keeps unsent lines across restarts.release,environment: added to every line.context: fields added to every line. Per-call context wins when keys clash.batchSize: send once this many lines are waiting. Default50.flushIntervalMs: send this long after the first waiting line. Default5000.maxQueueSize: lines kept while offline; past it the oldest go first. Default1000.timeoutMs: how long one delivery attempt may take. Default10000.captureErrors,captureRejections: report uncaught errors and unhandled rejections. Defaulttrue.traceLimit: stack frames kept per error. Default20.enabled: setfalseto turn the client off, for example in tests.maskSecrets: mask secrets before a line is queued (see above). Defaulttrue.secretKeys: more key names to treat as secret, matched whole, ignoring case,-,_,.and spaces.beforeSend: called with each line after masking. Return the line, changed or not, ornullto drop it.onError: called when a batch cannot be sent or is refused, or whenbeforeSendthrows. Failures are otherwise silent.
How delivery works
Lines wait in a queue and go out in batches, when batchSize is reached, flushIntervalMs after the first one, or when the app goes to the background. A line leaves the queue only once Tailcove has accepted it. If the phone is offline or the server asks it to slow down, the batch stays queued and is tried again with backoff (honouring Retry-After). A batch refused for good, for example after the key was revoked, is dropped and reported to onError. The client never throws into your app.
Call await tailcove.flush() to send now, and await tailcove.close() to send, save and detach the error hooks.
Help and feedback
- Docs: tailcove.dev/docs/sending-logs/react-native
- Bugs and feature requests: open an issue
- Security problems: please email [email protected] instead of opening a public issue.
