Skip to content

Commit 293680e

Browse files
author
deepakglobant
committed
Merge branch 'main' of https://github.com/monkvision/monkjs into feature/MN-176/factorize-monitor-code
2 parents 605e0d4 + 4ef6117 commit 293680e

File tree

8 files changed

+96
-106
lines changed

8 files changed

+96
-106
lines changed

.github/workflows/webapp-deploy.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ jobs:
5050
cache: yarn
5151
- name: Setup Expo
5252
run: |
53-
yarn global add expo-cli
53+
yarn global add expo-cli@6.1.0
5454
- name: Build
5555
run: |
5656
yarn install

monkjs-4.0.0/packages/sights/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"name": "@monkvision/sights4.0.0",
2+
"name": "@monkvision/sights4",
33
"version": "4.0.0",
44
"license": "BSD-3-Clause-Clear",
55
"packageManager": "[email protected]",

packages/corejs/src/hooks/index.ts

Lines changed: 0 additions & 1 deletion
This file was deleted.

packages/corejs/src/hooks/useMonitoring/index.ts

Lines changed: 0 additions & 12 deletions
This file was deleted.

packages/corejs/src/index.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@ import * as entity from './entities';
44
import * as schemas from './schemas';
55
import * as slices from './slices';
66
import * as types from './types';
7-
export * from './hooks';
7+
8+
export * from "./monitoring";
89

910
const reducers = {};
1011
Object.values(slices).forEach((slice) => {
Lines changed: 87 additions & 83 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import React, { createContext, useEffect, useMemo } from 'react';
1+
import React, { createContext, useContext, useEffect, useMemo } from 'react';
22
import { Primitive } from '@sentry/types';
33
import { CaptureConsole } from '@sentry/integrations';
44
import { Integrations } from '@sentry/tracing';
@@ -12,22 +12,22 @@ import { MonitoringContextType } from './types';
1212

1313
const tracingOrigins = ['localhost', 'cna.dev.monk.ai', 'cna.staging.monk.ai', 'cna.preview.monk.ai', 'cna.monk.ai'];
1414
const MonitoringConstants = {
15-
type: {
16-
UPLOAD: 'upload', // logs linked to the upload
17-
CAMERA: 'camera', // logs linked to the camera
18-
FUNC: 'func', // logs linked to a function
19-
APP: 'app', // logs linked to the application
20-
HTTP: 'http', // logs linked to the api
21-
},
22-
operation: {
23-
HTTP: 'http',
24-
USER_TIME: 'user-time-per-action',
25-
USER_CAMERA_TIME: 'user-camera-time',
26-
USER_UPLOAD_CENTER_TIME: 'user-upload-center-time',
27-
USER_ACTION: 'user-action',
28-
RESPONSE_TIME: 'response-time',
29-
FUNC: 'func',
30-
},
15+
type: {
16+
UPLOAD: 'upload', // logs linked to the upload
17+
CAMERA: 'camera', // logs linked to the camera
18+
FUNC: 'func', // logs linked to a function
19+
APP: 'app', // logs linked to the application
20+
HTTP: 'http', // logs linked to the api
21+
},
22+
operation: {
23+
HTTP: 'http',
24+
USER_TIME: 'user-time-per-action',
25+
USER_CAMERA_TIME: 'user-camera-time',
26+
USER_UPLOAD_CENTER_TIME: 'user-upload-center-time',
27+
USER_ACTION: 'user-action',
28+
RESPONSE_TIME: 'response-time',
29+
FUNC: 'func',
30+
},
3131
};
3232

3333
const Tracing = Integrations.BrowserTracing;
@@ -36,91 +36,95 @@ const setUser = (id: string) => SentryR.setUser({ id });
3636
const MonitoringContext = createContext<MonitoringContextType | null>(null);
3737

3838
function MonitoringProvider({ children, config }) {
39-
useEffect(() => {
40-
Sentry.init({
41-
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
42-
dsn: (config.dns || Constants.manifest.extra.SENTRY_DSN) as string,
43-
environment: Constants.manifest.extra.ENV as string,
44-
debug: Constants.manifest.extra.ENV !== 'production',
45-
enableAutoSessionTracking: true,
46-
enableInExpoDevelopment: true,
47-
sessionTrackingIntervalMillis: 10000,
48-
tracesSampleRate: Constants.manifest.extra.ENV !== 'production' ? 1.0 : 0.2,
49-
integrations: [
50-
...(Platform.select({
51-
web: [new CaptureConsole({ levels: ['log'] })],
52-
native: [],
53-
})),
54-
new Tracing({
55-
tracingOrigins,
56-
}),
57-
],
58-
} as Sentry.SentryExpoNativeOptions);
59-
}, []);
39+
useEffect(() => {
40+
Sentry.init({
41+
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
42+
dsn: (config.dns || Constants.manifest.extra.SENTRY_DSN) as string,
43+
environment: Constants.manifest.extra.ENV as string,
44+
debug: Constants.manifest.extra.ENV !== 'production',
45+
enableAutoSessionTracking: true,
46+
enableInExpoDevelopment: true,
47+
sessionTrackingIntervalMillis: 10000,
48+
tracesSampleRate: Constants.manifest.extra.ENV !== 'production' ? 1.0 : 0.2,
49+
integrations: [
50+
...(Platform.select({
51+
web: [new CaptureConsole({ levels: ['log'] })],
52+
native: [],
53+
})),
54+
new Tracing({
55+
tracingOrigins,
56+
}),
57+
],
58+
} as Sentry.SentryExpoNativeOptions);
59+
}, []);
6060

61-
/**
62-
* @param error {Error} - Caught error to send to Sentry.io
63-
* @param type {string} - tag of the error's type
64-
* @param extras {Record} - Useful information that can be sent (request's body for example)
65-
* @param additionalTags - (Optional) Additional tags to add to the error
66-
*/
67-
const errorHandler = (error: Error | string): string => {
68-
if (!Sentry || (!Sentry?.Browser && !Sentry?.Native)) { return null; }
61+
/**
62+
* @param error {Error} - Caught error to send to Sentry.io
63+
* @param type {string} - tag of the error's type
64+
* @param extras {Record} - Useful information that can be sent (request's body for example)
65+
* @param additionalTags - (Optional) Additional tags to add to the error
66+
*/
67+
const errorHandler = (error: Error | string): string => {
68+
if (!Sentry || (!Sentry?.Browser && !Sentry?.Native)) { return null; }
6969

70-
return Platform.select({
71-
web: Sentry.Browser,
72-
native: Sentry.Browser,
73-
}).captureException(error);
74-
};
70+
return Platform.select({
71+
web: Sentry.Browser,
72+
native: Sentry.Browser,
73+
}).captureException(error);
74+
};
7575

76-
/**
77-
* @param name {string} - Name of transaction
78-
* @param operation {string} - Operation of transaction to be performed
79-
* @param data {{[key: string]: number | string}} - Data to be added on transaction
80-
*/
81-
const measurePerformance = (name: string, operation: string, data: { [key: string]: number | string } | null) => {
82-
const transaction = Platform.select({
83-
web: Sentry.Browser,
84-
native: Sentry.Browser,
85-
}).startTransaction({ name, data });
86-
const transactionOperation = transaction.startChild({ op: operation });
76+
/**
77+
* @param name {string} - Name of transaction
78+
* @param operation {string} - Operation of transaction to be performed
79+
* @param data {{[key: string]: number | string}} - Data to be added on transaction
80+
*/
81+
const measurePerformance = (name: string, operation: string, data: { [key: string]: number | string } | null) => {
82+
const transaction = Platform.select({
83+
web: Sentry.Browser,
84+
native: Sentry.Browser,
85+
}).startTransaction({ name, data });
86+
const transactionOperation = transaction.startChild({ op: operation });
8787

88-
return () => {
89-
transactionOperation.finish();
90-
transaction.finish();
91-
};
92-
};
88+
return () => {
89+
transactionOperation.finish();
90+
transaction.finish();
91+
};
92+
};
9393

9494
const monitoringContextValue = useMemo(
9595
() => ({ errorHandler, measurePerformance }),
9696
[errorHandler, measurePerformance],
9797
);
9898

99-
return (
100-
<MonitoringContext.Provider value={monitoringContextValue}>
101-
{children}
102-
</MonitoringContext.Provider>
103-
);
99+
return (
100+
<MonitoringContext.Provider value={monitoringContextValue}>
101+
{children}
102+
</MonitoringContext.Provider>
103+
);
104104
}
105105

106-
export default MonitoringProvider;
106+
const useMonitoring = () => {
107+
return useContext(MonitoringContext);
108+
}
107109

108110
export {
109-
MonitoringContext,
110-
setTag,
111-
setUser,
112-
Tracing,
113111
MonitoringConstants,
112+
MonitoringContext,
113+
setTag,
114+
setUser,
115+
Tracing,
116+
MonitoringProvider,
117+
useMonitoring,
114118
};
115119

116120
MonitoringProvider.propTypes = {
117-
config: PropTypes.shape({
118-
dns: PropTypes.string,
119-
}),
121+
config: PropTypes.shape({
122+
dns: PropTypes.string,
123+
}),
120124
};
121125

122126
MonitoringProvider.defaultProps = {
123-
config: {
124-
dns: '',
125-
},
127+
config: {
128+
dns: '',
129+
},
126130
};

src/components/App.js

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ import { StyleSheet, useWindowDimensions, View } from 'react-native';
1616
import { DefaultTheme, Provider as PaperProvider } from 'react-native-paper';
1717
import { Provider } from 'react-redux';
1818
import store from 'store';
19-
// import { useMonitoring } from '@monkvision/corejs';
19+
import { useMonitoring } from '@monkvision/corejs';
2020

2121
const theme = {
2222
...DefaultTheme,
@@ -39,7 +39,7 @@ function App() {
3939
const { height: minHeight } = useWindowDimensions();
4040
const { t } = useTranslation();
4141

42-
// const [errorHandler] = useMonitoring();
42+
const { errorHandler } = useMonitoring();
4343
const [appIsReady, setAppIsReady] = useState(false);
4444

4545
const onLayoutRootView = useCallback(async () => {
@@ -52,13 +52,12 @@ function App() {
5252
try {
5353
await SplashScreen.hideAsync();
5454
} catch (err) {
55-
// errorHandler(err);
55+
errorHandler(err);
5656
}
5757
}
5858
}, [appIsReady]);
5959

6060
useEffect(() => {
61-
// errorHandler('Use Monitoring Error Checking');
6261
async function prepare() {
6362
try {
6463
// Keep the splash screen visible while we fetch resources
@@ -69,7 +68,7 @@ function App() {
6968
// experience. Please remove this if you copy and paste the code!
7069
// await new Promise((resolve) => { setTimeout(resolve, 2000); });
7170
} catch (err) {
72-
// errorHandler(err);
71+
errorHandler(err);
7372
} finally {
7473
// Tell the application to render
7574
setAppIsReady(true);

src/main.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,7 @@ import { Platform } from 'react-native';
55
import * as Sentry from 'sentry-expo';
66
import App from 'components/App';
77
import './i18n';
8-
9-
import MonitoringProvider from '@monkvision/corejs/src/monitoring';
8+
import { MonitoringProvider } from '@monkvision/corejs';
109

1110
if (Platform.OS === 'web') {
1211
const container = document.getElementById('root');

0 commit comments

Comments
 (0)