Skip to content

Commit 7cb9cc4

Browse files
authored
Implement flipper pluggin (#14)
* IM-0 - readapt reactotron + bump version * IM-0 - cleaning * IM-0 - add tealium and adobbe * IM-0 - add travis and improve docs * IM-0 - imrove readme * IM-0 - add exclusion feature and update docs * IM-0 - clean * IM-0 - small clean * IM-0 - improve docs * IM-0 - improve docs * Update REFERENCE_API.md * Update README.md * IM-0 - upgrade package * IM-0 - implement flipper plugin * IM-0 - update docs + bump version * IM-0 - fix test * IM-0 - fix jest timezone Co-authored-by: Imran Mentese <imran.mentese@arhs-spikeseed.com>
1 parent b18bbf0 commit 7cb9cc4

19 files changed

+205
-65
lines changed

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
# Changelog
22

3+
### Version 1.2.0
4+
5+
- News
6+
- Can be plugged to Flipper with `flipper-plugin-react-native-logging-tools` to display all events sent to different service.
7+
38
### Version 1.1.0
49

510
- News

README.md

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ A react native module that lets you:
99
- Send logs to multiple services in one time
1010
- Send crash/error reports to multiple services in one time
1111
- Register a global error handler which will capture fatal JS exceptions and send a report to your crash reporter libraries
12+
- Can be plugged to Flipper to display all events sent to different service.
1213

1314
and all this, as easily as possible
1415

@@ -23,6 +24,7 @@ and all this, as easily as possible
2324
- [Error Events](#error-events)
2425
- [Reactotron](#reactotron)
2526
- [JS Error handler](#js-error-handler)
27+
- [Flipper](#flipper)
2628

2729
---
2830

@@ -94,7 +96,7 @@ init({
9496
});
9597
```
9698

97-
:information_source: Documentation and example about initialization steps can be found [here](./REFERENCE_API.md).
99+
:information_source: Documentation and example about initialization steps can be found [here](./REFERENCE_API.md#init).
98100

99101
### Features
100102

@@ -112,7 +114,7 @@ logNetworkEvent('EVENT_NAME', { your_key: 'value', ... });
112114
logErrorEvent('EVENT_NAME', { your_key: 'value', ... });
113115
```
114116

115-
:information_source: Documentation and example about logging event can be found [here](./REFERENCE_API.md).
117+
:information_source: Documentation and example about logging event can be found [here](./REFERENCE_API.md#logEvent).
116118

117119
If you use `react-navigation` and you want send to analytics navigation events e.g, you can add `logEvent` to his event handler [(React-navigation docs)](https://reactnavigation.org/docs/navigation-events/)
118120

@@ -125,12 +127,17 @@ You can call this function where do you want/need to send logs to each plugged l
125127
recordError('EVENT_NAME', { your_key: 'value', ... });
126128
```
127129

128-
:information_source: Documentation and example about error reporting can be found [here](./REFERENCE_API.md).
130+
:information_source: Documentation and example about error reporting can be found [here](./REFERENCE_API.md#recordError).
129131

130132
#### Reactotron
131133

132-
:information_source: Documentation and example about Reactotron can be found [here](./REFERENCE_API.md).
134+
:information_source: Documentation and example about Reactotron can be found [here](./REFERENCE_API.md#setupreactotron).
133135

134136
#### JS Error handler
135137

136-
:information_source: Documentation and example about Reactotron can be found [here](./REFERENCE_API.md).
138+
:information_source: Documentation and example about Reactotron can be found [here](./REFERENCE_API.md#init).
139+
140+
#### Flipper
141+
142+
:information_source: Documentation about Flipper can be found [here](./REFERENCE_API.md#flipper).
143+

REFERENCE_API.md

Lines changed: 24 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -19,14 +19,18 @@ Page containing the full index of all React Native Logging Tools reference API t
1919
- [logNetworkEvent](#lognetworkevent)
2020
- [logErrorEvent](#logerrorevent)
2121
- [recordError](#recorderror)
22+
- [Flipper](#flipper)
2223
- [Supported libraries](#supported-libraries)
2324
- [Firebase crashlytics](#firebase-crashlytics)
2425
- [Firebase analytics](#firebase-analytics)
2526
- [Sentry](#sentry)
27+
- [Instabug](#instabug)
28+
- [Adobe](#adobe)
29+
- [Tealium](#tealium)
2630

2731
## API
2832

29-
### init
33+
### <a name="init">init</a>
3034

3135
Library initializer, to be used before anything
3236

@@ -38,6 +42,7 @@ init is an object which take three keys/values:
3842
- `AsyncStorage`: from @react-native-community/async-storage ie (optional)
3943
- `reportJSErrors: boolean`: set to true if you want turn on automatic fetch and send js crash to `errorReporters` (optional)
4044
- `isSensitiveBuild: boolean`: set to true if you want defined some logEvent as sensitive and not send log for this one (optional)
45+
- `useFlipperPlugin: boolean`: set to true if you want use flipper plugin [More details](#flipper) (optional)
4146
- `excludeLogs: object`: to exclude log types to not send to libraries which have been set (optional)
4247

4348
- `adobe: Array<number>`: add to an array, the log types which should *NOT* sent to adobe (optional)
@@ -76,7 +81,7 @@ init({
7681

7782
---
7883

79-
### setupReactotron
84+
### <a name="setupReactotron">setupReactotron</a>
8085

8186
To plug Reactotron to your redux store.
8287

@@ -112,7 +117,7 @@ const store = createStore(
112117

113118
---
114119

115-
### createFirebaseLogger
120+
### <a name="createFirebaseLogger">createFirebaseLogger</a>
116121

117122
To plug Firebase analytics to send event later.
118123

@@ -131,7 +136,7 @@ init({
131136

132137
---
133138

134-
### createSentryLogger
139+
### <a name="createSentryLogger">createSentryLogger</a>
135140

136141
To plug Sentry to send event later.
137142

@@ -152,7 +157,7 @@ init({
152157

153158
---
154159

155-
### createInstabugLogger
160+
### <a name="createInstabugLogger">createInstabugLogger</a>
156161

157162
To plug Instabug to send event later.
158163

@@ -174,7 +179,7 @@ init({
174179

175180
---
176181

177-
### createTealiumLogger
182+
### <a name="createTealiumLogger">createTealiumLogger</a>
178183

179184
To plug Tealium to send event later.
180185

@@ -203,7 +208,7 @@ init({
203208

204209
---
205210

206-
### createAdobeLogger
211+
### <a name="createAdobeLogger">createAdobeLogger</a>
207212

208213
To plug Adobe to send event later.
209214

@@ -223,7 +228,7 @@ init({
223228

224229
---
225230

226-
### createCrashlyticsLogger
231+
### <a name="createCrashlyticsLogger">createCrashlyticsLogger</a>
227232

228233
To plug Firebase crashlytics to send event later.
229234

@@ -242,7 +247,7 @@ init({
242247

243248
---
244249

245-
### logEvent
250+
### <a name="logEvent">logEvent</a>
246251

247252
To send an event to analytics services
248253

@@ -260,7 +265,7 @@ logEvent('EVENT_NAME', { your_key: 'value' }, true);
260265

261266
---
262267

263-
### logDebugEvent
268+
### <a name="logDebugEvent">logDebugEvent</a>
264269

265270
To send an event to analytics services, it's the same as `logEvent` but it will
266271
- Automatically prefix the event name with `D/` to facilitate the reading
@@ -299,7 +304,7 @@ logDebugEvent('EVENT_NAME', { your_key: 'value' }, true);
299304

300305
---
301306

302-
### logWarningEvent
307+
### <a name="logWarningEvent">logWarningEvent</a>
303308

304309
To send an event to analytics services, it's the same as `logEvent` but it will:
305310
- Automatically prefix the event name with `W/` to facilitate the reading
@@ -340,7 +345,7 @@ logWarningEvent('EVENT_NAME', { your_key: 'value' }, true);
340345

341346
---
342347

343-
### logNetworkEvent
348+
### <a name="logNetworkEvent">logNetworkEvent</a>
344349

345350
To send an event to analytics services, it's the same as `logEvent` but it will:
346351
- Automatically prefix the event name with `N/` to facilitate the reading
@@ -379,7 +384,7 @@ logNetworkEvent('EVENT_NAME', { your_key: 'value' }, true);
379384

380385
---
381386

382-
### logErrorEvent
387+
### <a name="logErrorEvent">logErrorEvent</a>
383388

384389
To send an event to analytics services, it's the same as `logEvent` but it will:
385390
- Automatically prefix the event name with `E/` to facilitate the reading
@@ -417,7 +422,7 @@ logErrorEvent('EVENT_NAME', { your_key: 'value' }, true);
417422

418423
---
419424

420-
### recordError
425+
### <a name="recordError">recordError</a>
421426

422427
To send an error report to error reporter services
423428

@@ -434,6 +439,11 @@ recordError('EVENT_NAME', { your_key: 'value' });
434439

435440
---
436441

442+
### <a name="flipper">Flipper</a>
443+
444+
You can display all events sent to different service on Flipper desktop app.
445+
Follow plugin's documentation to install it [link](https://github.com/imranMnts/flipper-plugin-react-native-logging-tools) and set `useFlipperPlugin` to true during initialization to be able to use it.
446+
437447
### Supported libraries
438448

439449
#### Firebase crashlytics

jest.setup.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,5 @@ import Adapter from 'enzyme-adapter-react-16';
33

44
configure({ adapter: new Adapter() });
55

6+
jest.mock('react-native-flipper');
7+

package.json

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,15 @@
11
{
22
"name": "react-native-logging-tools",
33
"title": "React Native library created to ease logging",
4-
"version": "1.1.0",
4+
"version": "1.2.0",
55
"main": "src/index.ts",
66
"typings": "index.d.ts",
7-
"publishConfig": { "registry": "https://npm.pkg.github.com/" },
87
"scripts": {
98
"prettier:fix": "prettier --config ./.prettierrc.js --write --check \"src/**/*.ts\" ",
109
"lint:fix": "tslint -p tsconfig.json --fix 'src/**/*.tsx' 'src/**/*.ts'",
1110
"precommit": "yarn run prettier:fix && yarn run lint:fix && yarn run tsc",
12-
"test": "jest",
13-
"testu": "node_modules/.bin/jest --updateSnapshot --i",
11+
"test": "TZ=UTC jest",
12+
"testu": "TZ=UTC node_modules/.bin/jest --updateSnapshot --i",
1413
"tsc": "tsc"
1514
},
1615
"keywords": [
@@ -43,6 +42,7 @@
4342
"instabug-reactnative": ">=9.0.0",
4443
"react": "^16.8.1",
4544
"react-native": ">=0.60.0-rc.0 <1.0.x",
45+
"react-native-flipper": ">=0.50.0",
4646
"reactotron-react-native": ">=4.0.0",
4747
"reactotron-redux": ">=3.0.0",
4848
"tealium-react-native": ">=1.0.10"
@@ -57,6 +57,7 @@
5757
"react": "16.13.1",
5858
"react-dom": "^16.13.0",
5959
"react-native": "0.63.0",
60+
"react-native-flipper": "^0.50.0",
6061
"reactotron-react-native": "4.0.2",
6162
"reactotron-redux": "^3.1.2",
6263
"ts-jest": "^25.0.0",
@@ -84,7 +85,7 @@
8485
},
8586
"testRegex": "(/__tests__/.*|\\.(test|spec))\\.(ts|tsx|js)$",
8687
"transformIgnorePatterns": [
87-
"./node_modules/(?!react-native|react-navigation|react-navigation-stack|reactotron-react-native|react-native-localize)/"
88+
"./node_modules/(?!react-native)/"
8889
],
8990
"coverageThreshold": {
9091
"global": {

src/__tests__/index.spec.ts

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ import {
44
createFirebaseLogger,
55
createAdobeLogger,
66
createTealiumLogger,
7-
setupReactotron,
87
logEvent,
98
createCrashlyticsLogger,
109
recordError,
@@ -58,8 +57,6 @@ describe('index test suite', () => {
5857
};
5958
const configTealium: ITealium = { account: 'accountName', profile: 'profileName', environment: 'environment' };
6059

61-
const AsyncStorage = jest.fn();
62-
const reactotronRedux = jest.fn();
6360
const Reactotron = {
6461
configure: () => Reactotron,
6562
setAsyncStorageHandler: () => Reactotron,
@@ -92,6 +89,7 @@ describe('index test suite', () => {
9289
it('should init properly and log event with reject', () => {
9390
init({
9491
config: {
92+
useFlipperPlugin: true,
9593
excludeLogs: {
9694
instabug: [DEBUG_LOG],
9795
tealium: [DEBUG_LOG],
@@ -105,17 +103,23 @@ describe('index test suite', () => {
105103
createInstabugLogger(instabug, { invocationEvent: 'shake', token: 'token' }),
106104
createTealiumLogger(Tealium, configTealium),
107105
createAdobeLogger(ACPAnalytics, ACPCore),
108-
createFirebaseLogger({}),
109-
createSentryLogger({ init: jest.fn() }, { dsn: 'dsn' }),
106+
createFirebaseLogger(analytics),
107+
createSentryLogger(sentry, { dsn: 'dsn' }),
110108
createCrashlyticsLogger(crashlytics),
111109
],
112110
});
113111
logDebugEvent('event');
112+
logWarningEvent('event');
114113
});
115114

116115
it('should init not properly 2', () => {
117116
init({
118-
config: { reportJSErrors: true, isSensitiveBuild: true, excludeLogs: { instabug: [DEBUG_LOG] } },
117+
config: {
118+
reportJSErrors: true,
119+
isSensitiveBuild: true,
120+
useFlipperPlugin: true,
121+
excludeLogs: { instabug: [DEBUG_LOG] },
122+
},
119123
});
120124
expect(excludeLogs).toEqual({ instabug: [DEBUG_LOG] });
121125
});
@@ -242,6 +246,11 @@ describe('index test suite', () => {
242246
recordError('error');
243247
});
244248

249+
it('should init properly and record error without flipper', () => {
250+
init({ config: { reportJSErrors: true }, errorReporters: [createCrashlyticsLogger(crashlytics)] });
251+
recordError('error', { key: 'value' });
252+
});
253+
245254
function givenSetSensitiveBuild(isSensitive: boolean = true) {
246255
// @ts-ignore
247256
Init.isSensitiveBuild = isSensitive;

src/flipper/__tests__/index.spec.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import FlipperConnectionManager from '../index';
2+
import { getCurrentDateTime } from '../../helpers/functions';
3+
4+
jest.mock('../../helpers/functions', () => ({
5+
getCurrentDateTime: jest.fn(),
6+
}))
7+
8+
describe('flipper test suite', () => {
9+
it('should init properly flipper and send event', () => {
10+
const flipper = new FlipperConnectionManager();
11+
flipper.handleConnect({ send: jest.fn() });
12+
flipper.send('service', 'event');
13+
expect(getCurrentDateTime).toHaveBeenCalledTimes(1);
14+
flipper.handleDisconnect();
15+
});
16+
});

src/flipper/index.ts

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
import { addPlugin } from 'react-native-flipper';
2+
import { getCurrentDateTime } from '../helpers/functions';
3+
4+
export default class FlipperConnectionManager {
5+
private flipperConnection?: any;
6+
7+
constructor() {
8+
/* istanbul ignore next */addPlugin({
9+
runInBackground: () => true,
10+
getId() {
11+
return 'flipper-plugin-react-native-logging-tools';
12+
},
13+
onConnect: this.handleConnect,
14+
onDisconnect: this.handleDisconnect,
15+
});
16+
}
17+
18+
handleConnect = (connection: any) => {
19+
this.flipperConnection = connection;
20+
};
21+
22+
handleDisconnect = () => {
23+
this.flipperConnection = undefined;
24+
};
25+
26+
send(service: string, event: string, params?: any, error?: any) {
27+
const payload: any = {
28+
service,
29+
event,
30+
params,
31+
error,
32+
time: getCurrentDateTime(),
33+
};
34+
35+
if (this.flipperConnection) {
36+
this.flipperConnection.send('action', payload);
37+
}
38+
}
39+
}

0 commit comments

Comments
 (0)