@sentienguard/apm 1.0.19 → 1.0.20
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 +141 -141
- package/package.json +1 -1
- package/src/aggregator.js +465 -465
- package/src/config.js +179 -179
- package/src/dependencies.js +374 -374
- package/src/errors.js +132 -132
- package/src/index.d.ts +120 -120
- package/src/index.js +248 -242
- package/src/mongodb.js +31 -1
- package/src/openai.js +520 -520
- package/src/spanExporter.js +238 -232
- package/src/tracing.js +235 -230
- package/src/transport.js +8 -0
package/README.md
CHANGED
|
@@ -1,141 +1,141 @@
|
|
|
1
|
-
# @sentienguard/apm
|
|
2
|
-
|
|
3
|
-
Minimal, production-safe APM SDK for Node.js applications. Zero-config setup with automatic instrumentation.
|
|
4
|
-
|
|
5
|
-
## Installation
|
|
6
|
-
|
|
7
|
-
```bash
|
|
8
|
-
npm install @sentienguard/apm
|
|
9
|
-
```
|
|
10
|
-
|
|
11
|
-
## Quick Start
|
|
12
|
-
|
|
13
|
-
```js
|
|
14
|
-
// If using dotenv, import it first
|
|
15
|
-
import 'dotenv/config';
|
|
16
|
-
|
|
17
|
-
// Then import the SDK (before other app modules for best instrumentation coverage)
|
|
18
|
-
import '@sentienguard/apm';
|
|
19
|
-
|
|
20
|
-
// Your app code
|
|
21
|
-
import express from 'express';
|
|
22
|
-
const app = express();
|
|
23
|
-
// ...
|
|
24
|
-
```
|
|
25
|
-
|
|
26
|
-
Set environment variables:
|
|
27
|
-
|
|
28
|
-
```bash
|
|
29
|
-
SENTIENGUARD_APM_KEY=your-app-key
|
|
30
|
-
SENTIENGUARD_SERVICE=my-api
|
|
31
|
-
```
|
|
32
|
-
|
|
33
|
-
That's it. The SDK automatically instruments your application and sends metrics to SentienGuard.
|
|
34
|
-
|
|
35
|
-
## Configuration
|
|
36
|
-
|
|
37
|
-
All configuration is via environment variables:
|
|
38
|
-
|
|
39
|
-
| Variable | Required | Default | Description |
|
|
40
|
-
|----------|----------|---------|-------------|
|
|
41
|
-
| `SENTIENGUARD_APM_KEY` | Yes | - | Your application's APM key |
|
|
42
|
-
| `SENTIENGUARD_SERVICE` | Yes | - | Service name (e.g., `orders-api`) |
|
|
43
|
-
| `SENTIENGUARD_ENV` | No | `production` | Environment (`production`, `staging`, `development`) |
|
|
44
|
-
| `SENTIENGUARD_ENDPOINT` | No | `https://sentienguard-dev.the-algo.com/api/v1` | SentienGuard backend URL |
|
|
45
|
-
| `SENTIENGUARD_FLUSH_INTERVAL` | No | `10` | Metrics flush interval in seconds |
|
|
46
|
-
|
|
47
|
-
> **Note:** If `SENTIENGUARD_APM_KEY` or `SENTIENGUARD_SERVICE` is missing, the SDK disables itself silently without affecting your application.
|
|
48
|
-
|
|
49
|
-
## What Gets Tracked
|
|
50
|
-
|
|
51
|
-
- **HTTP Requests** - Incoming requests with method, route, status, and latency
|
|
52
|
-
- **Dependencies** - Outgoing HTTP/HTTPS calls to external services
|
|
53
|
-
- **Errors** - Uncaught exceptions and unhandled rejections
|
|
54
|
-
|
|
55
|
-
## Framework Integration
|
|
56
|
-
|
|
57
|
-
### Express
|
|
58
|
-
|
|
59
|
-
For better route extraction, add the middleware:
|
|
60
|
-
|
|
61
|
-
```js
|
|
62
|
-
import 'dotenv/config'; // if using dotenv
|
|
63
|
-
import '@sentienguard/apm';
|
|
64
|
-
import { expressMiddleware, expressErrorMiddleware } from '@sentienguard/apm';
|
|
65
|
-
import express from 'express';
|
|
66
|
-
|
|
67
|
-
const app = express();
|
|
68
|
-
|
|
69
|
-
// Add early in middleware chain
|
|
70
|
-
app.use(expressMiddleware());
|
|
71
|
-
|
|
72
|
-
// Your routes
|
|
73
|
-
app.get('/users/:id', (req, res) => { ... });
|
|
74
|
-
|
|
75
|
-
// Add error middleware last
|
|
76
|
-
app.use(expressErrorMiddleware());
|
|
77
|
-
```
|
|
78
|
-
|
|
79
|
-
### Fastify
|
|
80
|
-
|
|
81
|
-
```js
|
|
82
|
-
import 'dotenv/config'; // if using dotenv
|
|
83
|
-
import '@sentienguard/apm';
|
|
84
|
-
import { fastifyPlugin, fastifyErrorHandler } from '@sentienguard/apm';
|
|
85
|
-
import Fastify from 'fastify';
|
|
86
|
-
|
|
87
|
-
const app = Fastify();
|
|
88
|
-
|
|
89
|
-
// Register plugin
|
|
90
|
-
app.register(fastifyPlugin);
|
|
91
|
-
|
|
92
|
-
// Add error handler
|
|
93
|
-
app.setErrorHandler(fastifyErrorHandler);
|
|
94
|
-
```
|
|
95
|
-
|
|
96
|
-
## API Reference
|
|
97
|
-
|
|
98
|
-
### Functions
|
|
99
|
-
|
|
100
|
-
```js
|
|
101
|
-
import {
|
|
102
|
-
shutdown, // Graceful shutdown (flushes pending metrics)
|
|
103
|
-
getStatus, // Get SDK status and stats
|
|
104
|
-
flush, // Force flush metrics now
|
|
105
|
-
isEnabled // Check if SDK is enabled
|
|
106
|
-
} from '@sentienguard/apm';
|
|
107
|
-
```
|
|
108
|
-
|
|
109
|
-
### Graceful Shutdown
|
|
110
|
-
|
|
111
|
-
The SDK automatically handles `SIGTERM` and `SIGINT` signals. For manual shutdown:
|
|
112
|
-
|
|
113
|
-
```js
|
|
114
|
-
import { shutdown } from '@sentienguard/apm';
|
|
115
|
-
|
|
116
|
-
process.on('exit', async () => {
|
|
117
|
-
await shutdown();
|
|
118
|
-
});
|
|
119
|
-
```
|
|
120
|
-
|
|
121
|
-
### Check Status
|
|
122
|
-
|
|
123
|
-
```js
|
|
124
|
-
import { getStatus } from '@sentienguard/apm';
|
|
125
|
-
|
|
126
|
-
console.log(getStatus());
|
|
127
|
-
// {
|
|
128
|
-
// enabled: true,
|
|
129
|
-
// initialized: true,
|
|
130
|
-
// config: { service: 'my-api', environment: 'production', flushInterval: 10 },
|
|
131
|
-
// stats: { requests: 150, dependencies: 45, errors: 2 }
|
|
132
|
-
// }
|
|
133
|
-
```
|
|
134
|
-
|
|
135
|
-
## Requirements
|
|
136
|
-
|
|
137
|
-
- Node.js >= 16.0.0
|
|
138
|
-
|
|
139
|
-
## License
|
|
140
|
-
|
|
141
|
-
MIT
|
|
1
|
+
# @sentienguard/apm
|
|
2
|
+
|
|
3
|
+
Minimal, production-safe APM SDK for Node.js applications. Zero-config setup with automatic instrumentation.
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
npm install @sentienguard/apm
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
## Quick Start
|
|
12
|
+
|
|
13
|
+
```js
|
|
14
|
+
// If using dotenv, import it first
|
|
15
|
+
import 'dotenv/config';
|
|
16
|
+
|
|
17
|
+
// Then import the SDK (before other app modules for best instrumentation coverage)
|
|
18
|
+
import '@sentienguard/apm';
|
|
19
|
+
|
|
20
|
+
// Your app code
|
|
21
|
+
import express from 'express';
|
|
22
|
+
const app = express();
|
|
23
|
+
// ...
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
Set environment variables:
|
|
27
|
+
|
|
28
|
+
```bash
|
|
29
|
+
SENTIENGUARD_APM_KEY=your-app-key
|
|
30
|
+
SENTIENGUARD_SERVICE=my-api
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
That's it. The SDK automatically instruments your application and sends metrics to SentienGuard.
|
|
34
|
+
|
|
35
|
+
## Configuration
|
|
36
|
+
|
|
37
|
+
All configuration is via environment variables:
|
|
38
|
+
|
|
39
|
+
| Variable | Required | Default | Description |
|
|
40
|
+
|----------|----------|---------|-------------|
|
|
41
|
+
| `SENTIENGUARD_APM_KEY` | Yes | - | Your application's APM key |
|
|
42
|
+
| `SENTIENGUARD_SERVICE` | Yes | - | Service name (e.g., `orders-api`) |
|
|
43
|
+
| `SENTIENGUARD_ENV` | No | `production` | Environment (`production`, `staging`, `development`) |
|
|
44
|
+
| `SENTIENGUARD_ENDPOINT` | No | `https://sentienguard-dev.the-algo.com/api/v1` | SentienGuard backend URL |
|
|
45
|
+
| `SENTIENGUARD_FLUSH_INTERVAL` | No | `10` | Metrics flush interval in seconds |
|
|
46
|
+
|
|
47
|
+
> **Note:** If `SENTIENGUARD_APM_KEY` or `SENTIENGUARD_SERVICE` is missing, the SDK disables itself silently without affecting your application.
|
|
48
|
+
|
|
49
|
+
## What Gets Tracked
|
|
50
|
+
|
|
51
|
+
- **HTTP Requests** - Incoming requests with method, route, status, and latency
|
|
52
|
+
- **Dependencies** - Outgoing HTTP/HTTPS calls to external services
|
|
53
|
+
- **Errors** - Uncaught exceptions and unhandled rejections
|
|
54
|
+
|
|
55
|
+
## Framework Integration
|
|
56
|
+
|
|
57
|
+
### Express
|
|
58
|
+
|
|
59
|
+
For better route extraction, add the middleware:
|
|
60
|
+
|
|
61
|
+
```js
|
|
62
|
+
import 'dotenv/config'; // if using dotenv
|
|
63
|
+
import '@sentienguard/apm';
|
|
64
|
+
import { expressMiddleware, expressErrorMiddleware } from '@sentienguard/apm';
|
|
65
|
+
import express from 'express';
|
|
66
|
+
|
|
67
|
+
const app = express();
|
|
68
|
+
|
|
69
|
+
// Add early in middleware chain
|
|
70
|
+
app.use(expressMiddleware());
|
|
71
|
+
|
|
72
|
+
// Your routes
|
|
73
|
+
app.get('/users/:id', (req, res) => { ... });
|
|
74
|
+
|
|
75
|
+
// Add error middleware last
|
|
76
|
+
app.use(expressErrorMiddleware());
|
|
77
|
+
```
|
|
78
|
+
|
|
79
|
+
### Fastify
|
|
80
|
+
|
|
81
|
+
```js
|
|
82
|
+
import 'dotenv/config'; // if using dotenv
|
|
83
|
+
import '@sentienguard/apm';
|
|
84
|
+
import { fastifyPlugin, fastifyErrorHandler } from '@sentienguard/apm';
|
|
85
|
+
import Fastify from 'fastify';
|
|
86
|
+
|
|
87
|
+
const app = Fastify();
|
|
88
|
+
|
|
89
|
+
// Register plugin
|
|
90
|
+
app.register(fastifyPlugin);
|
|
91
|
+
|
|
92
|
+
// Add error handler
|
|
93
|
+
app.setErrorHandler(fastifyErrorHandler);
|
|
94
|
+
```
|
|
95
|
+
|
|
96
|
+
## API Reference
|
|
97
|
+
|
|
98
|
+
### Functions
|
|
99
|
+
|
|
100
|
+
```js
|
|
101
|
+
import {
|
|
102
|
+
shutdown, // Graceful shutdown (flushes pending metrics)
|
|
103
|
+
getStatus, // Get SDK status and stats
|
|
104
|
+
flush, // Force flush metrics now
|
|
105
|
+
isEnabled // Check if SDK is enabled
|
|
106
|
+
} from '@sentienguard/apm';
|
|
107
|
+
```
|
|
108
|
+
|
|
109
|
+
### Graceful Shutdown
|
|
110
|
+
|
|
111
|
+
The SDK automatically handles `SIGTERM` and `SIGINT` signals. For manual shutdown:
|
|
112
|
+
|
|
113
|
+
```js
|
|
114
|
+
import { shutdown } from '@sentienguard/apm';
|
|
115
|
+
|
|
116
|
+
process.on('exit', async () => {
|
|
117
|
+
await shutdown();
|
|
118
|
+
});
|
|
119
|
+
```
|
|
120
|
+
|
|
121
|
+
### Check Status
|
|
122
|
+
|
|
123
|
+
```js
|
|
124
|
+
import { getStatus } from '@sentienguard/apm';
|
|
125
|
+
|
|
126
|
+
console.log(getStatus());
|
|
127
|
+
// {
|
|
128
|
+
// enabled: true,
|
|
129
|
+
// initialized: true,
|
|
130
|
+
// config: { service: 'my-api', environment: 'production', flushInterval: 10 },
|
|
131
|
+
// stats: { requests: 150, dependencies: 45, errors: 2 }
|
|
132
|
+
// }
|
|
133
|
+
```
|
|
134
|
+
|
|
135
|
+
## Requirements
|
|
136
|
+
|
|
137
|
+
- Node.js >= 16.0.0
|
|
138
|
+
|
|
139
|
+
## License
|
|
140
|
+
|
|
141
|
+
MIT
|