@echoteam/signoz-react 1.0.0 → 1.0.1

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/LICENSE CHANGED
@@ -1,21 +1,21 @@
1
- MIT License
2
-
3
- Copyright (c) 2024 CODR Team
4
-
5
- Permission is hereby granted, free of charge, to any person obtaining a copy
6
- of this software and associated documentation files (the "Software"), to deal
7
- in the Software without restriction, including without limitation the rights
8
- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
- copies of the Software, and to permit persons to whom the Software is
10
- furnished to do so, subject to the following conditions:
11
-
12
- The above copyright notice and this permission notice shall be included in all
13
- copies or substantial portions of the Software.
14
-
15
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
1
+ MIT License
2
+
3
+ Copyright (c) 2024 CODR Team
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
21
  SOFTWARE.
package/README.md CHANGED
@@ -1,285 +1,286 @@
1
- # @codr/signoz-react
2
-
3
- Library React untuk monitoring dan tracing aplikasi menggunakan OpenTelemetry dan SignOz.
4
-
5
- ## 🚀 Fitur
6
-
7
- - **Tracing Otomatis**: Integrasi OpenTelemetry untuk tracing HTTP requests, fetch, dan XMLHttpRequest
8
- - **Error Boundary**: Komponen React untuk menangkap dan melaporkan error dengan tracing
9
- - **Error Page**: Halaman error untuk React Router dengan integrasi tracing
10
- - **TypeScript Support**: Dukungan penuh untuk TypeScript
11
- - **Zero Configuration**: Mudah digunakan dengan environment variables
12
- - **Customizable**: ErrorPage dan ErrorBoundary dapat dikustomisasi sesuai kebutuhan
13
-
14
- ## 📦 Instalasi
15
-
16
- ```bash
17
- yarn add @codr/signoz-react
18
- ```
19
-
20
- ## 🔧 Konfigurasi
21
-
22
- ### Environment Variables
23
-
24
- Tambahkan environment variables berikut ke file `.env`:
25
-
26
- ```env
27
- REACT_APP_SIGNOZ_SERVICE_NAME=my-react-app
28
- REACT_APP_SIGNOZ_SERVICE_VERSION=1.0.0
29
- REACT_APP_SIGNOZ_ENV=production
30
- REACT_APP_SIGNOZ_SERVICE_NAMESPACE=frontend
31
- REACT_APP_SIGNOZ_URL=https://your-signoz-instance.com/v1/traces
32
- ```
33
-
34
- ### Inisialisasi
35
-
36
- ```typescript
37
- import { initializeSignOzTracing } from '@codr/signoz-react';
38
-
39
- // Inisialisasi dengan environment variables
40
- initializeSignOzTracing();
41
-
42
- // Atau dengan konfigurasi manual
43
- initializeSignOzTracing({
44
- serviceName: 'my-react-app',
45
- serviceVersion: '1.0.0',
46
- environment: 'production',
47
- serviceNamespace: 'frontend',
48
- url: 'https://your-signoz-instance.com/v1/traces',
49
- headers: {
50
- 'Authorization': 'Bearer your-token'
51
- }
52
- });
53
- ```
54
-
55
- ## 🎯 Penggunaan
56
-
57
- ### Error Boundary
58
-
59
- #### Penggunaan Dasar
60
- ```tsx
61
- import { ErrorBoundary } from '@codr/signoz-react';
62
-
63
- function App() {
64
- return (
65
- <ErrorBoundary>
66
- <YourApp />
67
- </ErrorBoundary>
68
- );
69
- }
70
- ```
71
-
72
- #### Error Boundary dengan Kustomisasi
73
- ```tsx
74
- import { ErrorBoundary, ErrorBoundaryProps } from '@codr/signoz-react';
75
-
76
- // Custom fallback component
77
- const CustomErrorFallback: React.FC<{ error: Error; resetErrorBoundary: () => void }> = ({
78
- error,
79
- resetErrorBoundary
80
- }) => (
81
- <div className="custom-error">
82
- <h2>Terjadi Kesalahan!</h2>
83
- <p>{error.message}</p>
84
- <button onClick={resetErrorBoundary}>Coba Lagi</button>
85
- </div>
86
- );
87
-
88
- function App() {
89
- const handleError = (error: Error, errorInfo: React.ErrorInfo) => {
90
- console.log('Error caught:', error);
91
- // Kirim ke service lain jika diperlukan
92
- };
93
-
94
- return (
95
- <ErrorBoundary
96
- fallback={CustomErrorFallback}
97
- onError={handleError}
98
- onReset={() => console.log('Error boundary reset')}
99
- fallbackClassName="my-error-boundary"
100
- >
101
- <YourApp />
102
- </ErrorBoundary>
103
- );
104
- }
105
- ```
106
-
107
- ### Error Page untuk React Router
108
-
109
- #### Penggunaan Dasar
110
- ```tsx
111
- import { ErrorPage } from '@codr/signoz-react';
112
- import { createBrowserRouter } from 'react-router-dom';
113
-
114
- const router = createBrowserRouter([
115
- {
116
- path: "/",
117
- element: <Root />,
118
- errorElement: <ErrorPage />,
119
- },
120
- ]);
121
- ```
122
-
123
- #### Error Page dengan Kustomisasi
124
- ```tsx
125
- import { ErrorPage, ErrorPageProps } from '@codr/signoz-react';
126
-
127
- // Custom error page
128
- const CustomErrorPage: React.FC<ErrorPageProps> = (props) => (
129
- <ErrorPage
130
- title="Halaman Tidak Ditemukan"
131
- message="Maaf, halaman yang Anda cari tidak tersedia."
132
- showStackTrace={process.env.NODE_ENV === 'development'}
133
- actionButton={
134
- <button onClick={() => window.history.back()}>
135
- Kembali ke Halaman Sebelumnya
136
- </button>
137
- }
138
- className="custom-error-page"
139
- />
140
- );
141
-
142
- // Atau dengan custom render function
143
- const CustomErrorPageWithRender: React.FC<ErrorPageProps> = () => (
144
- <ErrorPage
145
- renderError={(error) => (
146
- <div className="my-custom-error">
147
- <h1>🚨 Error!</h1>
148
- <p>Kode Error: {error.name}</p>
149
- <p>Pesan: {error.message}</p>
150
- <button onClick={() => window.location.href = '/'}>
151
- Kembali ke Beranda
152
- </button>
153
- </div>
154
- )}
155
- />
156
- );
157
-
158
- const router = createBrowserRouter([
159
- {
160
- path: "/",
161
- element: <Root />,
162
- errorElement: <CustomErrorPage />,
163
- },
164
- ]);
165
- ```
166
-
167
- ### Tracing Manual
168
-
169
- ```typescript
170
- import { trace } from '@opentelemetry/api';
171
-
172
- const tracer = trace.getTracer('my-service');
173
- const span = tracer.startSpan('my-operation');
174
-
175
- try {
176
- // Lakukan operasi
177
- span.setAttribute('operation.type', 'database-query');
178
- span.setAttribute('operation.result', 'success');
179
- } catch (error) {
180
- span.recordException(error);
181
- span.setStatus({ code: SpanStatusCode.ERROR, message: error.message });
182
- } finally {
183
- span.end();
184
- }
185
- ```
186
-
187
- ## 📋 API Reference
188
-
189
- ### `initializeSignOzTracing(config?)`
190
-
191
- Inisialisasi SignOz tracing untuk aplikasi React.
192
-
193
- **Parameter:**
194
- - `config` (opsional): Konfigurasi SignOz
195
- - `serviceName`: Nama layanan
196
- - `serviceVersion`: Versi layanan
197
- - `environment`: Environment (production, staging, development)
198
- - `serviceNamespace`: Namespace layanan
199
- - `url`: URL endpoint SignOz
200
- - `headers`: Headers tambahan untuk request
201
-
202
- ### `ErrorBoundary`
203
-
204
- Komponen React untuk menangkap error dan melaporkan ke SignOz.
205
-
206
- **Props:**
207
- - `children`: React children
208
- - `fallback`: Custom fallback component
209
- - `onError`: Custom error handler function
210
- - `onReset`: Custom reset handler
211
- - `showResetButton`: Apakah menampilkan reset button (default: true)
212
- - `resetButtonText`: Custom reset button text
213
- - `fallbackClassName`: Custom CSS class untuk fallback
214
-
215
- ### `ErrorPage`
216
-
217
- Komponen halaman error untuk React Router.
218
-
219
- **Props:**
220
- - `title`: Judul halaman error (default: "Oops!")
221
- - `message`: Pesan error utama (default: "Terjadi kesalahan yang tidak terduga.")
222
- - `renderError`: Custom render function untuk menampilkan error
223
- - `className`: Custom CSS class untuk container
224
- - `showStackTrace`: Apakah menampilkan stack trace (default: false)
225
- - `actionButton`: Custom action button
226
-
227
- ## 🔍 Monitoring
228
-
229
- Setelah setup, Anda dapat melihat traces di dashboard SignOz:
230
-
231
- 1. **Service Overview**: Melihat performa layanan secara keseluruhan
232
- 2. **Traces**: Melihat detail traces untuk setiap request
233
- 3. **Errors**: Melihat error yang terjadi dengan stack trace
234
- 4. **Metrics**: Melihat metrics performa aplikasi
235
-
236
- ## 🛠️ Development
237
-
238
- ### Setup Development
239
-
240
- ```bash
241
- # Clone repository
242
- git clone https://gitlab.echoteam.tech/codr/package/signoz-react-js.git
243
- cd signoz-react-js
244
-
245
- # Install dependencies
246
- yarn install
247
-
248
- # Build package
249
- yarn build
250
-
251
- # Development mode
252
- yarn dev
253
- ```
254
-
255
- ### Scripts
256
-
257
- - `yarn build`: Build package untuk production
258
- - `yarn dev`: Build dalam mode development dengan watch
259
- - `yarn test`: Jalankan tests
260
- - `yarn lint`: Lint kode
261
- - `yarn format`: Format kode dengan Prettier
262
-
263
- ## 📄 License
264
-
265
- MIT License - lihat file [LICENSE](LICENSE) untuk detail.
266
-
267
- ## 🤝 Contributing
268
-
269
- 1. Fork repository
270
- 2. Buat feature branch (`git checkout -b feature/amazing-feature`)
271
- 3. Commit perubahan (`git commit -m 'Add amazing feature'`)
272
- 4. Push ke branch (`git push origin feature/amazing-feature`)
273
- 5. Buat Pull Request
274
-
275
- ## 📞 Support
276
-
277
- - **Issues**: [GitLab Issues](https://gitlab.echoteam.tech/codr/package/signoz-react-js/-/issues)
278
- - **Email**: dev@codr.id
279
- - **Documentation**: [GitLab Wiki](https://gitlab.echoteam.tech/codr/package/signoz-react-js/-/wikis)
280
-
281
- ## 🔗 Links
282
-
283
- - [SignOz Documentation](https://signoz.io/docs/)
284
- - [OpenTelemetry Documentation](https://opentelemetry.io/docs/)
285
- - [React Error Boundary](https://reactjs.org/docs/error-boundaries.html)
1
+ # @echoteam/signoz-react
2
+
3
+ Library React untuk monitoring dan tracing aplikasi menggunakan OpenTelemetry dan SignOz.
4
+
5
+ ## 🚀 Fitur
6
+
7
+ - **Tracing Otomatis**: Integrasi OpenTelemetry untuk tracing HTTP requests, fetch, dan XMLHttpRequest
8
+ - **Error Boundary**: Komponen React untuk menangkap dan melaporkan error dengan tracing
9
+ - **Error Page**: Halaman error untuk React Router dengan integrasi tracing
10
+ - **TypeScript Support**: Dukungan penuh untuk TypeScript
11
+ - **Zero Configuration**: Mudah digunakan dengan environment variables
12
+ - **Customizable**: ErrorPage dan ErrorBoundary dapat dikustomisasi sesuai kebutuhan
13
+
14
+ ## 📦 Instalasi
15
+
16
+ ```bash
17
+ yarn add @echoteam/signoz-react
18
+ npm install @echoteam/signoz-react
19
+ ```
20
+
21
+ ## 🔧 Konfigurasi
22
+
23
+ ### Environment Variables
24
+
25
+ Tambahkan environment variables berikut ke file `.env`:
26
+
27
+ ```env
28
+ REACT_APP_SIGNOZ_SERVICE_NAME=my-react-app
29
+ REACT_APP_SIGNOZ_SERVICE_VERSION=1.0.0
30
+ REACT_APP_SIGNOZ_ENV=production
31
+ REACT_APP_SIGNOZ_SERVICE_NAMESPACE=frontend
32
+ REACT_APP_SIGNOZ_URL=https://your-signoz-instance.com/v1/traces
33
+ ```
34
+
35
+ ### Inisialisasi
36
+
37
+ ```typescript
38
+ import { initializeSignOzTracing } from '@echoteam/signoz-react';
39
+
40
+ // Inisialisasi dengan environment variables
41
+ initializeSignOzTracing();
42
+
43
+ // Atau dengan konfigurasi manual
44
+ initializeSignOzTracing({
45
+ serviceName: 'my-react-app',
46
+ serviceVersion: '1.0.0',
47
+ environment: 'production',
48
+ serviceNamespace: 'frontend',
49
+ url: 'https://your-signoz-instance.com/v1/traces',
50
+ headers: {
51
+ 'Authorization': 'Bearer your-token'
52
+ }
53
+ });
54
+ ```
55
+
56
+ ## 🎯 Penggunaan
57
+
58
+ ### Error Boundary
59
+
60
+ #### Penggunaan Dasar
61
+ ```tsx
62
+ import { ErrorBoundary } from '@echoteam/signoz-react';
63
+
64
+ function App() {
65
+ return (
66
+ <ErrorBoundary>
67
+ <YourApp />
68
+ </ErrorBoundary>
69
+ );
70
+ }
71
+ ```
72
+
73
+ #### Error Boundary dengan Kustomisasi
74
+ ```tsx
75
+ import { ErrorBoundary, ErrorBoundaryProps } from '@echoteam/signoz-react';
76
+
77
+ // Custom fallback component
78
+ const CustomErrorFallback: React.FC<{ error: Error; resetErrorBoundary: () => void }> = ({
79
+ error,
80
+ resetErrorBoundary
81
+ }) => (
82
+ <div className="custom-error">
83
+ <h2>Terjadi Kesalahan!</h2>
84
+ <p>{error.message}</p>
85
+ <button onClick={resetErrorBoundary}>Coba Lagi</button>
86
+ </div>
87
+ );
88
+
89
+ function App() {
90
+ const handleError = (error: Error, errorInfo: React.ErrorInfo) => {
91
+ console.log('Error caught:', error);
92
+ // Kirim ke service lain jika diperlukan
93
+ };
94
+
95
+ return (
96
+ <ErrorBoundary
97
+ fallback={CustomErrorFallback}
98
+ onError={handleError}
99
+ onReset={() => console.log('Error boundary reset')}
100
+ fallbackClassName="my-error-boundary"
101
+ >
102
+ <YourApp />
103
+ </ErrorBoundary>
104
+ );
105
+ }
106
+ ```
107
+
108
+ ### Error Page untuk React Router
109
+
110
+ #### Penggunaan Dasar
111
+ ```tsx
112
+ import { ErrorPage } from '@echoteam/signoz-react';
113
+ import { createBrowserRouter } from 'react-router-dom';
114
+
115
+ const router = createBrowserRouter([
116
+ {
117
+ path: "/",
118
+ element: <Root />,
119
+ errorElement: <ErrorPage />,
120
+ },
121
+ ]);
122
+ ```
123
+
124
+ #### Error Page dengan Kustomisasi
125
+ ```tsx
126
+ import { ErrorPage, ErrorPageProps } from '@echoteam/signoz-react';
127
+
128
+ // Custom error page
129
+ const CustomErrorPage: React.FC<ErrorPageProps> = (props) => (
130
+ <ErrorPage
131
+ title="Halaman Tidak Ditemukan"
132
+ message="Maaf, halaman yang Anda cari tidak tersedia."
133
+ showStackTrace={process.env.NODE_ENV === 'development'}
134
+ actionButton={
135
+ <button onClick={() => window.history.back()}>
136
+ Kembali ke Halaman Sebelumnya
137
+ </button>
138
+ }
139
+ className="custom-error-page"
140
+ />
141
+ );
142
+
143
+ // Atau dengan custom render function
144
+ const CustomErrorPageWithRender: React.FC<ErrorPageProps> = () => (
145
+ <ErrorPage
146
+ renderError={(error) => (
147
+ <div className="my-custom-error">
148
+ <h1>🚨 Error!</h1>
149
+ <p>Kode Error: {error.name}</p>
150
+ <p>Pesan: {error.message}</p>
151
+ <button onClick={() => window.location.href = '/'}>
152
+ Kembali ke Beranda
153
+ </button>
154
+ </div>
155
+ )}
156
+ />
157
+ );
158
+
159
+ const router = createBrowserRouter([
160
+ {
161
+ path: "/",
162
+ element: <Root />,
163
+ errorElement: <CustomErrorPage />,
164
+ },
165
+ ]);
166
+ ```
167
+
168
+ ### Tracing Manual
169
+
170
+ ```typescript
171
+ import { trace } from '@opentelemetry/api';
172
+
173
+ const tracer = trace.getTracer('my-service');
174
+ const span = tracer.startSpan('my-operation');
175
+
176
+ try {
177
+ // Lakukan operasi
178
+ span.setAttribute('operation.type', 'database-query');
179
+ span.setAttribute('operation.result', 'success');
180
+ } catch (error) {
181
+ span.recordException(error);
182
+ span.setStatus({ code: SpanStatusCode.ERROR, message: error.message });
183
+ } finally {
184
+ span.end();
185
+ }
186
+ ```
187
+
188
+ ## 📋 API Reference
189
+
190
+ ### `initializeSignOzTracing(config?)`
191
+
192
+ Inisialisasi SignOz tracing untuk aplikasi React.
193
+
194
+ **Parameter:**
195
+ - `config` (opsional): Konfigurasi SignOz
196
+ - `serviceName`: Nama layanan
197
+ - `serviceVersion`: Versi layanan
198
+ - `environment`: Environment (production, staging, development)
199
+ - `serviceNamespace`: Namespace layanan
200
+ - `url`: URL endpoint SignOz
201
+ - `headers`: Headers tambahan untuk request
202
+
203
+ ### `ErrorBoundary`
204
+
205
+ Komponen React untuk menangkap error dan melaporkan ke SignOz.
206
+
207
+ **Props:**
208
+ - `children`: React children
209
+ - `fallback`: Custom fallback component
210
+ - `onError`: Custom error handler function
211
+ - `onReset`: Custom reset handler
212
+ - `showResetButton`: Apakah menampilkan reset button (default: true)
213
+ - `resetButtonText`: Custom reset button text
214
+ - `fallbackClassName`: Custom CSS class untuk fallback
215
+
216
+ ### `ErrorPage`
217
+
218
+ Komponen halaman error untuk React Router.
219
+
220
+ **Props:**
221
+ - `title`: Judul halaman error (default: "Oops!")
222
+ - `message`: Pesan error utama (default: "Terjadi kesalahan yang tidak terduga.")
223
+ - `renderError`: Custom render function untuk menampilkan error
224
+ - `className`: Custom CSS class untuk container
225
+ - `showStackTrace`: Apakah menampilkan stack trace (default: false)
226
+ - `actionButton`: Custom action button
227
+
228
+ ## 🔍 Monitoring
229
+
230
+ Setelah setup, Anda dapat melihat traces di dashboard SignOz:
231
+
232
+ 1. **Service Overview**: Melihat performa layanan secara keseluruhan
233
+ 2. **Traces**: Melihat detail traces untuk setiap request
234
+ 3. **Errors**: Melihat error yang terjadi dengan stack trace
235
+ 4. **Metrics**: Melihat metrics performa aplikasi
236
+
237
+ ## 🛠️ Development
238
+
239
+ ### Setup Development
240
+
241
+ ```bash
242
+ # Clone repository
243
+ git clone https://gitlab.echoteam.tech/codr/package/signoz-react-js.git
244
+ cd signoz-react-js
245
+
246
+ # Install dependencies
247
+ yarn install
248
+
249
+ # Build package
250
+ yarn build
251
+
252
+ # Development mode
253
+ yarn dev
254
+ ```
255
+ ### Scripts
256
+
257
+ - `yarn build`: Build package untuk production
258
+ - `yarn dev`: Build dalam mode development dengan watch
259
+ - `yarn test`: Jalankan tests
260
+ - `yarn lint`: Lint kode
261
+ - `yarn format`: Format kode dengan Prettier
262
+
263
+ ## 📄 License
264
+
265
+ MIT License - lihat file [LICENSE](LICENSE) untuk detail.
266
+
267
+ ## 🤝 Contributing
268
+
269
+ 1. Fork repository
270
+ 2. Buat feature branch (`git checkout -b feature/amazing-feature`)
271
+ 3. Commit perubahan (`git commit -m 'Add amazing feature'`)
272
+ 4. Push ke branch (`git push origin feature/amazing-feature`)
273
+ 5. Buat Pull Request
274
+
275
+ ## 📞 Support
276
+
277
+ - **Issues**: [GitLab Issues](https://gitlab.echoteam.tech/codr/package/signoz-react-js/-/issues)
278
+ - **Email**: dev@codr.id
279
+ - **Documentation**: [GitLab Wiki](https://gitlab.echoteam.tech/codr/package/signoz-react-js/-/wikis)
280
+
281
+ ## 🔗 Links
282
+
283
+ - [SignOz Documentation](https://signoz.io/docs/)
284
+ - [OpenTelemetry Documentation](https://opentelemetry.io/docs/)
285
+ - [React Error Boundary](https://reactjs.org/docs/error-boundaries.html)
286
+