Skip to content

Instantly share code, notes, and snippets.

@sayurimizuguchi
Created May 12, 2022 19:50
Show Gist options
  • Save sayurimizuguchi/dec5deb0959cfa4d51461bf5665c5157 to your computer and use it in GitHub Desktop.
Save sayurimizuguchi/dec5deb0959cfa4d51461bf5665c5157 to your computer and use it in GitHub Desktop.
Sentry - Lunch and learn - May 12, 2022
// Import Dev Configs
import './src/config';
import React from 'react'
import { Button } from './design';
/**
* @author Sayuri Mizuguchi
* Import, Initialize and Wrap
*/
import * as Sentry from '@sentry/react-native';
import App from './App';
Sentry.init({
dsn: "myDSNFromConfigProject",
enabled: !__DEV__,
debug: true,
});
Sentry.wrap(App);
/**
* @author Sayuri Mizuguchi
* Native Crash Example
*/
const ButtonNativeCrash = (text: string) => {
return (
<Button onPress={() => Sentry.nativeCrash()}>
{text}
</Button>
);
}
/**
* @author Sayuri Mizuguchi
* JS Error Example
*/
const simulateError = (payload: object) => {
try {
throw Error(`Errorring with payload = ${JSON.stringify(payload)}`);
} catch (e) {
console.error(e);
}
}
/**
* @author Sayuri Mizuguchi
* Interceptor example
* ref: https://docs.sentry.io/platforms/javascript/enriching-events/breadcrumbs/
*/
Sentry.init({
dsn: "myDSNFromConfigProject",
enabled: !__DEV__,
beforeBreadcrumb(breadcrumb, _) {
return breadcrumb.category === "ui.network" ?
null :
breadcrumb;
},
});
/**
* @author Sayuri Mizuguchi
* Enriching events - Add custom Tags!
* ref: https://docs.sentry.io/platforms/javascript/enriching-events/tags/
*/
interface IAddTagSentry {
memberId: string;
};
const addTagsSentry = (payload: IAddTagSentry) =>
Sentry.setTag("member_id", payload.memberId)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment