@tumbaland/backend-core 1.16.1 → 1.18.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 +61 -48
- package/dist/app/shutdown.d.ts +31 -0
- package/dist/app/shutdown.d.ts.map +1 -0
- package/dist/app/shutdown.js +58 -0
- package/dist/app/shutdown.js.map +1 -0
- package/dist/health/createHealthCheck.d.ts +32 -0
- package/dist/health/createHealthCheck.d.ts.map +1 -0
- package/dist/health/createHealthCheck.js +50 -0
- package/dist/health/createHealthCheck.js.map +1 -0
- package/dist/index.d.ts +5 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +9 -1
- package/dist/index.js.map +1 -1
- package/dist/logging/logger.js +1 -1
- package/dist/logging/logger.js.map +1 -1
- package/dist/metrics/index.d.ts +3 -2
- package/dist/metrics/index.d.ts.map +1 -1
- package/dist/metrics/index.js +1 -1
- package/dist/metrics/index.js.map +1 -1
- package/dist/middleware/errorHandler.js.map +1 -1
- package/dist/middleware/requestLogger.d.ts +3 -2
- package/dist/middleware/requestLogger.d.ts.map +1 -1
- package/dist/middleware/requestLogger.js.map +1 -1
- package/dist/tracing/index.d.ts +9 -8
- package/dist/tracing/index.d.ts.map +1 -1
- package/dist/tracing/index.js +7 -7
- package/dist/tracing/index.js.map +1 -1
- package/dist/types/auth.d.ts +9 -1
- package/dist/types/auth.d.ts.map +1 -1
- package/dist/utils/correlation.js.map +1 -1
- package/dist/utils/permissionUtils.d.ts +31 -0
- package/dist/utils/permissionUtils.d.ts.map +1 -0
- package/dist/utils/permissionUtils.js +53 -0
- package/dist/utils/permissionUtils.js.map +1 -0
- package/dist/utils/response.d.ts +3 -3
- package/dist/utils/response.d.ts.map +1 -1
- package/package.json +6 -3
- package/src/app/shutdown.test.ts +129 -0
- package/src/app/shutdown.ts +81 -0
- package/src/health/createHealthCheck.test.ts +89 -0
- package/src/health/createHealthCheck.ts +67 -0
- package/src/index.ts +5 -0
- package/src/logging/logger.ts +1 -1
- package/src/metrics/index.ts +3 -2
- package/src/middleware/errorHandler.ts +2 -2
- package/src/middleware/requestLogger.ts +2 -1
- package/src/tracing/index.test.ts +11 -7
- package/src/tracing/index.ts +26 -13
- package/src/types/auth.ts +10 -1
- package/src/utils/correlation.ts +1 -1
- package/src/utils/permissionUtils.test.ts +47 -0
- package/src/utils/permissionUtils.ts +68 -0
- package/src/utils/response.ts +3 -3
package/README.md
CHANGED
|
@@ -64,6 +64,58 @@ app.get('/protected', authenticateToken, (req, res) => {
|
|
|
64
64
|
});
|
|
65
65
|
```
|
|
66
66
|
|
|
67
|
+
### Health Checks (unified standard)
|
|
68
|
+
|
|
69
|
+
Every service mounts the same `/health` readiness endpoint via the
|
|
70
|
+
`createHealthCheck` factory — one response contract across all services, so
|
|
71
|
+
monitoring and dashboards see identical shapes:
|
|
72
|
+
|
|
73
|
+
```typescript
|
|
74
|
+
import { createHealthCheck } from '@tumbaland/backend-core';
|
|
75
|
+
|
|
76
|
+
// DB-backed service (default): reports `dependencies.mongodb` and returns 503
|
|
77
|
+
// while the connection is down.
|
|
78
|
+
export const healthCheck = createHealthCheck({
|
|
79
|
+
service: 'my-service',
|
|
80
|
+
description: 'My awesome service'
|
|
81
|
+
});
|
|
82
|
+
|
|
83
|
+
// Service with no database: readiness is a static ok, no `dependencies`.
|
|
84
|
+
export const healthCheck = createHealthCheck({
|
|
85
|
+
service: 'public-service',
|
|
86
|
+
description: 'Public API endpoints service',
|
|
87
|
+
checkDatabase: false
|
|
88
|
+
});
|
|
89
|
+
|
|
90
|
+
app.get('/health', healthCheck);
|
|
91
|
+
```
|
|
92
|
+
|
|
93
|
+
Response body: `{ status, service, type: 'backend', timestamp, version, description }`,
|
|
94
|
+
plus `dependencies.mongodb` when `checkDatabase` is on. `/health/live` (liveness,
|
|
95
|
+
no dependency checks — used by the Docker `HEALTHCHECK`) is mounted separately by
|
|
96
|
+
`createBaseApp`.
|
|
97
|
+
|
|
98
|
+
### Graceful Shutdown
|
|
99
|
+
|
|
100
|
+
`registerShutdown` wires `SIGINT` **and** `SIGTERM` (the signal Docker/Kubernetes
|
|
101
|
+
send on stop and rollout) to drain the HTTP server and close the MongoDB
|
|
102
|
+
connection before the process exits:
|
|
103
|
+
|
|
104
|
+
```typescript
|
|
105
|
+
import { registerShutdown } from '@tumbaland/backend-core';
|
|
106
|
+
|
|
107
|
+
const server = app.listen(PORT, () => logger.info('Service started', { port: PORT }));
|
|
108
|
+
|
|
109
|
+
// DB-backed service
|
|
110
|
+
registerShutdown({ serviceName: 'my-service', server });
|
|
111
|
+
|
|
112
|
+
// No-DB service: skip the Mongo disconnect
|
|
113
|
+
registerShutdown({ serviceName: 'public-service', server, disconnectDatabase: false });
|
|
114
|
+
```
|
|
115
|
+
|
|
116
|
+
The handler is idempotent and self-arms a force-exit timer so a hung close still
|
|
117
|
+
terminates.
|
|
118
|
+
|
|
67
119
|
### Structured Logging
|
|
68
120
|
|
|
69
121
|
```typescript
|
|
@@ -120,54 +172,15 @@ This library is optimized for Docker deployments:
|
|
|
120
172
|
|
|
121
173
|
## 📦 Releases & Versioning
|
|
122
174
|
|
|
123
|
-
This library
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
```
|
|
134
|
-
type(scope): description
|
|
135
|
-
|
|
136
|
-
[optional body]
|
|
137
|
-
|
|
138
|
-
[optional footer]
|
|
139
|
-
```
|
|
140
|
-
|
|
141
|
-
**Types:**
|
|
142
|
-
- `feat`: New feature
|
|
143
|
-
- `fix`: Bug fix
|
|
144
|
-
- `docs`: Documentation
|
|
145
|
-
- `style`: Code style changes
|
|
146
|
-
- `refactor`: Code refactoring
|
|
147
|
-
- `test`: Testing
|
|
148
|
-
- `chore`: Maintenance
|
|
149
|
-
|
|
150
|
-
**Examples:**
|
|
151
|
-
```
|
|
152
|
-
feat(auth): add JWT token refresh
|
|
153
|
-
fix(logging): resolve memory leak in Winston transport
|
|
154
|
-
docs(api): update health check endpoint documentation
|
|
155
|
-
```
|
|
156
|
-
|
|
157
|
-
### Release Process
|
|
158
|
-
|
|
159
|
-
1. **Make changes** with conventional commit messages
|
|
160
|
-
2. **Run release script**: `./release.sh`
|
|
161
|
-
3. **Push changes**: `git push origin main`
|
|
162
|
-
4. **Publish**: Automated via GitHub Actions
|
|
163
|
-
|
|
164
|
-
### Changelog
|
|
165
|
-
|
|
166
|
-
Changelogs are maintained at the project level in the root `CHANGELOG.md` file. Individual library changelogs are not generated to maintain consistency across the monorepo.
|
|
167
|
-
|
|
168
|
-
### Beta Releases
|
|
169
|
-
|
|
170
|
-
For beta releases: `npm run release:beta`
|
|
175
|
+
This library is a real published npm package (`@tumbaland/backend-core`), versioned independently
|
|
176
|
+
of the monorepo with [standard-version](https://github.com/conventional-changelog/standard-version)
|
|
177
|
+
and [Conventional Commits](https://conventionalcommits.org/). See the root
|
|
178
|
+
[README's "Commits & Releases" section](../../README.md#commits--releases) for the full process
|
|
179
|
+
and the reasoning behind it — summary: commit with conventional messages, then from this directory
|
|
180
|
+
run `npm run release` (never hand-edit `version` and `npm publish` directly, or the package,
|
|
181
|
+
changelog, and tags drift out of sync with each other). Tags for this package are scoped as
|
|
182
|
+
`backend-core-vX.Y.Z` so they can't collide with `frontend-core`'s, `components`', or the
|
|
183
|
+
monorepo's own `app-vX.Y.Z` tags.
|
|
171
184
|
|
|
172
185
|
---
|
|
173
186
|
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import type { Server } from 'http';
|
|
2
|
+
export interface RegisterShutdownOptions {
|
|
3
|
+
/** Service name, used for log context and the DB disconnect. */
|
|
4
|
+
serviceName: string;
|
|
5
|
+
/** The HTTP server returned by `app.listen(...)`, closed before the DB. */
|
|
6
|
+
server?: Server;
|
|
7
|
+
/**
|
|
8
|
+
* Whether to close the MongoDB connection on shutdown. Defaults to `true`;
|
|
9
|
+
* set `false` for services that never call `connectDB` (e.g. file, public).
|
|
10
|
+
*/
|
|
11
|
+
disconnectDatabase?: boolean;
|
|
12
|
+
/** Optional extra cleanup run before the server/DB are closed. */
|
|
13
|
+
onShutdown?: () => Promise<void> | void;
|
|
14
|
+
/**
|
|
15
|
+
* Force `process.exit` after this many ms if a graceful close hangs, so a
|
|
16
|
+
* stuck connection can't block a container rollout. Defaults to 10s.
|
|
17
|
+
*/
|
|
18
|
+
forceExitAfterMs?: number;
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* Registers `SIGINT` and `SIGTERM` handlers that drain the service before the
|
|
22
|
+
* process exits: run the optional cleanup hook, stop accepting new HTTP
|
|
23
|
+
* connections, then close the MongoDB connection. `SIGTERM` matters most —
|
|
24
|
+
* it's the signal Docker/Kubernetes send on stop and rollout, and without a
|
|
25
|
+
* handler the process is force-killed with its DB connection still open.
|
|
26
|
+
*
|
|
27
|
+
* The handler is idempotent (a second signal while shutting down is ignored)
|
|
28
|
+
* and self-arms a force-exit timer so a hung close still terminates.
|
|
29
|
+
*/
|
|
30
|
+
export declare const registerShutdown: ({ serviceName, server, disconnectDatabase, onShutdown, forceExitAfterMs }: RegisterShutdownOptions) => void;
|
|
31
|
+
//# sourceMappingURL=shutdown.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"shutdown.d.ts","sourceRoot":"","sources":["../../src/app/shutdown.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,MAAM,CAAC;AAInC,MAAM,WAAW,uBAAuB;IACtC,gEAAgE;IAChE,WAAW,EAAE,MAAM,CAAC;IACpB,2EAA2E;IAC3E,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB;;;OAGG;IACH,kBAAkB,CAAC,EAAE,OAAO,CAAC;IAC7B,kEAAkE;IAClE,UAAU,CAAC,EAAE,MAAM,OAAO,CAAC,IAAI,CAAC,GAAG,IAAI,CAAC;IACxC;;;OAGG;IACH,gBAAgB,CAAC,EAAE,MAAM,CAAC;CAC3B;AAED;;;;;;;;;GASG;AACH,eAAO,MAAM,gBAAgB,GAAI,2EAM9B,uBAAuB,KAAG,IAyC5B,CAAC"}
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.registerShutdown = void 0;
|
|
7
|
+
const logger_1 = __importDefault(require("../logging/logger"));
|
|
8
|
+
const connection_1 = require("../database/connection");
|
|
9
|
+
/**
|
|
10
|
+
* Registers `SIGINT` and `SIGTERM` handlers that drain the service before the
|
|
11
|
+
* process exits: run the optional cleanup hook, stop accepting new HTTP
|
|
12
|
+
* connections, then close the MongoDB connection. `SIGTERM` matters most —
|
|
13
|
+
* it's the signal Docker/Kubernetes send on stop and rollout, and without a
|
|
14
|
+
* handler the process is force-killed with its DB connection still open.
|
|
15
|
+
*
|
|
16
|
+
* The handler is idempotent (a second signal while shutting down is ignored)
|
|
17
|
+
* and self-arms a force-exit timer so a hung close still terminates.
|
|
18
|
+
*/
|
|
19
|
+
const registerShutdown = ({ serviceName, server, disconnectDatabase = true, onShutdown, forceExitAfterMs = 10_000 }) => {
|
|
20
|
+
let shuttingDown = false;
|
|
21
|
+
const shutdown = async (signal) => {
|
|
22
|
+
if (shuttingDown)
|
|
23
|
+
return;
|
|
24
|
+
shuttingDown = true;
|
|
25
|
+
logger_1.default.info('Received shutdown signal, closing gracefully', { service: serviceName, signal });
|
|
26
|
+
const forceExit = setTimeout(() => {
|
|
27
|
+
logger_1.default.error('Graceful shutdown timed out, forcing exit', { service: serviceName });
|
|
28
|
+
process.exit(1);
|
|
29
|
+
}, forceExitAfterMs);
|
|
30
|
+
// Don't let the timer itself keep the event loop alive.
|
|
31
|
+
forceExit.unref?.();
|
|
32
|
+
try {
|
|
33
|
+
if (onShutdown)
|
|
34
|
+
await onShutdown();
|
|
35
|
+
if (server) {
|
|
36
|
+
await new Promise((resolve, reject) => {
|
|
37
|
+
server.close((err) => (err ? reject(err) : resolve()));
|
|
38
|
+
});
|
|
39
|
+
}
|
|
40
|
+
if (disconnectDatabase)
|
|
41
|
+
await (0, connection_1.disconnectDB)(serviceName);
|
|
42
|
+
clearTimeout(forceExit);
|
|
43
|
+
process.exit(0);
|
|
44
|
+
}
|
|
45
|
+
catch (error) {
|
|
46
|
+
clearTimeout(forceExit);
|
|
47
|
+
logger_1.default.error('Error during graceful shutdown', {
|
|
48
|
+
service: serviceName,
|
|
49
|
+
error: error?.message
|
|
50
|
+
});
|
|
51
|
+
process.exit(1);
|
|
52
|
+
}
|
|
53
|
+
};
|
|
54
|
+
process.on('SIGINT', () => void shutdown('SIGINT'));
|
|
55
|
+
process.on('SIGTERM', () => void shutdown('SIGTERM'));
|
|
56
|
+
};
|
|
57
|
+
exports.registerShutdown = registerShutdown;
|
|
58
|
+
//# sourceMappingURL=shutdown.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"shutdown.js","sourceRoot":"","sources":["../../src/app/shutdown.ts"],"names":[],"mappings":";;;;;;AACA,+DAAuC;AACvC,uDAAsD;AAqBtD;;;;;;;;;GASG;AACI,MAAM,gBAAgB,GAAG,CAAC,EAC/B,WAAW,EACX,MAAM,EACN,kBAAkB,GAAG,IAAI,EACzB,UAAU,EACV,gBAAgB,GAAG,MAAM,EACD,EAAQ,EAAE;IAClC,IAAI,YAAY,GAAG,KAAK,CAAC;IAEzB,MAAM,QAAQ,GAAG,KAAK,EAAE,MAAc,EAAiB,EAAE;QACvD,IAAI,YAAY;YAAE,OAAO;QACzB,YAAY,GAAG,IAAI,CAAC;QAEpB,gBAAM,CAAC,IAAI,CAAC,8CAA8C,EAAE,EAAE,OAAO,EAAE,WAAW,EAAE,MAAM,EAAE,CAAC,CAAC;QAE9F,MAAM,SAAS,GAAG,UAAU,CAAC,G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,CAAC,CAAC,CAAC;AACxD,CAAC,CAAC;AA/CW,QAAA,gBAAgB,oBA+C3B"}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { Request, Response } from 'express';
|
|
2
|
+
export interface HealthCheckConfig {
|
|
3
|
+
/** Service name reported in the body, e.g. `auth-service`. */
|
|
4
|
+
service: string;
|
|
5
|
+
/** Human-readable service description. */
|
|
6
|
+
description: string;
|
|
7
|
+
/** Reported version. Defaults to `1.0.0`. */
|
|
8
|
+
version?: string;
|
|
9
|
+
/**
|
|
10
|
+
* Whether readiness depends on the MongoDB connection. Defaults to `true`:
|
|
11
|
+
* the response reports `dependencies.mongodb` and returns 503 while
|
|
12
|
+
* disconnected. Set `false` for services with no database (e.g.
|
|
13
|
+
* public-service), which then always report `ok` with no `dependencies`.
|
|
14
|
+
*/
|
|
15
|
+
checkDatabase?: boolean;
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* The single, unified `/health` readiness handler for every backend service.
|
|
19
|
+
*
|
|
20
|
+
* Response contract (identical across services):
|
|
21
|
+
* { status, service, type: 'backend', timestamp, version, description }
|
|
22
|
+
* plus, when `checkDatabase` is `true` (the default), a
|
|
23
|
+
* `dependencies.mongodb` field and a 503 while the connection is down. A
|
|
24
|
+
* DB-less service (`checkDatabase: false`) omits `dependencies` and always
|
|
25
|
+
* reports `ok`. On an unexpected failure the handler returns 503 with a
|
|
26
|
+
* generic `error: 'Health check failed'` body.
|
|
27
|
+
*
|
|
28
|
+
* `/health/live` (liveness, no dependency checks) is mounted separately by
|
|
29
|
+
* `createBaseApp`.
|
|
30
|
+
*/
|
|
31
|
+
export declare const createHealthCheck: ({ service, description, version, checkDatabase }: HealthCheckConfig) => (_req: Request, res: Response) => Promise<void>;
|
|
32
|
+
//# sourceMappingURL=createHealthCheck.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"createHealthCheck.d.ts","sourceRoot":"","sources":["../../src/health/createHealthCheck.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAC;AAG5C,MAAM,WAAW,iBAAiB;IAChC,8DAA8D;IAC9D,OAAO,EAAE,MAAM,CAAC;IAChB,0CAA0C;IAC1C,WAAW,EAAE,MAAM,CAAC;IACpB,6CAA6C;IAC7C,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB;;;;;OAKG;IACH,aAAa,CAAC,EAAE,OAAO,CAAC;CACzB;AAED;;;;;;;;;;;;;GAaG;AACH,eAAO,MAAM,iBAAiB,GAAI,kDAK/B,iBAAiB,MACJ,MAAM,OAAO,EAAE,KAAK,QAAQ,KAAG,OAAO,CAAC,IAAI,CA2B1D,CAAC"}
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.createHealthCheck = void 0;
|
|
7
|
+
const mongoose_1 = __importDefault(require("mongoose"));
|
|
8
|
+
/**
|
|
9
|
+
* The single, unified `/health` readiness handler for every backend service.
|
|
10
|
+
*
|
|
11
|
+
* Response contract (identical across services):
|
|
12
|
+
* { status, service, type: 'backend', timestamp, version, description }
|
|
13
|
+
* plus, when `checkDatabase` is `true` (the default), a
|
|
14
|
+
* `dependencies.mongodb` field and a 503 while the connection is down. A
|
|
15
|
+
* DB-less service (`checkDatabase: false`) omits `dependencies` and always
|
|
16
|
+
* reports `ok`. On an unexpected failure the handler returns 503 with a
|
|
17
|
+
* generic `error: 'Health check failed'` body.
|
|
18
|
+
*
|
|
19
|
+
* `/health/live` (liveness, no dependency checks) is mounted separately by
|
|
20
|
+
* `createBaseApp`.
|
|
21
|
+
*/
|
|
22
|
+
const createHealthCheck = ({ service, description, version = '1.0.0', checkDatabase = true }) => {
|
|
23
|
+
return async (_req, res) => {
|
|
24
|
+
const timestamp = new Date().toISOString();
|
|
25
|
+
const base = { service, type: 'backend', timestamp, version, description };
|
|
26
|
+
if (!checkDatabase) {
|
|
27
|
+
res.status(200).json({ status: 'ok', ...base });
|
|
28
|
+
return;
|
|
29
|
+
}
|
|
30
|
+
try {
|
|
31
|
+
const isMongoHealthy = mongoose_1.default.connection.readyState === 1; // 1 = connected
|
|
32
|
+
res.status(isMongoHealthy ? 200 : 503).json({
|
|
33
|
+
status: isMongoHealthy ? 'ok' : 'error',
|
|
34
|
+
...base,
|
|
35
|
+
dependencies: {
|
|
36
|
+
mongodb: isMongoHealthy ? 'connected' : 'disconnected'
|
|
37
|
+
}
|
|
38
|
+
});
|
|
39
|
+
}
|
|
40
|
+
catch {
|
|
41
|
+
res.status(503).json({
|
|
42
|
+
status: 'error',
|
|
43
|
+
...base,
|
|
44
|
+
error: 'Health check failed'
|
|
45
|
+
});
|
|
46
|
+
}
|
|
47
|
+
};
|
|
48
|
+
};
|
|
49
|
+
exports.createHealthCheck = createHealthCheck;
|
|
50
|
+
//# sourceMappingURL=createHealthCheck.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"createHealthCheck.js","sourceRoot":"","sources":["../../src/health/createHealthCheck.ts"],"names":[],"mappings":";;;;;;AACA,wDAAgC;AAkBhC;;;;;;;;;;;;;GAaG;AACI,MAAM,iBAAiB,GAAG,CAAC,EAChC,OAAO,EACP,WAAW,EACX,OAAO,GAAG,OAAO,EACjB,aAAa,GAAG,IAAI,EACF,EAAE,EAAE;IACtB,OAAO,KAAK,EAAE,IAAa,EAAE,GAAa,EAAiB,EAAE;QAC3D,MAAM,SAAS,GAAG,IAAI,IAAI,EAAE,CAAC,WAAW,EAAE,CAAC;QAC3C,MAAM,IAAI,GAAG,EAAE,OAAO,EAAE,IAAI,EAAE,SAAS,EAAE,SAAS,EAAE,OAAO,EAAE,WAAW,EAAE,CAAC;QAE3E,IAAI,CAAC,aAAa,EAAE,CAAC;YACnB,GAAG,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,IAAI,CAAC,EAAE,MAAM,EAAE,IAAI,EAAE,GAAG,IAAI,EAAE,CAAC,CAAC;YAChD,OAAO;QACT,CAAC;QAED,IAAI,CAAC;YACH,MAAM,cAAc,GAAG,kBAAQ,CAAC,UAAU,CAAC,UAAU,KAAK,CAAC,CAAC,CAAC,gBAAgB;YAE7E,GAAG,CAAC,MAAM,CAAC,cAAc,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,IAAI,CAAC;gBAC1C,MAAM,EAAE,cAAc,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,OAAO;gBACvC,GAAG,IAAI;gBACP,YAAY,EAAE;oBACZ,OAAO,EAAE,cAAc,CAAC,CAAC,CAAC,WAAW,CAAC,CAAC,CAAC,cAAc;iBACvD;aACF,CAAC,CAAC;QACL,CAAC;QAAC,MAAM,CAAC;YACP,GAAG,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,IAAI,CAAC;gBACnB,MAAM,EAAE,OAAO;gBACf,GAAG,IAAI;gBACP,KAAK,EAAE,qBAAqB;aAC7B,CAAC,CAAC;QACL,CAAC;IACH,CAAC,CAAC;AACJ,CAAC,CAAC;AAjCW,QAAA,iBAAiB,qBAiC5B"}
|
package/dist/index.d.ts
CHANGED
|
@@ -1,7 +1,11 @@
|
|
|
1
1
|
export { createBaseApp } from './app/createBaseApp';
|
|
2
2
|
export type { CreateBaseAppOptions } from './app/createBaseApp';
|
|
3
|
+
export { registerShutdown } from './app/shutdown';
|
|
4
|
+
export type { RegisterShutdownOptions } from './app/shutdown';
|
|
3
5
|
export { default as logger } from './logging/logger';
|
|
4
6
|
export { healthCheck, healthLive, metricsHandler } from './health/healthController';
|
|
7
|
+
export { createHealthCheck } from './health/createHealthCheck';
|
|
8
|
+
export type { HealthCheckConfig } from './health/createHealthCheck';
|
|
5
9
|
export { connectDB, disconnectDB } from './database/connection';
|
|
6
10
|
export { requireEnv } from './config/env';
|
|
7
11
|
export { HttpError, BadRequestError, UnauthorizedError, ForbiddenError, NotFoundError, ConflictError, TooManyRequestsError } from './errors/HttpError';
|
|
@@ -15,6 +19,7 @@ export type { UserPayload } from './types/auth';
|
|
|
15
19
|
export { generateCorrelationId, correlationMiddleware } from './utils/correlation';
|
|
16
20
|
export { createApiResponse, sendSuccess, sendError } from './utils/response';
|
|
17
21
|
export type { ApiResponse } from './utils/response';
|
|
22
|
+
export { buildAccessQuery, canAccessResource } from './utils/permissionUtils';
|
|
18
23
|
export { metricsMiddleware, httpRequestDuration, httpRequestsTotal, databaseQueryDuration, databaseQueriesTotal, businessMetrics, register } from './metrics';
|
|
19
24
|
export { initTracer, getTracer, startSpan, tracingMiddleware, createChildSpan, logToSpan, setSpanTag, injectHeaders, extractSpanContext } from './tracing';
|
|
20
25
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAC;AACpD,YAAY,EAAE,oBAAoB,EAAE,MAAM,qBAAqB,CAAC;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAC;AACpD,YAAY,EAAE,oBAAoB,EAAE,MAAM,qBAAqB,CAAC;AAChE,OAAO,EAAE,gBAAgB,EAAE,MAAM,gBAAgB,CAAC;AAClD,YAAY,EAAE,uBAAuB,EAAE,MAAM,gBAAgB,CAAC;AAG9D,OAAO,EAAE,OAAO,IAAI,MAAM,EAAE,MAAM,kBAAkB,CAAC;AAGrD,OAAO,EAAE,WAAW,EAAE,UAAU,EAAE,cAAc,EAAE,MAAM,2BAA2B,CAAC;AACpF,OAAO,EAAE,iBA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,SAAS,EACT,UAAU,EACV,aAAa,EACb,kBAAkB,EACnB,MAAM,WAAW,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -4,10 +4,13 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
4
4
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
5
5
|
};
|
|
6
6
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
|
-
exports.
|
|
7
|
+
exports.injectHeaders = exports.setSpanTag = exports.logToSpan = exports.createChildSpan = exports.tracingMiddleware = exports.startSpan = exports.getTracer = exports.initTracer = exports.register = exports.businessMetrics = exports.databaseQueriesTotal = exports.databaseQueryDuration = exports.httpRequestsTotal = exports.httpRequestDuration = exports.metricsMiddleware = exports.canAccessResource = exports.buildAccessQuery = exports.sendError = exports.sendSuccess = exports.createApiResponse = exports.correlationMiddleware = exports.generateCorrelationId = exports.validate = exports.strictRateLimiter = exports.standardRateLimiter = exports.createRateLimiter = exports.securityHeaders = exports.simpleRequestLogger = exports.requestLoggerWithMetrics = exports.requestLogger = exports.errorHandler = exports.createCorsMiddleware = exports.authenticateToken = exports.TooManyRequestsError = exports.ConflictError = exports.NotFoundError = exports.ForbiddenError = exports.UnauthorizedError = exports.BadRequestError = exports.HttpError = exports.requireEnv = exports.disconnectDB = exports.connectDB = exports.createHealthCheck = exports.metricsHandler = exports.healthLive = exports.healthCheck = exports.logger = exports.registerShutdown = exports.createBaseApp = void 0;
|
|
8
|
+
exports.extractSpanContext = void 0;
|
|
8
9
|
// App bootstrap
|
|
9
10
|
var createBaseApp_1 = require("./app/createBaseApp");
|
|
10
11
|
Object.defineProperty(exports, "createBaseApp", { enumerable: true, get: function () { return createBaseApp_1.createBaseApp; } });
|
|
12
|
+
var shutdown_1 = require("./app/shutdown");
|
|
13
|
+
Object.defineProperty(exports, "registerShutdown", { enumerable: true, get: function () { return shutdown_1.registerShutdown; } });
|
|
11
14
|
// Logging
|
|
12
15
|
var logger_1 = require("./logging/logger");
|
|
13
16
|
Object.defineProperty(exports, "logger", { enumerable: true, get: function () { return __importDefault(logger_1).default; } });
|
|
@@ -16,6 +19,8 @@ var healthController_1 = require("./health/healthController");
|
|
|
16
19
|
Object.defineProperty(exports, "healthCheck", { enumerable: true, get: function () { return healthController_1.healthCheck; } });
|
|
17
20
|
Object.defineProperty(exports, "healthLive", { enumerable: true, get: function () { return healthController_1.healthLive; } });
|
|
18
21
|
Object.defineProperty(exports, "metricsHandler", { enumerable: true, get: function () { return healthController_1.metricsHandler; } });
|
|
22
|
+
var createHealthCheck_1 = require("./health/createHealthCheck");
|
|
23
|
+
Object.defineProperty(exports, "createHealthCheck", { enumerable: true, get: function () { return createHealthCheck_1.createHealthCheck; } });
|
|
19
24
|
// Database
|
|
20
25
|
var connection_1 = require("./database/connection");
|
|
21
26
|
Object.defineProperty(exports, "connectDB", { enumerable: true, get: function () { return connection_1.connectDB; } });
|
|
@@ -58,6 +63,9 @@ var response_1 = require("./utils/response");
|
|
|
58
63
|
Object.defineProperty(exports, "createApiResponse", { enumerable: true, get: function () { return response_1.createApiResponse; } });
|
|
59
64
|
Object.defineProperty(exports, "sendSuccess", { enumerable: true, get: function () { return response_1.sendSuccess; } });
|
|
60
65
|
Object.defineProperty(exports, "sendError", { enumerable: true, get: function () { return response_1.sendError; } });
|
|
66
|
+
var permissionUtils_1 = require("./utils/permissionUtils");
|
|
67
|
+
Object.defineProperty(exports, "buildAccessQuery", { enumerable: true, get: function () { return permissionUtils_1.buildAccessQuery; } });
|
|
68
|
+
Object.defineProperty(exports, "canAccessResource", { enumerable: true, get: function () { return permissionUtils_1.canAccessResource; } });
|
|
61
69
|
// Metrics
|
|
62
70
|
var metrics_1 = require("./metrics");
|
|
63
71
|
Object.defineProperty(exports, "metricsMiddleware", { enumerable: true, get: function () { return metrics_1.metricsMiddleware; } });
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"m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AqB,OAAA;AACrD,6CAA6E;AAApE,6GAAA,iBAAiB,OAAA;AAAE,uGAAA,WAAW,OAAA;AAAE,qGAAA,SAAS,OAAA;AAElD,2DAA8E;AAArE,mHAAA,gBAAgB,OAAA;AAAE,oHAAA,iBAAiB,OAAA;AAE5C,UAAU;AACV,qCAQmB;AAPjB,4GAAA,iBAAiB,OAAA;AACjB,8GAAA,mBAAmB,OAAA;AACnB,4GAAA,iBAAiB,OAAA;AACjB,gHAAA,qBAAqB,OAAA;AACrB,+GAAA,oBAAoB,OAAA;AACpB,0GAAA,eAAe,OAAA;AACf,mGAAA,QAAQ,OAAA;AAGV,UAAU;AACV,qCAUmB;AATjB,qGAAA,UAAU,OAAA;AACV,oGAAA,SAAS,OAAA;AACT,oGAAA,SAAS,OAAA;AACT,4GAAA,iBAAiB,OAAA;AACjB,0GAAA,eAAe,OAAA;AACf,oGAAA,SAAS,OAAA;AACT,qGAAA,UAAU,OAAA;AACV,wGAAA,aAAa,OAAA;AACb,6GAAA,kBAAkB,OAAA"}
|
package/dist/logging/logger.js
CHANGED
|
@@ -29,7 +29,7 @@ const colors = {
|
|
|
29
29
|
};
|
|
30
30
|
winston_1.default.addColors(colors);
|
|
31
31
|
// Define format for console (human-readable)
|
|
32
|
-
const consoleFormat = winston_1.default.format.combine(winston_1.default.format.timestamp({ format: 'YYYY-MM-DD HH:mm:ss:ms' }), winston_1.default.format.colorize({ all: true }), winston_1.default.format.printf((info) => `${info.timestamp} ${info.level}: ${info.message}`));
|
|
32
|
+
const consoleFormat = winston_1.default.format.combine(winston_1.default.format.timestamp({ format: 'YYYY-MM-DD HH:mm:ss:ms' }), winston_1.default.format.colorize({ all: true }), winston_1.default.format.printf((info) => `${info.timestamp} ${info.level}: ${String(info.message)}`));
|
|
33
33
|
// Define JSON format for production (structured logging)
|
|
34
34
|
const jsonFormat = winston_1.default.format.combine(winston_1.default.format.timestamp(), winston_1.default.format.errors({ stack: true }), winston_1.default.format.json());
|
|
35
35
|
// Choose format based on environment
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"logger.js","sourceRoot":"","sources":["../../src/logging/logger.ts"],"names":[],"mappings":";;;;;AAAA,sDAA8B;AAC9B,gDAAwB;AACxB,4CAAoB;AAEpB,oBAAoB;AACpB,MAAM,MAAM,GAAG;IACb,KAAK,EAAE,CAAC;IACR,IAAI,EAAE,CAAC;IACP,IAAI,EAAE,CAAC;IACP,IAAI,EAAE,CAAC;IACP,KAAK,EAAE,CAAC;CACT,CAAC;AAEF,MAAM,KAAK,GAAG,GAAG,EAAE;IACjB,MAAM,GAAG,GAAG,OAAO,CAAC,GAAG,CAAC,QAAQ,IAAI,aAAa,CAAC;IAClD,MAAM,aAAa,GAAG,GAAG,KAAK,aAAa,CAAC;IAC5C,OAAO,aAAa,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC;AAC1C,CAAC,CAAC;AAEF,+BAA+B;AAC/B,MAAM,MAAM,GAAG;IACb,KAAK,EAAE,KAAK;IACZ,IAAI,EAAE,QAAQ;IACd,IAAI,EAAE,OAAO;IACb,IAAI,EAAE,SAAS;IACf,KAAK,EAAE,OAAO;CACf,CAAC;AAEF,iBAAO,CAAC,SAAS,CAAC,MAAM,CAAC,CAAC;AAE1B,6CAA6C;AAC7C,MAAM,aAAa,GAAG,iBAAO,CAAC,MAAM,CAAC,OAAO,CAC1C,iBAAO,CAAC,MAAM,CAAC,SAAS,CAAC,EAAE,MAAM,EAAE,wBAAwB,EAAE,CAAC,EAC9D,iBAAO,CAAC,MAAM,CAAC,QAAQ,CAAC,EAAE,GAAG,EAAE,IAAI,EAAE,CAAC,EACtC,iBAAO,CAAC,MAAM,CAAC,MAAM,CACnB,CAAC,
|
|
1
|
+
{"version":3,"file":"logger.js","sourceRoot":"","sources":["../../src/logging/logger.ts"],"names":[],"mappings":";;;;;AAAA,sDAA8B;AAC9B,gDAAwB;AACxB,4CAAoB;AAEpB,oBAAoB;AACpB,MAAM,MAAM,G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iBAAO,CAAC,MAAM,CAAC,OAAO,CAC5B,iBAAO,CAAC,MAAM,CAAC,QAAQ,EAAE,EACzB,iBAAO,CAAC,MAAM,CAAC,MAAM,EAAE,CACxB;SACF,CAAC;KACH;IACD,iBAAiB,EAAE;QACjB,IAAI,iBAAO,CAAC,UAAU,CAAC,OAAO,CAAC;YAC7B,MAAM,EAAE,iBAAO,CAAC,MAAM,CAAC,OAAO,CAC5B,iBAAO,CAAC,MAAM,CAAC,QAAQ,EAAE,EACzB,iBAAO,CAAC,MAAM,CAAC,MAAM,EAAE,CACxB;SACF,CAAC;KACH;CACF,CAAC,CAAC;AAEH,kBAAe,MAAM,CAAC"}
|
package/dist/metrics/index.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import promClient from 'prom-client';
|
|
2
|
+
import { Request, Response, NextFunction } from 'express';
|
|
2
3
|
declare const register: promClient.Registry<"text/plain; version=0.0.4; charset=utf-8">;
|
|
3
4
|
export declare const httpRequestDuration: promClient.Histogram<"route" | "method" | "status_code">;
|
|
4
5
|
export declare const httpRequestsTotal: promClient.Counter<"route" | "method" | "status_code">;
|
|
@@ -11,7 +12,7 @@ export declare const businessMetrics: {
|
|
|
11
12
|
usersRegistered: promClient.Counter<string>;
|
|
12
13
|
paymentsProcessed: promClient.Counter<"method" | "status">;
|
|
13
14
|
};
|
|
14
|
-
export declare const metricsHandler: (
|
|
15
|
-
export declare const metricsMiddleware: (req:
|
|
15
|
+
export declare const metricsHandler: (_req: Request, res: Response) => Promise<void>;
|
|
16
|
+
export declare const metricsMiddleware: (req: Request, res: Response, next: NextFunction) => void;
|
|
16
17
|
export { register };
|
|
17
18
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/metrics/index.ts"],"names":[],"mappings":"AAAA,OAAO,UAAU,MAAM,aAAa,CAAC;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/metrics/index.ts"],"names":[],"mappings":"AAAA,OAAO,UAAU,MAAM,aAAa,CAAC;AACrC,OAAO,EAAE,OAAO,EAAE,QAAQ,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AAG1D,QAAA,MAAM,QAAQ,iEAA4B,CAAC;AAY3C,eAAO,MAAM,mBAAmB,0DAK9B,CAAC;AAEH,eAAO,MAAM,iBAAiB,wDAI5B,CAAC;AAEH,eAAO,MAAM,iBAAiB,0BAG5B,CAAC;AAEH,eAAO,MAAM,qBAAqB,kDAKhC,CAAC;AAEH,eAAO,MAAM,oBAAoB,2DAI/B,CAAC;AAEH,eAAO,MAAM,eAAe;;;;;CAsB3B,CAAC;AAGF,eAAO,MAAM,cAAc,GAAU,MAAM,OAAO,EAAE,KAAK,QAAQ,kBAQhE,CAAC;AAGF,eAAO,MAAM,iBAAiB,GAAI,KAAK,OAAO,EAAE,KAAK,QAAQ,EAAE,MAAM,YAAY,SAyBhF,CAAC;AAEF,OAAO,EAAE,QAAQ,EAAE,CAAC"}
|
package/dist/metrics/index.js
CHANGED
|
@@ -63,7 +63,7 @@ exports.businessMetrics = {
|
|
|
63
63
|
})
|
|
64
64
|
};
|
|
65
65
|
// Metrics endpoint handler
|
|
66
|
-
const metricsHandler = async (
|
|
66
|
+
const metricsHandler = async (_req, res) => {
|
|
67
67
|
try {
|
|
68
68
|
res.set('Content-Type', register.contentType);
|
|
69
69
|
const metrics = await register.metrics();
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/metrics/index.ts"],"names":[],"mappings":";;;;;;AAAA,8DAAqC;
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/metrics/index.ts"],"names":[],"mappings":";;;;;;AAAA,8DAAqC;AAGrC,gDAAgD;AAChD,MAAM,QAAQ,GAAG,IAAI,qBAAU,CAAC,QAAQ,EAAE,CAAC;AA0GlC,4BAAQ;AAxGjB,oDAAoD;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E,iCAAiC,CAAC,CAAC;QAC9E,GAAG,CAAC,MAAM,CAAC,8BAA8B,EAAE,+EAA+E,CAAC,CAAC;IAC9H,CAAC;IAED,IAAI,KAAK,EAAE,CAAC;QACV,GAAG,CAAC,MAAM,CAAC,KAAK,CAAC,UAAU,CAAC,CAAC,IAAI,CAAC;YAChC,OAAO,EAAE,KAAK;YACd,KAAK,EAAE,KAAK,CAAC,IAAI;YACjB,OAAO,EAAE,KAAK,CAAC,OAAO;SACvB,CAAC,CAAC;QACH,OAAO;IACT,CAAC;IAED,+DAA+D;IAC/D,MAAM,aAAa,GAAG,OAAO,CAAC,GAAG,CAAC,QAAQ,KAAK,aAAa,CAAC;IAC7D,MAAM,YAAY,GAAG,aAAa,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,sBAAsB,CAAC;IAE5E,GAAG,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,IAAI,CAAC;QACnB,OAAO,EAAE,KAAK;QACd,KAAK,EAAE,uBAAuB;QAC9B,OAAO,EAAE,YAAY;QACrB,GAAG,CAAC,aAAa,IAAI,EAAE,KAAK,EAAE,KAAK,CAAC,KAAK,EAAE,CAAC;KAC7C,CAAC,CAAC;AACL,CAAC,CAAC;AA1DW,QAAA,YAAY,gBA0DvB"}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { Request, Response, NextFunction } from 'express';
|
|
1
2
|
/**
|
|
2
3
|
* Morgan middleware configured to use Winston logger
|
|
3
4
|
* Logs HTTP requests in structured format
|
|
@@ -7,10 +8,10 @@ export declare const requestLogger: (req: import("node:http").IncomingMessage, r
|
|
|
7
8
|
* Combined middleware that includes both logging and metrics
|
|
8
9
|
* Use this instead of separate requestLogger and metricsMiddleware
|
|
9
10
|
*/
|
|
10
|
-
export declare const requestLoggerWithMetrics: ((req:
|
|
11
|
+
export declare const requestLoggerWithMetrics: ((req: Request, res: Response, next: NextFunction) => void)[];
|
|
11
12
|
/**
|
|
12
13
|
* Simple request logger for development
|
|
13
14
|
* Logs basic request info with correlation ID
|
|
14
15
|
*/
|
|
15
|
-
export declare const simpleRequestLogger: (req:
|
|
16
|
+
export declare const simpleRequestLogger: (req: Request, res: Response, next: NextFunction) => void;
|
|
16
17
|
//# sourceMappingURL=requestLogger.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"requestLogger.d.ts","sourceRoot":"","sources":["../../src/middleware/requestLogger.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"requestLogger.d.ts","sourceRoot":"","sources":["../../src/middleware/requestLogger.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,OAAO,EAAE,QAAQ,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AAI1D;;;GAGG;AACH,eAAO,MAAM,aAAa,yIAHM,CAAA,yBAS9B,CAAC;AAEH;;;GAGG;AACH,eAAO,MAAM,wBAAwB,+DAAqC,CAAC;AAE3E;;;GAGG;AACH,eAAO,MAAM,mBAAmB,GAAI,KAAK,OAAO,EAAE,KAAK,QAAQ,EAAE,MAAM,YAAY,SAoBlF,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"requestLogger.js","sourceRoot":"","sources":["../../src/middleware/requestLogger.ts"],"names":[],"mappings":";;;;;;AAAA,oDAA4B;
|
|
1
|
+
{"version":3,"file":"requestLogger.js","sourceRoot":"","sources":["../../src/middleware/requestLogger.ts"],"names":[],"mappings":";;;;;;AAAA,oDAA4B;AAE5B,+DAAuC;AACvC,wCAA+C;AAE/C;;;GAGG;AACU,QAAA,aAAa,GAAG,IAAA,gBAAM,EAAC,UAAU,EAAE;IAC9C,MAAM,EAAE;QACN,KAAK,EAAE,CAAC,OAAe,EAAE,EAAE;YACzB,gBAAM,CAAC,IAAI,CAAC,OAAO,CAAC,IAAI,EAAE,CAAC,CAAC;QAC9B,CAAC;KACF;CACF,CAAC,CAAC;AAEH;;;GAGG;AACU,QAAA,wBAAwB,GAAG,CAAC,qBAAa,EAAE,2BAAiB,CAAC,CAAC;AAE3E;;;GAGG;AACI,MAAM,mBAAmB,GAAG,CAAC,GAAY,EAAE,GAAa,EAAE,IAAkB,EAAE,EAAE;IACrF,MAAM,KAAK,GAAG,IAAI,CAAC,GAAG,EAAE,CAAC;IACzB,MAAM,aAAa,GAAG,GAAG,CAAC,aAAa,IAAI,SAAS,CAAC;IAErD,gBAAM,CAAC,IAAI,CAAC,KAAK,GAAG,CAAC,MAAM,IAAI,GAAG,CAAC,GAAG,EAAE,EAAE;QACxC,aAAa;QACb,EAAE,EAAE,GAAG,CAAC,EAAE;QACV,SAAS,EAAE,GAAG,CAAC,GAAG,CAAC,YAAY,CAAC;KACjC,CAAC,CAAC;IAEH,GAAG,CAAC,EAAE,CAAC,QAAQ,EAAE,GAAG,EAAE;QACpB,MAAM,QAAQ,GAAG,IAAI,CAAC,GAAG,EAAE,GAAG,KAAK,CAAC;QACpC,gBAAM,CAAC,IAAI,CAAC,KAAK,GAAG,CAAC,MAAM,IAAI,GAAG,CAAC,GAAG,IAAI,GAAG,CAAC,UAAU,IAAI,QAAQ,IAAI,EAAE;YACxE,aAAa;YACb,UAAU,EAAE,GAAG,CAAC,UAAU;YAC1B,QAAQ;SACT,CAAC,CAAC;IACL,CAAC,CAAC,CAAC;IAEH,IAAI,EAAE,CAAC;AACT,CAAC,CAAC;AApBW,QAAA,mBAAmB,uBAoB9B"}
|
package/dist/tracing/index.d.ts
CHANGED
|
@@ -1,13 +1,14 @@
|
|
|
1
|
-
import { Tracer } from '@opentelemetry/api';
|
|
1
|
+
import { Tracer, Span, Context, Attributes, AttributeValue } from '@opentelemetry/api';
|
|
2
|
+
import { Request, Response, NextFunction } from 'express';
|
|
2
3
|
export declare const initTracer: (serviceName: string) => Tracer;
|
|
3
4
|
export declare const getTracer: () => Tracer;
|
|
4
|
-
export declare const startSpan: (operationName: string,
|
|
5
|
-
export declare const tracingMiddleware: (req:
|
|
6
|
-
export declare const createChildSpan: (operationName: string,
|
|
7
|
-
export declare const logToSpan: (span:
|
|
8
|
-
export declare const setSpanTag: (span:
|
|
9
|
-
export declare const injectHeaders: (span:
|
|
5
|
+
export declare const startSpan: (operationName: string, parent?: Span | Context) => Span;
|
|
6
|
+
export declare const tracingMiddleware: (req: Request, res: Response, next: NextFunction) => void;
|
|
7
|
+
export declare const createChildSpan: (operationName: string, parent: Span | Context) => Span;
|
|
8
|
+
export declare const logToSpan: (span: Span, event: string, data?: Attributes) => void;
|
|
9
|
+
export declare const setSpanTag: (span: Span, key: string, value: AttributeValue) => void;
|
|
10
|
+
export declare const injectHeaders: (span: Span) => {
|
|
10
11
|
[key: string]: string;
|
|
11
12
|
};
|
|
12
|
-
export declare const extractSpanContext: (headers:
|
|
13
|
+
export declare const extractSpanContext: (headers: Record<string, string | string[] | undefined>) => Context;
|
|
13
14
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/tracing/index.ts"],"names":[],"mappings":"AAAA,OAAO,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/tracing/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAKL,MAAM,EACN,IAAI,EACJ,OAAO,EACP,UAAU,EACV,cAAc,EACf,MAAM,oBAAoB,CAAC;AAC5B,OAAO,EAAE,OAAO,EAAE,QAAQ,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AAQ1D,eAAO,MAAM,UAAU,GAAI,aAAa,MAAM,KAAG,MAiBhD,CAAC;AAKF,eAAO,MAAM,SAAS,QAAO,MAK5B,CAAC;AAGF,eAAO,MAAM,SAAS,GAAI,eAAe,MAAM,EAAE,SAAS,IAAI,GAAG,OAAO,SASvE,CAAC;AAGF,eAAO,MAAM,iBAAiB,GAAI,KAAK,OAAO,EAAE,KAAK,QAAQ,EAAE,MAAM,YAAY,SAmBhF,CAAC;AAGF,eAAO,MAAM,eAAe,GAAI,eAAe,MAAM,EAAE,QAAQ,IAAI,GAAG,OAAO,SAE5E,CAAC;AAGF,eAAO,MAAM,SAAS,GAAI,MAAM,IAAI,EAAE,OAAO,MAAM,EAAE,OAAO,UAAU,SAErE,CAAC;AAGF,eAAO,MAAM,UAAU,GAAI,MAAM,IAAI,EAAE,KAAK,MAAM,EAAE,OAAO,cAAc,SAExE,CAAC;AAGF,eAAO,MAAM,aAAa,GAAI,MAAM,IAAI;;CAIvC,CAAC;AAGF,eAAO,MAAM,kBAAkB,GAC7B,SAAS,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,EAAE,GAAG,SAAS,CAAC,KACrD,OAEF,CAAC"}
|
package/dist/tracing/index.js
CHANGED
|
@@ -34,13 +34,13 @@ const getTracer = () => {
|
|
|
34
34
|
};
|
|
35
35
|
exports.getTracer = getTracer;
|
|
36
36
|
// Start a new span. `parent` may be a Span or a Context (e.g. from extractSpanContext).
|
|
37
|
-
const startSpan = (operationName,
|
|
38
|
-
if (!
|
|
37
|
+
const startSpan = (operationName, parent) => {
|
|
38
|
+
if (!parent) {
|
|
39
39
|
return (0, exports.getTracer)().startSpan(operationName);
|
|
40
40
|
}
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
41
|
+
// A Span exposes `spanContext()`; a Context does not — use that to decide
|
|
42
|
+
// whether we need to wrap the parent span into an active context first.
|
|
43
|
+
const parentContext = 'spanContext' in parent ? api_1.trace.setSpan(api_1.context.active(), parent) : parent;
|
|
44
44
|
return (0, exports.getTracer)().startSpan(operationName, undefined, parentContext);
|
|
45
45
|
};
|
|
46
46
|
exports.startSpan = startSpan;
|
|
@@ -60,8 +60,8 @@ const tracingMiddleware = (req, res, next) => {
|
|
|
60
60
|
};
|
|
61
61
|
exports.tracingMiddleware = tracingMiddleware;
|
|
62
62
|
// Helper to create child spans
|
|
63
|
-
const createChildSpan = (operationName,
|
|
64
|
-
return (0, exports.startSpan)(operationName,
|
|
63
|
+
const createChildSpan = (operationName, parent) => {
|
|
64
|
+
return (0, exports.startSpan)(operationName, parent);
|
|
65
65
|
};
|
|
66
66
|
exports.createChildSpan = createChildSpan;
|
|
67
67
|
// Helper to log events to spans
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/tracing/index.ts"],"names":[],"mappings":";;;AAAA,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/tracing/index.ts"],"names":[],"mappings":";;;AAAA,4CAU4B;AAE5B,kEAAuF;AACvF,sFAA4E;AAC5E,wDAAkE;AAClE,8EAA8F;AAE9F,qEAAqE;AACrE,4GAA4G;AACrG,MAAM,UAAU,GAAG,CAAC,WAAmB,EAAU,EAAE;IACxD,MAAM,GAAG,GACP,OAAO,CAAC,GAAG,CAAC,kCAAkC;QAC9C,OAAO,CAAC,GAAG,CAAC,eAAe;QAC3B,wCAAwC,CAAC;IAE3C,MAAM,QAAQ,GAAG,IAAI,mCAAkB,CAAC;QACtC,QAAQ,EAAE,IAAA,kCAAsB,EAAC;YAC/B,CAAC,wCAAiB,CAAC,EAAE,WAAW;YAChC,CAAC,2CAAoB,CAAC,EAAE,OAAO,CAAC,GAAG,CAAC,mBAAmB,IAAI,OAAO;YAClE,wBAAwB,EAAE,OAAO,CAAC,GAAG,CAAC,QAAQ,IAAI,aAAa;SAChE,CAAC;QACF,cAAc,EAAE,CAAC,IAAI,mCAAkB,CAAC,IAAI,4CAAiB,CAAC,EAAE,GAAG,EAAE,CAAC,CAAC,CAAC;KACzE,CAAC,CAAC;IACH,QAAQ,CAAC,QAAQ,EAAE,CAAC;IAEpB,OAAO,QAAQ,CAAC,SAAS,CAAC,WAAW,CAAC,CAAC;AACzC,CAAC,CAAC;AAjBW,QAAA,UAAU,cAiBrB;AAEF,yBAAyB;AACzB,IAAI,MAAM,GAAkB,IAAI,CAAC;AAE1B,MAAM,SAAS,GAAG,GAAW,EAAE;IACpC,IAAI,CAAC,MAAM,EAAE,CAAC;QACZ,MAAM,GAAG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