@oneteme/inspect-ng-collector 1.3.1 → 1.3.2-ng12

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.
Files changed (50) hide show
  1. package/README.md +361 -13
  2. package/bundles/oneteme-inspect-ng-collector.umd.js +1450 -0
  3. package/bundles/oneteme-inspect-ng-collector.umd.js.map +1 -0
  4. package/esm2015/lib/configuration.js +136 -0
  5. package/esm2015/lib/event-bus.js +41 -0
  6. package/esm2015/lib/event-trace-debugger.js +187 -0
  7. package/esm2015/lib/event-trace-scheduled-dispatcher.service.js +119 -0
  8. package/esm2015/lib/global-error-handler.service.js +25 -0
  9. package/esm2015/lib/http-interceptor.service.js +54 -0
  10. package/esm2015/lib/local-request.monitor.js +21 -0
  11. package/esm2015/lib/navigation.monitor.js +33 -0
  12. package/esm2015/lib/ng-collector.module.js +69 -0
  13. package/esm2015/lib/resource-usage.monitor.js +27 -0
  14. package/esm2015/lib/rest-request.monitor.js +112 -0
  15. package/esm2015/lib/session-manager.service.js +107 -0
  16. package/esm2015/lib/trace.model.js +21 -0
  17. package/esm2015/lib/traceable-stage.decorator.js +39 -0
  18. package/esm2015/lib/user-action.monitor.js +95 -0
  19. package/esm2015/oneteme-inspect-ng-collector.js +5 -0
  20. package/esm2015/public-api.js +7 -0
  21. package/fesm2015/oneteme-inspect-ng-collector.js +870 -0
  22. package/fesm2015/oneteme-inspect-ng-collector.js.map +1 -0
  23. package/lib/configuration.d.ts +36 -30
  24. package/lib/event-bus.d.ts +12 -0
  25. package/lib/event-trace-debugger.d.ts +5 -3
  26. package/lib/event-trace-scheduled-dispatcher.service.d.ts +22 -17
  27. package/lib/global-error-handler.service.d.ts +3 -3
  28. package/lib/http-interceptor.service.d.ts +5 -1
  29. package/lib/local-request.monitor.d.ts +8 -0
  30. package/lib/navigation.monitor.d.ts +2 -0
  31. package/lib/ng-collector.module.d.ts +14 -5
  32. package/lib/resource-usage.monitor.d.ts +1 -0
  33. package/lib/rest-request.monitor.d.ts +10 -0
  34. package/lib/session-manager.service.d.ts +16 -7
  35. package/lib/trace.model.d.ts +66 -52
  36. package/lib/traceable-stage.decorator.d.ts +4 -0
  37. package/lib/user-action.monitor.d.ts +1 -0
  38. package/package.json +11 -16
  39. package/public-api.d.ts +1 -1
  40. package/fesm2022/oneteme-inspect-ng-collector.mjs +0 -1114
  41. package/fesm2022/oneteme-inspect-ng-collector.mjs.map +0 -1
  42. package/lib/analytics-collect.service.d.ts +0 -1
  43. package/lib/context-manager.d.ts +0 -16
  44. package/lib/handlers.d.ts +0 -3
  45. package/lib/listeners.d.ts +0 -5
  46. package/lib/log.service.d.ts +0 -5
  47. package/lib/machine-ressource-monitor.service.d.ts +0 -1
  48. package/lib/rest-request-monitor.d.ts +0 -14
  49. package/lib/util.d.ts +0 -12
  50. /package/{index.d.ts → oneteme-inspect-ng-collector.d.ts} +0 -0
package/README.md CHANGED
@@ -1,24 +1,372 @@
1
- # InspectNgCollector
1
+ # @oneteme/inspect-ng-collector
2
2
 
3
- This library was generated with [Angular CLI](https://github.com/angular/angular-cli) version 17.3.0.
3
+ [![npm version](https://img.shields.io/npm/v/@oneteme/inspect-ng-collector.svg)](https://www.npmjs.com/package/@oneteme/inspect-ng-collector)
4
+ [![License](https://img.shields.io/badge/License-MIT-blue.svg)](LICENSE)
5
+ [![Angular Version](https://img.shields.io/badge/Angular-%3E%3D16.2.8-red.svg)](https://angular.io)
6
+ [![Tests](https://img.shields.io/badge/Tests-150%2B%20Cases-brightgreen.svg)](#testing)
4
7
 
5
- ## Code scaffolding
8
+ A comprehensive **front-end telemetry and monitoring library for Angular applications**. Automatically collect user interactions, HTTP requests, navigation events, performance metrics, and errors—then send them to your backend analytics service.
6
9
 
7
- Run `ng generate component component-name --project inspect-ng-collector` to generate a new component. You can also use `ng generate directive|pipe|service|class|guard|interface|enum|module --project inspect-ng-collector`.
8
- > Note: Don't forget to add `--project inspect-ng-collector` or else it will be added to the default project in your `angular.json` file.
10
+ ## 🚀 Features
9
11
 
10
- ## Build
12
+ - **🔍 Comprehensive Event Tracking**
13
+ - User interactions (clicks, form changes, scrolling)
14
+ - HTTP requests and responses with full request/response details
15
+ - Navigation and route changes
16
+ - Global error handling and exceptions
17
+ - Memory and resource usage metrics
18
+ - Custom application events via `@TraceableStage()` decorator
11
19
 
12
- Run `ng build inspect-ng-collector` to build the project. The build artifacts will be stored in the `dist/` directory.
20
+ - **📊 Session Management**
21
+ - Automatic session creation per user navigation flow
22
+ - Session correlation across multiple requests
23
+ - Configurable session lifecycle
13
24
 
14
- ## Publishing
25
+ - **⚡ Performance Optimized**
26
+ - In-memory event queue with configurable capacity
27
+ - Batch export of events at regular intervals
28
+ - Minimal impact on application performance
29
+ - Tree-shakeable and side-effect free
15
30
 
16
- After building your library with `ng build inspect-ng-collector`, go to the dist folder `cd dist/inspect-ng-collector` and run `npm publish`.
31
+ - **🔐 Enterprise Ready**
32
+ - Support for custom application properties
33
+ - User identification integration
34
+ - Environment and version tracking
35
+ - Debug mode for development
17
36
 
18
- ## Running unit tests
37
+ - **🧪 Fully Tested**
38
+ - 150+ unit test cases
39
+ - 80%+ code coverage
40
+ - Comprehensive test documentation
19
41
 
20
- Run `ng test inspect-ng-collector` to execute the unit tests via [Karma](https://karma-runner.github.io).
42
+ ## 📦 Installation
21
43
 
22
- ## Further help
44
+ ```bash
45
+ npm install @oneteme/inspect-ng-collector
46
+ ```
23
47
 
24
- To get more help on the Angular CLI use `ng help` or go check out the [Angular CLI Overview and Command Reference](https://angular.io/cli) page.
48
+ ### Peer Dependencies
49
+
50
+ - `@angular/common` >= 16.2.8
51
+ - `@angular/core` >= 16.2.8
52
+ - `@angular/router` >= 16.2.8
53
+
54
+ ## 🔧 Quick Start
55
+
56
+ ### 1. Import the Module
57
+
58
+ In your `app.module.ts`:
59
+
60
+ ```typescript
61
+ import { NgModule } from '@angular/core';
62
+ import { BrowserModule } from '@angular/platform-browser';
63
+ import { NgCollectorModule } from '@oneteme/inspect-ng-collector';
64
+ import { AppComponent } from './app.component';
65
+
66
+ @NgModule({
67
+ declarations: [ AppComponent ],
68
+ imports: [
69
+ BrowserModule,
70
+ NgCollectorModule.forRoot({
71
+ enabled: true,
72
+ name: 'my-application',
73
+ version: '1.0.0',
74
+ env: 'production',
75
+ tracing: {
76
+ remote: {
77
+ host: 'https://api.analytics.example.com'
78
+ }
79
+ }
80
+ })
81
+ ],
82
+ bootstrap: [ AppComponent ]
83
+ })
84
+ export class AppModule { }
85
+ ```
86
+
87
+ ### 2. (Optional) Add Custom Tracing
88
+
89
+ Use the `@TraceableStage()` decorator to track custom application stages:
90
+
91
+ ```typescript
92
+ import { Injectable } from '@angular/core';
93
+ import { TraceableStage } from '@oneteme/inspect-ng-collector';
94
+
95
+ @Injectable()
96
+ export class DataService {
97
+
98
+ @TraceableStage()
99
+ fetchUserData(userId: string) {
100
+ // Your logic here
101
+ }
102
+
103
+ @TraceableStage()
104
+ async processData(data: any) {
105
+ // Async operations are supported
106
+ }
107
+ }
108
+ ```
109
+
110
+ ### 3. (Optional) Log Application Events
111
+
112
+ ```typescript
113
+ import { Injectable } from '@angular/core';
114
+ import { LogService } from '@oneteme/inspect-ng-collector';
115
+
116
+ @Injectable()
117
+ export class MyService {
118
+
119
+ constructor(private logger: LogService) {}
120
+
121
+ doSomething() {
122
+ this.logger.info('Operation started');
123
+ // ... operations ...
124
+ this.logger.warn('Something unexpected');
125
+ this.logger.error('An error occurred');
126
+ }
127
+ }
128
+ ```
129
+
130
+ ## ⚙️ Configuration
131
+
132
+ ### Full Configuration Example
133
+
134
+ ```typescript
135
+ NgCollectorModule.forRoot({
136
+ // Core Configuration
137
+ enabled: true, // Enable/disable collection
138
+ debugMode: false, // Enable debug console output
139
+
140
+ // Application Identity (at root level)
141
+ name: 'my-app',
142
+ version: () => getAppVersion(), // Can be a function
143
+ env: 'production',
144
+ user: 'john@example.com', // Optional user identifier
145
+
146
+ // Additional Properties
147
+ additionalProperties: () => ({
148
+ customProperty: 'value',
149
+ userId: getUserId()
150
+ }),
151
+
152
+ // Scheduling
153
+ scheduling: {
154
+ interval: 30000 // Export interval in ms (default: 30s)
155
+ },
156
+
157
+ // Monitoring Configuration
158
+ monitoring: {
159
+ // HTTP Monitoring
160
+ httpRoute: {
161
+ excludes: {
162
+ path: [/\/health$/, /\/status$/] // Exclude paths from tracking
163
+ }
164
+ },
165
+ httpRequest: {
166
+ excludes: {
167
+ host: ['localhost:4200'] // Exclude hosts
168
+ }
169
+ },
170
+ // Features
171
+ resources: {
172
+ enabled: true // Track memory usage
173
+ },
174
+ analytics: {
175
+ enabled: true // Track user actions
176
+ },
177
+ storage: {
178
+ enabled: false // Track storage events
179
+ }
180
+ },
181
+
182
+ // Tracing Configuration
183
+ tracing: {
184
+ queueCapacity: 1000, // Max events in queue
185
+ remote: {
186
+ host: 'https://analytics.example.com',
187
+ mode: 'cors',
188
+ retentionMaxAge: 86400000 // 24 hours
189
+ }
190
+ }
191
+ })
192
+ ```
193
+
194
+ ### Configuration Properties
195
+
196
+ | Property | Type | Default | Description |
197
+ |----------|------|---------|-------------|
198
+ | `enabled` | boolean | false | Enable/disable collection |
199
+ | `debugMode` | boolean | false | Enable debug output |
200
+ | `name` | string \| function | required | Application name |
201
+ | `version` | string \| function | optional | Application version |
202
+ | `env` | string \| function | optional | Environment (prod, dev, etc.) |
203
+ | `user` | string \| function | optional | Current user identifier |
204
+ | `additionalProperties` | function | optional | Custom app properties |
205
+ | `scheduling.interval` | number | 30000 | Event export interval (ms) |
206
+ | `monitoring.resources.enabled` | boolean | false | Track memory metrics |
207
+ | `monitoring.analytics.enabled` | boolean | false | Track user interactions |
208
+ | `tracing.queueCapacity` | number | 1000 | Max queued events |
209
+ | `tracing.remote.host` | string | required | Backend analytics endpoint |
210
+
211
+ ## 📊 Collected Data
212
+
213
+ The library automatically collects:
214
+
215
+ - **Navigation Events**: Route changes, page loads, back/forward navigation
216
+ - **HTTP Events**:
217
+ - Request details (method, URL, headers, body size)
218
+ - Response details (status, content-type, duration)
219
+ - Request failures and network errors
220
+ - **User Actions**: Clicks, form inputs, scrolling, drag operations
221
+ - **Errors**: Uncaught exceptions, Angular error handler events
222
+ - **Performance**: JavaScript memory usage, resource timing
223
+ - **Custom Traces**: Any method decorated with `@TraceableStage()`
224
+ - **Application Logs**: Via `LogService.info()`, `.warn()`, `.error()`
225
+
226
+ All events are **correlated by session** and sent to your backend service.
227
+
228
+ ## 🎯 Exported API
229
+
230
+ ### NgCollectorModule
231
+
232
+ Main module for integration.
233
+
234
+ ```typescript
235
+ NgCollectorModule.forRoot(config: CollectorConfig): ModuleWithProviders
236
+ ```
237
+
238
+ ### TraceableStage
239
+
240
+ Decorator for tracking custom method execution:
241
+
242
+ ```typescript
243
+ @TraceableStage()
244
+ myMethod() { }
245
+ ```
246
+
247
+ Supports both synchronous and asynchronous methods.
248
+
249
+ ### SessionManager
250
+
251
+ Service managing user sessions (injected automatically).
252
+
253
+ ```typescript
254
+ import { SessionManager } from '@oneteme/inspect-ng-collector';
255
+ ```
256
+
257
+ ### LogService
258
+
259
+ Service for application logging:
260
+
261
+ ```typescript
262
+ import { LogService } from '@oneteme/inspect-ng-collector';
263
+
264
+ constructor(private logger: LogService) {}
265
+
266
+ this.logger.info('message');
267
+ this.logger.warn('message');
268
+ this.logger.error('message');
269
+ ```
270
+
271
+ ### COLLECTOR_CONFIG
272
+
273
+ Injection token for accessing collector configuration:
274
+
275
+ ```typescript
276
+ import { COLLECTOR_CONFIG } from '@oneteme/inspect-ng-collector';
277
+
278
+ constructor(@Inject(COLLECTOR_CONFIG) config: any) { }
279
+ ```
280
+
281
+ ## 🏗️ Architecture
282
+
283
+ ```
284
+ ┌─────────────────────────────────────────────┐
285
+ │ Angular Application │
286
+ │ (Components, Services, HTTP calls) │
287
+ └──────────────┬──────────────────────────────┘
288
+ │
289
+ ┌──────▼──────────────────────────────────────────┐
290
+ │ EventBus (Internal Event System) │
291
+ │ Receives events from monitors and services │
292
+ └──────┬──────────────────────────────────────────┘
293
+ │
294
+ ┌──────▼──────────────────────────────────────────┐
295
+ │ Session Manager & Monitors │
296
+ │ • Navigation Monitor │
297
+ │ • HTTP Interceptor │
298
+ │ • User Action Monitor │
299
+ │ • Resource Usage Monitor │
300
+ │ • Global Error Handler │
301
+ └──────┬──────────────────────────────────────────┘
302
+ │
303
+ ┌──────▼──────────────────────────────────────────┐
304
+ │ Event Queue (In-Memory) │
305
+ │ Batches and buffers events │
306
+ └──────┬──────────────────────────────────────────┘
307
+ │
308
+ ┌──────▼──────────────────────────────────────────┐
309
+ │ Scheduled Dispatcher │
310
+ │ Sends events to backend at intervals │
311
+ └──────┬──────────────────────────────────────────┘
312
+ │
313
+ ┌──────▼──────────────────────────────────────────┐
314
+ │ Analytics Backend (Your Service) │
315
+ │ https://analytics.example.com/api │
316
+ └─────────────────────────────────────────────────┘
317
+ ```
318
+
319
+ ## 🐛 Debug Mode
320
+
321
+ Enable debug mode in configuration to see internal events logged to the browser console:
322
+
323
+ ```typescript
324
+ NgCollectorModule.forRoot({
325
+ // ...
326
+ debugMode: true
327
+ })
328
+ ```
329
+
330
+ This will show:
331
+ - Event creation and dispatching
332
+ - Session lifecycle
333
+ - Network requests to backend
334
+ - Internal state changes
335
+
336
+ ## 🔒 Security
337
+
338
+ This library respects user privacy and security:
339
+
340
+ - Events are sent only to configured backend endpoints
341
+ - No external requests outside your configured domain
342
+ - Supports CORS and custom headers
343
+ - Sensitive information (credentials) excluded from HTTP tracking
344
+ - No local persistence of sensitive data
345
+
346
+ ### Excluding Sensitive Endpoints
347
+
348
+ ```typescript
349
+ monitoring: {
350
+ httpRoute: {
351
+ excludes: {
352
+ path: [
353
+ /\/api\/login$/,
354
+ /\/api\/password-reset$/,
355
+ /\/api\/tokens?$/
356
+ ]
357
+ }
358
+ }
359
+ }
360
+ ```
361
+
362
+ ## 📄 License
363
+
364
+ This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.
365
+
366
+ ## 🤝 Contributing
367
+
368
+ Contributions are welcome! Please feel free to submit a Pull Request.
369
+
370
+ ---
371
+
372
+ **Made with ❤️ by [u$f](https://oneteme.github.io/) and contributors**