@umituz/react-native-sentry 1.2.1 → 1.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md
CHANGED
|
@@ -73,6 +73,25 @@ function MyComponent() {
|
|
|
73
73
|
}
|
|
74
74
|
```
|
|
75
75
|
|
|
76
|
+
### Test Helpers (Production/TestFlight)
|
|
77
|
+
|
|
78
|
+
Verify Sentry is working in production builds:
|
|
79
|
+
|
|
80
|
+
```typescript
|
|
81
|
+
import { sendTestError, sendTestMessage, runTestSuite } from '@umituz/react-native-sentry';
|
|
82
|
+
|
|
83
|
+
// Send a single test error
|
|
84
|
+
sendTestError();
|
|
85
|
+
|
|
86
|
+
// Send a test message
|
|
87
|
+
sendTestMessage();
|
|
88
|
+
|
|
89
|
+
// Run complete test suite
|
|
90
|
+
runTestSuite('user-123');
|
|
91
|
+
```
|
|
92
|
+
|
|
93
|
+
Add a debug button in your app (e.g., Settings screen) to trigger these tests in TestFlight builds.
|
|
94
|
+
|
|
76
95
|
## License
|
|
77
96
|
|
|
78
97
|
MIT
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@umituz/react-native-sentry",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.3.0",
|
|
4
4
|
"description": "Production-ready error tracking and performance monitoring for React Native apps",
|
|
5
5
|
"main": "./src/index.ts",
|
|
6
6
|
"types": "./src/index.ts",
|
|
@@ -48,4 +48,4 @@
|
|
|
48
48
|
"README.md",
|
|
49
49
|
"LICENSE"
|
|
50
50
|
]
|
|
51
|
-
}
|
|
51
|
+
}
|
package/src/global.d.ts
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Global type declarations for React Native environment
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
declare const __DEV__: boolean;
|
|
6
|
+
|
|
7
|
+
declare const console: {
|
|
8
|
+
log(...args: any[]): void;
|
|
9
|
+
warn(...args: any[]): void;
|
|
10
|
+
error(...args: any[]): void;
|
|
11
|
+
info(...args: any[]): void;
|
|
12
|
+
debug(...args: any[]): void;
|
|
13
|
+
};
|
package/src/index.ts
CHANGED
|
@@ -45,3 +45,11 @@ export {
|
|
|
45
45
|
trackPackageEvent,
|
|
46
46
|
} from './presentation/utils/sentryTracking';
|
|
47
47
|
export type { PackageErrorContext } from './presentation/utils/sentryTracking';
|
|
48
|
+
|
|
49
|
+
// Test Helpers (for verifying Sentry in production/TestFlight)
|
|
50
|
+
export {
|
|
51
|
+
sendTestError,
|
|
52
|
+
sendTestMessage,
|
|
53
|
+
setTestUser,
|
|
54
|
+
runTestSuite,
|
|
55
|
+
} from './presentation/utils/testHelpers';
|
|
@@ -4,6 +4,7 @@
|
|
|
4
4
|
*/
|
|
5
5
|
|
|
6
6
|
import * as Sentry from '@sentry/react-native';
|
|
7
|
+
import type { SeverityLevel } from '@sentry/types';
|
|
7
8
|
import type { SentryConfig } from '../../domain/entities/SentryConfig';
|
|
8
9
|
import type { UserData, Breadcrumb } from '../../domain/value-objects/ErrorMetadata';
|
|
9
10
|
import type { CaptureMetadata, MessageLevel } from '../../application/ports/ISentryClient';
|
|
@@ -39,20 +40,10 @@ export const nativeSentryAdapter: NativeSentryAdapter = {
|
|
|
39
40
|
debug: config.debug ?? false,
|
|
40
41
|
enableAutoPerformanceTracing: true,
|
|
41
42
|
enableNativeCrashHandling: true,
|
|
42
|
-
|
|
43
|
-
// Session Replay
|
|
44
|
-
replaysSessionSampleRate: config.replaysSessionSampleRate ?? 0.1,
|
|
45
|
-
replaysOnErrorSampleRate: config.replaysOnErrorSampleRate ?? 1.0,
|
|
46
43
|
integrations: integrations.length > 0 ? integrations : undefined,
|
|
47
|
-
|
|
48
|
-
// Logs
|
|
49
|
-
enableLogs: config.enableLogs ?? false,
|
|
50
|
-
|
|
51
|
-
// PII
|
|
52
44
|
sendDefaultPii: config.sendDefaultPii ?? false,
|
|
53
45
|
|
|
54
|
-
beforeSend: (event) => {
|
|
55
|
-
// Privacy: Mask email in production unless sendDefaultPii is true
|
|
46
|
+
beforeSend: (event: any) => {
|
|
56
47
|
if (!__DEV__ && !config.sendDefaultPii && event.user?.email) {
|
|
57
48
|
event.user.email = '***@***.***';
|
|
58
49
|
}
|
|
@@ -71,7 +62,7 @@ export const nativeSentryAdapter: NativeSentryAdapter = {
|
|
|
71
62
|
|
|
72
63
|
captureMessage(message: string, level?: MessageLevel, metadata?: CaptureMetadata): string | undefined {
|
|
73
64
|
return Sentry.captureMessage(message, {
|
|
74
|
-
level: level as
|
|
65
|
+
level: level as SeverityLevel,
|
|
75
66
|
tags: metadata?.tags,
|
|
76
67
|
extra: metadata?.extra,
|
|
77
68
|
user: metadata?.user,
|
|
@@ -82,7 +73,7 @@ export const nativeSentryAdapter: NativeSentryAdapter = {
|
|
|
82
73
|
Sentry.addBreadcrumb({
|
|
83
74
|
message: breadcrumb.message,
|
|
84
75
|
category: breadcrumb.category,
|
|
85
|
-
level: breadcrumb.level as
|
|
76
|
+
level: breadcrumb.level as SeverityLevel,
|
|
86
77
|
data: breadcrumb.data,
|
|
87
78
|
timestamp: breadcrumb.timestamp,
|
|
88
79
|
});
|
|
@@ -0,0 +1,164 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Sentry Test Helpers
|
|
3
|
+
* Utilities for testing Sentry integration in production/TestFlight
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
import { SentryClient } from '../../infrastructure/config/SentryClient';
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* Send test error to Sentry
|
|
10
|
+
* Use this to verify Sentry is working in production builds
|
|
11
|
+
*
|
|
12
|
+
* @example
|
|
13
|
+
* import { sendTestError } from '@umituz/react-native-sentry';
|
|
14
|
+
* sendTestError(); // In a debug button
|
|
15
|
+
*/
|
|
16
|
+
export function sendTestError(): void {
|
|
17
|
+
if (!SentryClient.isInitialized()) {
|
|
18
|
+
/* eslint-disable-next-line no-console */
|
|
19
|
+
if (__DEV__) {
|
|
20
|
+
console.warn('[Sentry Test] Not initialized, cannot send test error');
|
|
21
|
+
}
|
|
22
|
+
return;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
try {
|
|
26
|
+
SentryClient.addBreadcrumb({
|
|
27
|
+
category: 'test',
|
|
28
|
+
message: 'Test breadcrumb added',
|
|
29
|
+
level: 'info',
|
|
30
|
+
data: { timestamp: new Date().toISOString() },
|
|
31
|
+
});
|
|
32
|
+
|
|
33
|
+
const error = new Error(
|
|
34
|
+
`[TEST] Sentry verification - ${new Date().toISOString()}`
|
|
35
|
+
);
|
|
36
|
+
SentryClient.captureException(error, {
|
|
37
|
+
tags: { test: 'true', type: 'verification' },
|
|
38
|
+
extra: { purpose: 'Testing Sentry integration', timestamp: Date.now() },
|
|
39
|
+
});
|
|
40
|
+
|
|
41
|
+
/* eslint-disable-next-line no-console */
|
|
42
|
+
if (__DEV__) {
|
|
43
|
+
console.log('✅ Test error sent to Sentry');
|
|
44
|
+
}
|
|
45
|
+
} catch (error) {
|
|
46
|
+
/* eslint-disable-next-line no-console */
|
|
47
|
+
if (__DEV__) {
|
|
48
|
+
console.error('[Sentry Test] Failed to send test error:', error);
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
/**
|
|
54
|
+
* Send test message to Sentry
|
|
55
|
+
* Lighter alternative to sendTestError for verification
|
|
56
|
+
*
|
|
57
|
+
* @example
|
|
58
|
+
* import { sendTestMessage } from '@umituz/react-native-sentry';
|
|
59
|
+
* sendTestMessage();
|
|
60
|
+
*/
|
|
61
|
+
export function sendTestMessage(): void {
|
|
62
|
+
if (!SentryClient.isInitialized()) {
|
|
63
|
+
/* eslint-disable-next-line no-console */
|
|
64
|
+
if (__DEV__) {
|
|
65
|
+
console.warn('[Sentry Test] Not initialized, cannot send test message');
|
|
66
|
+
}
|
|
67
|
+
return;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
try {
|
|
71
|
+
const message = `[TEST] Sentry message verification - ${new Date().toISOString()}`;
|
|
72
|
+
SentryClient.captureMessage(message, 'info', {
|
|
73
|
+
tags: { test: 'true', type: 'message' },
|
|
74
|
+
extra: { timestamp: Date.now() },
|
|
75
|
+
});
|
|
76
|
+
|
|
77
|
+
/* eslint-disable-next-line no-console */
|
|
78
|
+
if (__DEV__) {
|
|
79
|
+
console.log('✅ Test message sent to Sentry');
|
|
80
|
+
}
|
|
81
|
+
} catch (error) {
|
|
82
|
+
/* eslint-disable-next-line no-console */
|
|
83
|
+
if (__DEV__) {
|
|
84
|
+
console.error('[Sentry Test] Failed to send test message:', error);
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
/**
|
|
90
|
+
* Set test user context
|
|
91
|
+
* Verify user tracking is working
|
|
92
|
+
*
|
|
93
|
+
* @param userId - User ID to test with
|
|
94
|
+
*
|
|
95
|
+
* @example
|
|
96
|
+
* import { setTestUser } from '@umituz/react-native-sentry';
|
|
97
|
+
* setTestUser('test-user-123');
|
|
98
|
+
*/
|
|
99
|
+
export function setTestUser(userId: string): void {
|
|
100
|
+
if (!SentryClient.isInitialized()) {
|
|
101
|
+
/* eslint-disable-next-line no-console */
|
|
102
|
+
if (__DEV__) {
|
|
103
|
+
console.warn('[Sentry Test] Not initialized, cannot set test user');
|
|
104
|
+
}
|
|
105
|
+
return;
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
try {
|
|
109
|
+
SentryClient.setUser({
|
|
110
|
+
id: userId,
|
|
111
|
+
extras: {
|
|
112
|
+
testMode: true,
|
|
113
|
+
testTimestamp: new Date().toISOString(),
|
|
114
|
+
},
|
|
115
|
+
});
|
|
116
|
+
|
|
117
|
+
/* eslint-disable-next-line no-console */
|
|
118
|
+
if (__DEV__) {
|
|
119
|
+
console.log('✅ Test user set in Sentry:', userId);
|
|
120
|
+
}
|
|
121
|
+
} catch (error) {
|
|
122
|
+
/* eslint-disable-next-line no-console */
|
|
123
|
+
if (__DEV__) {
|
|
124
|
+
console.error('[Sentry Test] Failed to set test user:', error);
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
/**
|
|
130
|
+
* Send comprehensive test suite
|
|
131
|
+
* Tests breadcrumbs, user context, message and error tracking
|
|
132
|
+
*
|
|
133
|
+
* @param userId - Optional user ID for testing user context
|
|
134
|
+
*
|
|
135
|
+
* @example
|
|
136
|
+
* import { runTestSuite } from '@umituz/react-native-sentry';
|
|
137
|
+
* runTestSuite('user-123');
|
|
138
|
+
*/
|
|
139
|
+
export function runTestSuite(userId?: string): void {
|
|
140
|
+
if (!SentryClient.isInitialized()) {
|
|
141
|
+
/* eslint-disable-next-line no-console */
|
|
142
|
+
if (__DEV__) {
|
|
143
|
+
console.warn('[Sentry Test] Not initialized, cannot run test suite');
|
|
144
|
+
}
|
|
145
|
+
return;
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
/* eslint-disable-next-line no-console */
|
|
149
|
+
if (__DEV__) {
|
|
150
|
+
console.log('🧪 Running Sentry test suite...');
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
if (userId) {
|
|
154
|
+
setTestUser(userId);
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
sendTestMessage();
|
|
158
|
+
sendTestError();
|
|
159
|
+
|
|
160
|
+
/* eslint-disable-next-line no-console */
|
|
161
|
+
if (__DEV__) {
|
|
162
|
+
console.log('✅ Sentry test suite completed. Check Sentry dashboard.');
|
|
163
|
+
}
|
|
164
|
+
}
|