Skip to content

Commit

Permalink
POC: Sentry Opentelemetry support
Browse files Browse the repository at this point in the history
  • Loading branch information
krystofwoldrich committed Apr 18, 2023
1 parent 1325d7b commit 584c33f
Show file tree
Hide file tree
Showing 4 changed files with 117 additions and 15 deletions.
3 changes: 3 additions & 0 deletions sample-new-architecture/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,12 @@
"pod-install-legacy-production": "cd ios; PRODUCTION=1 bundle exec pod install; cd .."
},
"dependencies": {
"@opentelemetry/api": "^1.4.1",
"@opentelemetry/sdk-trace-web": "^1.12.0",
"@react-native-community/cli-platform-android": "^10.1.3",
"@react-navigation/native": "^6.1.2",
"@react-navigation/stack": "^6.3.11",
"@sentry/opentelemetry-node": "^7.48.0",
"react": "18.2.0",
"react-native": "0.71.6",
"react-native-gesture-handler": "^2.9.0",
Expand Down
39 changes: 25 additions & 14 deletions sample-new-architecture/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,18 @@ import { GestureHandlerRootView } from 'react-native-gesture-handler';
import GesturesTracingScreen from './Screens/GesturesTracingScreen';
import { StyleSheet } from 'react-native';
import { HttpClient } from '@sentry/integrations';
import { WebTracerProvider } from '@opentelemetry/sdk-trace-web';
import { SentrySpanProcessor } from '@sentry/opentelemetry-node';

const reactNavigationInstrumentation =
new Sentry.ReactNavigationInstrumentation({
routeChangeTimeoutMs: 500, // How long it will wait for the route change to complete. Default is 1000ms
});

const provider = new WebTracerProvider();
provider.addSpanProcessor(new SentrySpanProcessor());
provider.register();

Sentry.init({
// Replace the example DSN below with your own DSN:
dsn: SENTRY_INTERNAL_DSN,
Expand All @@ -34,27 +40,32 @@ Sentry.init({
console.log('Event beforeSend:', event);
return event;
},
beforeSendTransaction: (transaction) => {
console.log('Transaction beforeSend:', transaction);
return transaction;
},
// This will be called with a boolean `didCallNativeInit` when the native SDK has been contacted.
onReady: ({ didCallNativeInit }) => {
console.log('onReady called with didCallNativeInit:', didCallNativeInit);
},
instrumenter: 'otel',
integrations(integrations) {
integrations.push(
new Sentry.ReactNativeTracing({
// The time to wait in ms until the transaction will be finished, For testing, default is 1000 ms
idleTimeout: 5000,
routingInstrumentation: reactNavigationInstrumentation,
tracingOrigins: ['localhost', /^\//, /^https:\/\//],
enableUserInteractionTracing: true,
beforeNavigate: (context: Sentry.ReactNavigationTransactionContext) => {
// Example of not sending a transaction for the screen with the name "Manual Tracker"
if (context.data.route.name === 'ManualTracker') {
context.sampled = false;
}
// new Sentry.ReactNativeTracing({
// // The time to wait in ms until the transaction will be finished, For testing, default is 1000 ms
// idleTimeout: 5000,
// routingInstrumentation: reactNavigationInstrumentation,
// tracingOrigins: ['localhost', /^\//, /^https:\/\//],
// enableUserInteractionTracing: false,
// beforeNavigate: (context: Sentry.ReactNavigationTransactionContext) => {
// // Example of not sending a transaction for the screen with the name "Manual Tracker"
// if (context.data.route.name === 'ManualTracker') {
// context.sampled = false;
// }

return context;
},
}),
// return context;
// },
// }),
new HttpClient({
// These options are effective only in JS.
// This array can contain tuples of `[begin, end]` (both inclusive),
Expand Down
14 changes: 14 additions & 0 deletions sample-new-architecture/src/Screens/HomeScreen.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,18 @@ import { CommonActions } from '@react-navigation/native';
import { UserFeedbackModal } from '../components/UserFeedbackModal';
import { FallbackRender } from '@sentry/react';
import NativeSampleModule from '../../tm/NativeSampleModule';
import opentelemetry from "@opentelemetry/api";

const { AssetsModule } = NativeModules;

interface Props {
navigation: StackNavigationProp<any, 'HomeScreen'>;
}

const tracer = opentelemetry.trace.getTracer(
'home-screen-tracer'
);

const HomeScreen = (props: Props) => {
// Show bad code inside error boundary to trigger it.
const [showBadCode, setShowBadCode] = React.useState(false);
Expand Down Expand Up @@ -62,6 +67,15 @@ const HomeScreen = (props: Props) => {
<StatusBar barStyle="dark-content" />
<ScrollView style={styles.mainView}>
<Text style={styles.welcomeTitle}>Hey there!</Text>
<Button
title="Create open telemetry span"
onPress={() => {
const span = tracer.startSpan("test-span");
setTimeout(() => {
span.end();
}, 1000);
}}
/>
<Button
title="Capture message"
onPress={() => {
Expand Down
76 changes: 75 additions & 1 deletion sample-new-architecture/yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1669,6 +1669,49 @@
"@nodelib/fs.scandir" "2.1.5"
fastq "^1.6.0"

"@opentelemetry/api@^1.4.1":
version "1.4.1"
resolved "https://registry.yarnpkg.com/@opentelemetry/api/-/api-1.4.1.tgz#ff22eb2e5d476fbc2450a196e40dd243cc20c28f"
integrity sha512-O2yRJce1GOc6PAy3QxFM4NzFiWzvScDC1/5ihYBL6BUEVdq0XMWN01sppE+H6bBXbaFYipjwFLEWLg5PaSOThA==

"@opentelemetry/core@1.12.0":
version "1.12.0"
resolved "https://registry.yarnpkg.com/@opentelemetry/core/-/core-1.12.0.tgz#afa32341b794045c54c979d4561de2f8f00d0da9"
integrity sha512-4DWYNb3dLs2mSCGl65jY3aEgbvPWSHVQV/dmDWiYeWUrMakZQFcymqZOSUNZO0uDrEJoxMu8O5tZktX6UKFwag==
dependencies:
"@opentelemetry/semantic-conventions" "1.12.0"

"@opentelemetry/resources@1.12.0":
version "1.12.0"
resolved "https://registry.yarnpkg.com/@opentelemetry/resources/-/resources-1.12.0.tgz#895394c727dc3e7e51d1d2cc50907ec07a626dca"
integrity sha512-gunMKXG0hJrR0LXrqh7BVbziA/+iJBL3ZbXCXO64uY+SrExkwoyJkpiq9l5ismkGF/A20mDEV7tGwh+KyPw00Q==
dependencies:
"@opentelemetry/core" "1.12.0"
"@opentelemetry/semantic-conventions" "1.12.0"

"@opentelemetry/sdk-trace-base@1.12.0":
version "1.12.0"
resolved "https://registry.yarnpkg.com/@opentelemetry/sdk-trace-base/-/sdk-trace-base-1.12.0.tgz#62b895dbb5900048a85e4899c38fec5585447d4b"
integrity sha512-pfCOB3tNDlYVoWuz4D7Ji+Jmy9MHnATWHVpkERdCEiwUGEZ+4IvNPXUcPc37wJVmMpjGLeaWgPPrie0KIpWf1A==
dependencies:
"@opentelemetry/core" "1.12.0"
"@opentelemetry/resources" "1.12.0"
"@opentelemetry/semantic-conventions" "1.12.0"

"@opentelemetry/sdk-trace-web@^1.12.0":
version "1.12.0"
resolved "https://registry.yarnpkg.com/@opentelemetry/sdk-trace-web/-/sdk-trace-web-1.12.0.tgz#400511122d952a4a6bc9aeb2492d2acc00caa98e"
integrity sha512-i89anQYHSOamzXEkoMh2xr0Ms8qTQ9dseqHOTBUMOqCVxwj18DJFJC7TwNtVliusZQ0hAbnsPG+V5+/67aNmFg==
dependencies:
"@opentelemetry/core" "1.12.0"
"@opentelemetry/sdk-trace-base" "1.12.0"
"@opentelemetry/semantic-conventions" "1.12.0"

"@opentelemetry/semantic-conventions@1.12.0":
version "1.12.0"
resolved "https://registry.yarnpkg.com/@opentelemetry/semantic-conventions/-/semantic-conventions-1.12.0.tgz#19c959bdb900986e74939d4227e757aa16936b91"
integrity sha512-hO+bdeGOlJwqowUBoZF5LyP3ORUFOP1G0GRv8N45W/cztXbT2ZEXaAzfokRS9Xc9FWmYrDj32mF6SzH6wuoIyA==

"@react-native-community/cli-clean@^10.1.1":
version "10.1.1"
resolved "https://registry.yarnpkg.com/@react-native-community/cli-clean/-/cli-clean-10.1.1.tgz#4c73ce93a63a24d70c0089d4025daac8184ff504"
Expand Down Expand Up @@ -1924,6 +1967,37 @@
color "^4.2.3"
warn-once "^0.1.0"

"@sentry/core@7.48.0":
version "7.48.0"
resolved "https://registry.yarnpkg.com/@sentry/core/-/core-7.48.0.tgz#1a5ec347ab7212d73a99583c2e64989e34e3263a"
integrity sha512-8FYuJTMpyuxRZvlen3gQ3rpOtVInSDmSyXqWEhCLuG/w34AtWoTiW7G516rsAAh6Hy1TP91GooMWbonP3XQNTQ==
dependencies:
"@sentry/types" "7.48.0"
"@sentry/utils" "7.48.0"
tslib "^1.9.3"

"@sentry/opentelemetry-node@^7.48.0":
version "7.48.0"
resolved "https://registry.yarnpkg.com/@sentry/opentelemetry-node/-/opentelemetry-node-7.48.0.tgz#69a710d2f8b2ee9f9a7a5bb975baaccb7a9e4450"
integrity sha512-Xm8lrLyjG5HG9N3q8SDyWPbNvE8bM+2ctOhhdaHLygECdSOBR9US/b7aGDWFOw3rfmNe4WsnuG0tluD4XwQMBA==
dependencies:
"@sentry/core" "7.48.0"
"@sentry/types" "7.48.0"
"@sentry/utils" "7.48.0"

"@sentry/types@7.48.0":
version "7.48.0"
resolved "https://registry.yarnpkg.com/@sentry/types/-/types-7.48.0.tgz#57f3c9cf331a5621e82dda04eefcf8c19ee42bc9"
integrity sha512-kkAszZwQ5/v4n7Yyw/DPNRWx7h724mVNRGZIJa9ggUMvTgMe7UKCZZ5wfQmYiKVlGbwd9pxXAcP8Oq15EbByFQ==

"@sentry/utils@7.48.0":
version "7.48.0"
resolved "https://registry.yarnpkg.com/@sentry/utils/-/utils-7.48.0.tgz#2866975ea8899aba35b083dd0558cbbe29ee8de1"
integrity sha512-d977sghkFVMfld0LrEyyY2gYrfayLPdDEpUDT+hg5y79r7zZDCFyHtdB86699E5K89MwDZahW7Erk+a1nk4x5w==
dependencies:
"@sentry/types" "7.48.0"
tslib "^1.9.3"

"@sideway/address@^4.1.3":
version "4.1.4"
resolved "https://registry.yarnpkg.com/@sideway/address/-/address-4.1.4.tgz#03dccebc6ea47fdc226f7d3d1ad512955d4783f0"
Expand Down Expand Up @@ -7260,7 +7334,7 @@ tr46@~0.0.3:
resolved "https://registry.yarnpkg.com/tr46/-/tr46-0.0.3.tgz#8184fd347dac9cdc185992f3a6622e14b9d9ab6a"
integrity sha512-N3WMsuqV66lT30CrXNbEjx4GEwlow3v6rr4mCcv6prnfwhS01rkgyFdjPNBYd9br7LpXV1+Emh01fHnq2Gdgrw==

tslib@^1.8.1:
tslib@^1.8.1, tslib@^1.9.3:
version "1.14.1"
resolved "https://registry.yarnpkg.com/tslib/-/tslib-1.14.1.tgz#cf2d38bdc34a134bcaf1091c41f6619e2f672d00"
integrity sha512-Xni35NKzjgMrwevysHTCArtLDpPvye8zV/0E4EyYn43P7/7qvQwPh9BGkHewbMulVntbigmcT7rdX3BNo9wRJg==
Expand Down

0 comments on commit 584c33f

Please sign in to comment.