@openapi-typescript-infra/service 4.27.2 → 5.0.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/{.eslintrc.js → .eslintrc.cjs} +1 -1
- package/{.prettierrc.js → .prettierrc.cjs} +1 -1
- package/Makefile +1 -1
- package/build/bin/start-service.js +8 -13
- package/build/bin/start-service.js.map +1 -1
- package/build/bootstrap.d.ts +4 -4
- package/build/bootstrap.js +17 -29
- package/build/bootstrap.js.map +1 -1
- package/build/config/index.d.ts +3 -3
- package/build/config/index.js +15 -36
- package/build/config/index.js.map +1 -1
- package/build/config/schema.js +1 -2
- package/build/config/shortstops.js +19 -25
- package/build/config/shortstops.js.map +1 -1
- package/build/config/validation.d.ts +1 -1
- package/build/config/validation.js +1 -4
- package/build/config/validation.js.map +1 -1
- package/build/development/port-finder.js +6 -12
- package/build/development/port-finder.js.map +1 -1
- package/build/development/repl.d.ts +2 -2
- package/build/development/repl.js +16 -24
- package/build/development/repl.js.map +1 -1
- package/build/env.js +5 -12
- package/build/env.js.map +1 -1
- package/build/error.d.ts +2 -2
- package/build/error.js +1 -5
- package/build/error.js.map +1 -1
- package/build/express-app/app.d.ts +2 -2
- package/build/express-app/app.js +44 -52
- package/build/express-app/app.js.map +1 -1
- package/build/express-app/index.d.ts +3 -3
- package/build/express-app/index.js +3 -19
- package/build/express-app/index.js.map +1 -1
- package/build/express-app/internal-server.d.ts +2 -2
- package/build/express-app/internal-server.js +5 -11
- package/build/express-app/internal-server.js.map +1 -1
- package/build/express-app/modules.d.ts +0 -1
- package/build/express-app/modules.js +6 -24
- package/build/express-app/modules.js.map +1 -1
- package/build/express-app/route-loader.d.ts +2 -2
- package/build/express-app/route-loader.js +10 -16
- package/build/express-app/route-loader.js.map +1 -1
- package/build/express-app/types.d.ts +2 -2
- package/build/express-app/types.js +1 -2
- package/build/hook.d.ts +2 -2
- package/build/hook.js +1 -4
- package/build/hook.js.map +1 -1
- package/build/index.d.ts +9 -9
- package/build/index.js +9 -27
- package/build/index.js.map +1 -1
- package/build/openapi.d.ts +3 -3
- package/build/openapi.js +17 -46
- package/build/openapi.js.map +1 -1
- package/build/telemetry/DummyExporter.js +3 -7
- package/build/telemetry/DummyExporter.js.map +1 -1
- package/build/telemetry/index.d.ts +3 -3
- package/build/telemetry/index.js +22 -51
- package/build/telemetry/index.js.map +1 -1
- package/build/telemetry/instrumentations.js +19 -22
- package/build/telemetry/instrumentations.js.map +1 -1
- package/build/telemetry/requestLogger.d.ts +2 -2
- package/build/telemetry/requestLogger.js +10 -18
- package/build/telemetry/requestLogger.js.map +1 -1
- package/build/tsconfig.build.tsbuildinfo +1 -1
- package/build/types.d.ts +2 -2
- package/build/types.js +1 -2
- package/package.json +14 -13
- package/src/bin/start-service.ts +3 -3
- package/src/bootstrap.ts +12 -17
- package/src/config/index.ts +4 -4
- package/src/config/validation.ts +1 -1
- package/src/development/port-finder.ts +1 -1
- package/src/development/repl.ts +6 -7
- package/src/error.ts +2 -2
- package/src/express-app/app.ts +11 -11
- package/src/express-app/index.ts +3 -3
- package/src/express-app/internal-server.ts +3 -3
- package/src/express-app/modules.ts +4 -22
- package/src/express-app/route-loader.ts +6 -6
- package/src/express-app/types.ts +2 -2
- package/src/hook.ts +2 -2
- package/src/index.ts +9 -9
- package/src/openapi.ts +6 -6
- package/src/telemetry/index.ts +5 -5
- package/src/telemetry/requestLogger.ts +7 -7
- package/src/types.ts +2 -2
- package/tsconfig.json +4 -3
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"route-loader.js","sourceRoot":"","sources":["../../src/express-app/route-loader.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"route-loader.js","sourceRoot":"","sources":["../../src/express-app/route-loader.ts"],"names":[],"mappings":"AAAA,OAAO,IAAI,MAAM,MAAM,CAAC;AAExB,OAAO,EAAE,MAAM,EAAE,MAAM,SAAS,CAAC;AAKjC,OAAO,EAAE,aAAa,EAAE,MAAM,cAAc,C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,EAAE,EAAE,oBAAoB,CAAC,CAAC;YACrF,GAAG,CAAC,GAAG,CAAC,SAAS,EAAE,WAAW,CAAC,CAAC;QAClC,CAAC;aAAM,CAAC;YACN,GAAG,CAAC,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC,EAAE,QAAQ,EAAE,EAAE,kCAAkC,CAAC,CAAC;QAC3E,CAAC;IACH,CAAC,CAAC,CACH,CAAC;AACJ,CAAC"}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { NextFunction, Response } from 'express';
|
|
2
|
-
import type { AnyServiceLocals, RequestLocals, RequestWithApp, ServiceLocals } from '../types';
|
|
3
|
-
import { ConfigurationSchema } from '../config/schema';
|
|
2
|
+
import type { AnyServiceLocals, RequestLocals, RequestWithApp, ServiceLocals } from '../types.js';
|
|
3
|
+
import { ConfigurationSchema } from '../config/schema.js';
|
|
4
4
|
export type ServiceHandler<SLocals extends AnyServiceLocals = ServiceLocals<ConfigurationSchema>, RLocals extends RequestLocals = RequestLocals, ResBody = unknown, RetType = unknown> = (req: RequestWithApp<SLocals>, res: Response<ResBody, RLocals>, next: NextFunction) => RetType | Promise<RetType>;
|
|
5
5
|
export interface ServiceRouter<SLocals extends AnyServiceLocals = ServiceLocals<ConfigurationSchema>, RLocals extends RequestLocals = RequestLocals> {
|
|
6
6
|
all(path: string, ...handlers: ServiceHandler<SLocals, RLocals>[]): void;
|
package/build/hook.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { ConfigurationSchema } from './config/schema';
|
|
2
|
-
import type { AnyServiceLocals, RequestLocals, Service, ServiceLocals } from './types';
|
|
1
|
+
import { ConfigurationSchema } from './config/schema.js';
|
|
2
|
+
import type { AnyServiceLocals, RequestLocals, Service, ServiceLocals } from './types.js';
|
|
3
3
|
/**
|
|
4
4
|
* Your service should call this function and then "inherit"
|
|
5
5
|
* the behavior in a functional way. So,
|
package/build/hook.js
CHANGED
|
@@ -1,6 +1,3 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.useService = useService;
|
|
4
1
|
/**
|
|
5
2
|
* Your service should call this function and then "inherit"
|
|
6
3
|
* the behavior in a functional way. So,
|
|
@@ -22,7 +19,7 @@ exports.useService = useService;
|
|
|
22
19
|
*
|
|
23
20
|
* @returns Service<Config, SLocals, RLocals>
|
|
24
21
|
*/
|
|
25
|
-
function useService(baseService) {
|
|
22
|
+
export function useService(baseService) {
|
|
26
23
|
return {
|
|
27
24
|
async start(app) {
|
|
28
25
|
await baseService?.start(app);
|
package/build/hook.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"hook.js","sourceRoot":"","sources":["../src/hook.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"hook.js","sourceRoot":"","sources":["../src/hook.ts"],"names":[],"mappings":"AAGA;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,MAAM,UAAU,UAAU,CAGxB,WAAuC;IACvC,OAAO;QACL,KAAK,CAAC,KAAK,CAAC,GAAG;YACb,MAAM,WAAW,EAAE,KAAK,CAAC,GAAG,CAAC,CAAC;YAC9B,gEAAgE;YAChE,iDAAiD;QACnD,CAAC;KACF,CAAC;AACJ,CAAC"}
|
package/build/index.d.ts
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
export * from './telemetry';
|
|
2
|
-
export * from './express-app';
|
|
3
|
-
export * from './types';
|
|
4
|
-
export * from './env';
|
|
5
|
-
export * from './config';
|
|
6
|
-
export * from './error';
|
|
7
|
-
export * from './bootstrap';
|
|
8
|
-
export * from './hook';
|
|
9
|
-
export { repl$ } from './development/repl';
|
|
1
|
+
export * from './telemetry/index.js';
|
|
2
|
+
export * from './express-app/index.js';
|
|
3
|
+
export * from './types.js';
|
|
4
|
+
export * from './env.js';
|
|
5
|
+
export * from './config/index.js';
|
|
6
|
+
export * from './error.js';
|
|
7
|
+
export * from './bootstrap.js';
|
|
8
|
+
export * from './hook.js';
|
|
9
|
+
export { repl$ } from './development/repl.js';
|
package/build/index.js
CHANGED
|
@@ -1,28 +1,10 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
-
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
-
};
|
|
16
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
-
exports.repl$ = void 0;
|
|
18
|
-
__exportStar(require("./telemetry"), exports);
|
|
19
|
-
__exportStar(require("./express-app"), exports);
|
|
20
|
-
__exportStar(require("./types"), exports);
|
|
21
|
-
__exportStar(require("./env"), exports);
|
|
22
|
-
__exportStar(require("./config"), exports);
|
|
23
|
-
__exportStar(require("./error"), exports);
|
|
24
|
-
__exportStar(require("./bootstrap"), exports);
|
|
25
|
-
__exportStar(require("./hook"), exports);
|
|
26
|
-
var repl_1 = require("./development/repl");
|
|
27
|
-
Object.defineProperty(exports, "repl$", { enumerable: true, get: function () { return repl_1.repl$; } });
|
|
1
|
+
export * from './telemetry/index.js';
|
|
2
|
+
export * from './express-app/index.js';
|
|
3
|
+
export * from './types.js';
|
|
4
|
+
export * from './env.js';
|
|
5
|
+
export * from './config/index.js';
|
|
6
|
+
export * from './error.js';
|
|
7
|
+
export * from './bootstrap.js';
|
|
8
|
+
export * from './hook.js';
|
|
9
|
+
export { repl$ } from './development/repl.js';
|
|
28
10
|
//# sourceMappingURL=index.js.map
|
package/build/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,sBAAsB,CAAC;AACrC,cAAc,wBAAwB,CAAC;AACvC,cAAc,YAAY,CAAC;AAC3B,cAAc,UAAU,CAAC;AACzB,cAAc,mBAAmB,CAAC;AAClC,cAAc,YAAY,CAAC;AAC3B,cAAc,gBAAgB,CAAC;AAC/B,cAAc,WAAW,CAAC;AAC1B,OAAO,EAAE,KAAK,EAAE,MAAM,uBAAuB,CAAC"}
|
package/build/openapi.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import * as OpenApiValidator from 'express-openapi-validator';
|
|
2
|
-
import type { AnyServiceLocals, ServiceExpress, ServiceLocals } from './types';
|
|
3
|
-
import { ConfigurationSchema } from './config/schema';
|
|
2
|
+
import type { AnyServiceLocals, ServiceExpress, ServiceLocals } from './types.js';
|
|
3
|
+
import { ConfigurationSchema } from './config/schema.js';
|
|
4
4
|
type OAPIOpts = Parameters<typeof OpenApiValidator.middleware>[0];
|
|
5
|
-
export declare function openApi<SLocals extends AnyServiceLocals = ServiceLocals<ConfigurationSchema>>(app: ServiceExpress<SLocals>, rootDirectory: string, codepath: string, pattern: string, openApiOptions?: Partial<OAPIOpts>): Promise<import("express-openapi-validator/dist/framework/types").OpenApiRequestHandler[]>;
|
|
5
|
+
export declare function openApi<SLocals extends AnyServiceLocals = ServiceLocals<ConfigurationSchema>>(app: ServiceExpress<SLocals>, rootDirectory: string, codepath: string, pattern: string, openApiOptions?: Partial<OAPIOpts>): Promise<import("express-openapi-validator/dist/framework/types.js").OpenApiRequestHandler[]>;
|
|
6
6
|
export {};
|
package/build/openapi.js
CHANGED
|
@@ -1,38 +1,9 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
-
}) : function(o, v) {
|
|
16
|
-
o["default"] = v;
|
|
17
|
-
});
|
|
18
|
-
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
-
if (mod && mod.__esModule) return mod;
|
|
20
|
-
var result = {};
|
|
21
|
-
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
-
__setModuleDefault(result, mod);
|
|
23
|
-
return result;
|
|
24
|
-
};
|
|
25
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
26
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
27
|
-
};
|
|
28
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
29
|
-
exports.openApi = openApi;
|
|
30
|
-
const path_1 = __importDefault(require("path"));
|
|
31
|
-
const lodash_1 = __importDefault(require("lodash"));
|
|
32
|
-
const OpenApiValidator = __importStar(require("express-openapi-validator"));
|
|
33
|
-
const index_1 = require("express-openapi-validator/dist/framework/index");
|
|
34
|
-
const env_1 = require("./env");
|
|
35
|
-
const modules_1 = require("./express-app/modules");
|
|
1
|
+
import path from 'path';
|
|
2
|
+
import _ from 'lodash';
|
|
3
|
+
import * as OpenApiValidator from 'express-openapi-validator';
|
|
4
|
+
import { OpenAPIFramework } from 'express-openapi-validator/dist/framework/index.js';
|
|
5
|
+
import { getNodeEnv } from './env.js';
|
|
6
|
+
import { getFilesInDir } from './express-app/modules.js';
|
|
36
7
|
const notImplementedHandler = (req, res) => {
|
|
37
8
|
res.status(501).json({
|
|
38
9
|
code: 'NotImplemented',
|
|
@@ -43,16 +14,16 @@ const notImplementedHandler = (req, res) => {
|
|
|
43
14
|
function stripExtension(filename) {
|
|
44
15
|
return filename.slice(0, filename.lastIndexOf('.'));
|
|
45
16
|
}
|
|
46
|
-
async function openApi(app, rootDirectory, codepath, pattern, openApiOptions) {
|
|
47
|
-
const apiSpec =
|
|
17
|
+
export async function openApi(app, rootDirectory, codepath, pattern, openApiOptions) {
|
|
18
|
+
const apiSpec = path.resolve(rootDirectory, `./api/${app.locals.name}.yaml`);
|
|
48
19
|
app.locals.logger.debug({ apiSpec, codepath }, 'Serving OpenAPI');
|
|
49
|
-
const basePath =
|
|
20
|
+
const basePath = path.resolve(rootDirectory, `${codepath}/handlers`);
|
|
50
21
|
// Because of the weirdness of ESM/CJS interop, and the synchronous nature of
|
|
51
22
|
// the OpenAPI resolver, we need to preload all the modules we might need
|
|
52
|
-
const moduleFiles = await
|
|
23
|
+
const moduleFiles = await getFilesInDir(pattern, path.resolve(rootDirectory, `${codepath}/handlers`));
|
|
53
24
|
const preloadedModules = await Promise.all(moduleFiles.map((file) => {
|
|
54
|
-
const fullPath =
|
|
55
|
-
return (
|
|
25
|
+
const fullPath = path.join(basePath, file);
|
|
26
|
+
return import(fullPath).catch((error) => {
|
|
56
27
|
app.locals.logger.warn({ file: fullPath, message: error.message }, 'Could not load potential API handler');
|
|
57
28
|
return undefined;
|
|
58
29
|
});
|
|
@@ -72,7 +43,7 @@ async function openApi(app, rootDirectory, codepath, pattern, openApiOptions) {
|
|
|
72
43
|
delete global.window;
|
|
73
44
|
}
|
|
74
45
|
try {
|
|
75
|
-
app.locals.openApiSpecification = await new
|
|
46
|
+
app.locals.openApiSpecification = await new OpenAPIFramework({ apiDoc: apiSpec })
|
|
76
47
|
.initialize({ visitApi() { } })
|
|
77
48
|
.then((docs) => docs.apiDoc)
|
|
78
49
|
.catch((error) => {
|
|
@@ -89,7 +60,7 @@ async function openApi(app, rootDirectory, codepath, pattern, openApiOptions) {
|
|
|
89
60
|
basePath,
|
|
90
61
|
resolver(basePath, route) {
|
|
91
62
|
const pathKey = route.openApiRoute.substring(route.basePath.length);
|
|
92
|
-
const modulePath =
|
|
63
|
+
const modulePath = path.join(basePath, pathKey);
|
|
93
64
|
try {
|
|
94
65
|
const module = modulesByPath[pathKey];
|
|
95
66
|
const method = module
|
|
@@ -104,7 +75,7 @@ async function openApi(app, rootDirectory, codepath, pattern, openApiOptions) {
|
|
|
104
75
|
app.locals.logger.error({
|
|
105
76
|
error: error.message,
|
|
106
77
|
pathKey,
|
|
107
|
-
modulePath:
|
|
78
|
+
modulePath: path.relative(rootDirectory, modulePath),
|
|
108
79
|
}, 'Failed to load API method handler');
|
|
109
80
|
return notImplementedHandler;
|
|
110
81
|
}
|
|
@@ -115,7 +86,7 @@ async function openApi(app, rootDirectory, codepath, pattern, openApiOptions) {
|
|
|
115
86
|
const combinedOptions = {
|
|
116
87
|
// In test mode, validate returned swagger responses. This can easily be disabled
|
|
117
88
|
// by setting validateResponses to false in the config.
|
|
118
|
-
...(
|
|
89
|
+
...(getNodeEnv() === 'test'
|
|
119
90
|
? {
|
|
120
91
|
validateResponses: {
|
|
121
92
|
onError(error, body, req) {
|
|
@@ -130,7 +101,7 @@ async function openApi(app, rootDirectory, codepath, pattern, openApiOptions) {
|
|
|
130
101
|
...(typeof routing.openapi === 'object' ? routing.openapi : {}),
|
|
131
102
|
...openApiOptions,
|
|
132
103
|
};
|
|
133
|
-
return OpenApiValidator.middleware(
|
|
104
|
+
return OpenApiValidator.middleware(_.defaultsDeep(defaultOptions, combinedOptions));
|
|
134
105
|
}
|
|
135
106
|
finally {
|
|
136
107
|
if (_window) {
|
package/build/openapi.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"openapi.js","sourceRoot":"","sources":["../src/openapi.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"openapi.js","sourceRoot":"","sources":["../src/openapi.ts"],"names":[],"mappings":"AAAA,OAAO,IAAI,MAAM,MAAM,CAAC;AAExB,OAAO,CAAC,MAAM,QAAQ,CAAC;AACvB,OAAO,KAAK,gBAAgB,MAA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Q,CAAC,aAAa,EAAE,UAAU,CAAC;yBACrD,EACD,mCAAmC,CACpC,CAAC;wBACF,OAAO,qBAAqB,CAAC;oBAC/B,CAAC;gBACH,CAAC;aACF;SACF,CAAC;QAEF,MAAM,EAAE,OAAO,EAAE,GAAG,GAAG,CAAC,MAAM,CAAC,MAAM,CAAC;QACtC,MAAM,eAAe,GAAG;YACtB,iFAAiF;YACjF,uDAAuD;YACvD,GAAG,CAAC,UAAU,EAAE,KAAK,MAAM;gBACzB,CAAC,CAAC;oBACA,iBAAiB,EAAE;wBACjB,OAAO,CAAC,KAAY,EAAE,IAAa,EAAE,GAAY;4BAC/C,OAAO,CAAC,GAAG,CAAC,kCAAkC,EAAE,KAAK,CAAC,CAAC;4BACvD,OAAO,CAAC,GAAG,CAAC,eAAe,EAAE,GAAG,CAAC,WAAW,CAAC,CAAC;4BAC9C,OAAO,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;4BACpB,MAAM,KAAK,CAAC;wBACd,CAAC;qBACF;iBACF;gBACD,CAAC,CAAC,EAAE,CAAC;YACP,GAAG,CAAC,OAAO,OAAO,CAAC,OAAO,KAAK,QAAQ,CAAC,CAAC,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC,CAAC,EAAE,CAAC;YAC/D,GAAG,cAAc;SAClB,CAAC;QAEF,OAAO,gBAAgB,CAAC,UAAU,CAAC,CAAC,CAAC,YAAY,CAAC,cAAc,EAAE,eAAe,CAAC,CAAC,CAAC;IACtF,CAAC;YAAS,CAAC;QACT,IAAI,OAAO,EAAE,CAAC;YACX,MAA8B,CAAC,MAAM,GAAG,OAAO,CAAC;QACnD,CAAC;QAAA,CAAC;IACJ,CAAC;AACH,CAAC"}
|
|
@@ -1,16 +1,12 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
exports.DummySpanExporter = void 0;
|
|
4
|
-
const core_1 = require("@opentelemetry/core");
|
|
5
|
-
class DummySpanExporter {
|
|
1
|
+
import { ExportResultCode } from '@opentelemetry/core';
|
|
2
|
+
export class DummySpanExporter {
|
|
6
3
|
export(spans, resultCallback) {
|
|
7
4
|
setImmediate(() => resultCallback({
|
|
8
|
-
code:
|
|
5
|
+
code: ExportResultCode.SUCCESS,
|
|
9
6
|
}));
|
|
10
7
|
}
|
|
11
8
|
async shutdown() {
|
|
12
9
|
// Nothing to do
|
|
13
10
|
}
|
|
14
11
|
}
|
|
15
|
-
exports.DummySpanExporter = DummySpanExporter;
|
|
16
12
|
//# sourceMappingURL=DummyExporter.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"DummyExporter.js","sourceRoot":"","sources":["../../src/telemetry/DummyExporter.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"DummyExporter.js","sourceRoot":"","sources":["../../src/telemetry/DummyExporter.ts"],"names":[],"mappings":"AAAA,OAAO,EAAgB,gBAAgB,EAAE,MAAM,qBAAqB,CAAC;AAGrE,MAAM,OAAO,iBAAiB;IAC5B,MAAM,CAAC,KAAqB,EAAE,cAAyC;QACrE,YAAY,CAAC,GAAG,EAAE,CAChB,cAAc,CAAC;YACb,IAAI,EAAE,gBAAgB,CAAC,OAAO;SAC/B,CAAC,CACH,CAAC;IACJ,CAAC;IAED,KAAK,CAAC,QAAQ;QACZ,gBAAgB;IAClB,CAAC;CACF"}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { PrometheusExporter } from '@opentelemetry/exporter-prometheus';
|
|
2
|
-
import type { AnyServiceLocals, DelayLoadServiceStartOptions, RequestLocals, ServiceLocals } from '../types';
|
|
3
|
-
import type { ConfigurationSchema } from '../config/schema';
|
|
2
|
+
import type { AnyServiceLocals, DelayLoadServiceStartOptions, RequestLocals, ServiceLocals } from '../types.js';
|
|
3
|
+
import type { ConfigurationSchema } from '../config/schema.js';
|
|
4
4
|
/**
|
|
5
5
|
* OpenTelemetry is not friendly to the idea of stopping
|
|
6
6
|
* and starting itself, it seems. So we can only keep a global
|
|
@@ -13,7 +13,7 @@ export declare function startGlobalTelemetry(serviceName: string): Promise<void>
|
|
|
13
13
|
export declare function getGlobalPrometheusExporter(): PrometheusExporter | undefined;
|
|
14
14
|
export declare function shutdownGlobalTelemetry(): Promise<void>;
|
|
15
15
|
export declare function startWithTelemetry<SLocals extends AnyServiceLocals = ServiceLocals<ConfigurationSchema>, RLocals extends RequestLocals = RequestLocals>(options: DelayLoadServiceStartOptions): Promise<{
|
|
16
|
-
app: import("../types").ServiceExpress<SLocals>;
|
|
16
|
+
app: import("../types.js").ServiceExpress<SLocals>;
|
|
17
17
|
codepath: "build" | "src" | "dist" | undefined;
|
|
18
18
|
server: import("http").Server<typeof import("http").IncomingMessage, typeof import("http").ServerResponse> | import("https").Server<typeof import("http").IncomingMessage, typeof import("http").ServerResponse>;
|
|
19
19
|
}>;
|
package/build/telemetry/index.js
CHANGED
|
@@ -1,54 +1,25 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
-
}) : function(o, v) {
|
|
16
|
-
o["default"] = v;
|
|
17
|
-
});
|
|
18
|
-
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
-
if (mod && mod.__esModule) return mod;
|
|
20
|
-
var result = {};
|
|
21
|
-
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
-
__setModuleDefault(result, mod);
|
|
23
|
-
return result;
|
|
24
|
-
};
|
|
25
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
|
-
exports.startGlobalTelemetry = startGlobalTelemetry;
|
|
27
|
-
exports.getGlobalPrometheusExporter = getGlobalPrometheusExporter;
|
|
28
|
-
exports.shutdownGlobalTelemetry = shutdownGlobalTelemetry;
|
|
29
|
-
exports.startWithTelemetry = startWithTelemetry;
|
|
30
|
-
const exporter_trace_otlp_proto_1 = require("@opentelemetry/exporter-trace-otlp-proto");
|
|
31
|
-
const resources_1 = require("@opentelemetry/resources");
|
|
32
|
-
const resource_detector_container_1 = require("@opentelemetry/resource-detector-container");
|
|
33
|
-
const resource_detector_gcp_1 = require("@opentelemetry/resource-detector-gcp");
|
|
34
|
-
const opentelemetry = __importStar(require("@opentelemetry/sdk-node"));
|
|
35
|
-
const exporter_prometheus_1 = require("@opentelemetry/exporter-prometheus");
|
|
36
|
-
const instrumentations_1 = require("./instrumentations");
|
|
37
|
-
const DummyExporter_1 = require("./DummyExporter");
|
|
1
|
+
import { OTLPTraceExporter } from '@opentelemetry/exporter-trace-otlp-proto';
|
|
2
|
+
import { envDetectorSync, hostDetectorSync, osDetectorSync, processDetectorSync, } from '@opentelemetry/resources';
|
|
3
|
+
import { containerDetector } from '@opentelemetry/resource-detector-container';
|
|
4
|
+
import { gcpDetector } from '@opentelemetry/resource-detector-gcp';
|
|
5
|
+
import * as opentelemetry from '@opentelemetry/sdk-node';
|
|
6
|
+
import { PrometheusExporter } from '@opentelemetry/exporter-prometheus';
|
|
7
|
+
import { getAutoInstrumentations } from './instrumentations.js';
|
|
8
|
+
import { DummySpanExporter } from './DummyExporter.js';
|
|
38
9
|
// For troubleshooting, set the log level to DiagLogLevel.DEBUG
|
|
39
10
|
opentelemetry.api.diag.setLogger(new (opentelemetry.api.DiagConsoleLogger)(), opentelemetry.api.DiagLogLevel.INFO);
|
|
40
11
|
function getExporter() {
|
|
41
12
|
if (!process.env.DISABLE_OLTP_EXPORTER &&
|
|
42
13
|
(['production', 'staging'].includes(process.env.APP_ENV || process.env.NODE_ENV || '') ||
|
|
43
14
|
process.env.OTLP_EXPORTER)) {
|
|
44
|
-
return new
|
|
15
|
+
return new OTLPTraceExporter({
|
|
45
16
|
url: process.env.OTLP_EXPORTER || 'http://otlp-exporter:4318/v1/traces',
|
|
46
17
|
});
|
|
47
18
|
}
|
|
48
19
|
if (process.env.ENABLE_CONSOLE_OLTP_EXPORTER) {
|
|
49
20
|
return new opentelemetry.tracing.ConsoleSpanExporter();
|
|
50
21
|
}
|
|
51
|
-
return new
|
|
22
|
+
return new DummySpanExporter();
|
|
52
23
|
}
|
|
53
24
|
let prometheusExporter;
|
|
54
25
|
let telemetrySdk;
|
|
@@ -60,21 +31,21 @@ let telemetrySdk;
|
|
|
60
31
|
* In addition, since we have to load it right away before configuration
|
|
61
32
|
* is available, we can't use configuration to decide anything.
|
|
62
33
|
*/
|
|
63
|
-
async function startGlobalTelemetry(serviceName) {
|
|
34
|
+
export async function startGlobalTelemetry(serviceName) {
|
|
64
35
|
if (!prometheusExporter) {
|
|
65
|
-
prometheusExporter = new
|
|
66
|
-
const instrumentations =
|
|
36
|
+
prometheusExporter = new PrometheusExporter({ preventServerStart: true });
|
|
37
|
+
const instrumentations = getAutoInstrumentations();
|
|
67
38
|
telemetrySdk = new opentelemetry.NodeSDK({
|
|
68
39
|
serviceName,
|
|
69
40
|
autoDetectResources: false,
|
|
70
41
|
traceExporter: getExporter(),
|
|
71
42
|
resourceDetectors: [
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
43
|
+
envDetectorSync,
|
|
44
|
+
hostDetectorSync,
|
|
45
|
+
osDetectorSync,
|
|
46
|
+
processDetectorSync,
|
|
47
|
+
containerDetector,
|
|
48
|
+
gcpDetector,
|
|
78
49
|
],
|
|
79
50
|
metricReader: prometheusExporter,
|
|
80
51
|
instrumentations,
|
|
@@ -90,15 +61,15 @@ async function startGlobalTelemetry(serviceName) {
|
|
|
90
61
|
telemetrySdk.start();
|
|
91
62
|
}
|
|
92
63
|
}
|
|
93
|
-
function getGlobalPrometheusExporter() {
|
|
64
|
+
export function getGlobalPrometheusExporter() {
|
|
94
65
|
return prometheusExporter;
|
|
95
66
|
}
|
|
96
|
-
async function shutdownGlobalTelemetry() {
|
|
67
|
+
export async function shutdownGlobalTelemetry() {
|
|
97
68
|
await telemetrySdk?.shutdown();
|
|
98
69
|
telemetrySdk = undefined;
|
|
99
70
|
prometheusExporter = undefined;
|
|
100
71
|
}
|
|
101
|
-
async function startWithTelemetry(options) {
|
|
72
|
+
export async function startWithTelemetry(options) {
|
|
102
73
|
await startGlobalTelemetry(options.name);
|
|
103
74
|
// eslint-disable-next-line import/no-unresolved, @typescript-eslint/no-var-requires
|
|
104
75
|
const { startApp, listen } = require('../express-app/app.js');
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/telemetry/index.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/telemetry/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,MAAM,0CAA0C,CAAC;AAC7E,OAAO,EACL,eAAe,EACf,gBAAgB,EAChB,cAAc,EACd,mBAAmB,GACpB,MAAM,0BAA0B,CAAC;AAClC,OAAO,EAAE,iBAAiB,EAAE,MAAM,4CAA4C,CAAC;AAC/E,OAAO,EAAE,WAAW,EAAE,MAAM,sCAAsC,CAAC;AACnE,OAAO,KAAK,aAAa,MAAM,yBAAyB,CAAC;AACzD,OAAO,EAAE,kBAAkB,EAAE,MAAM,oCAAoC,CAAC;AAYxE,OAAO,EAAE,uBAAuB,EAAE,MAAM,uBAAuB,CAAC;AAChE,OAAO,EAAE,iBAAiB,EAAE,MAAM,oBAAoB,CAAC;AAEvD,+DAA+D;AAC/D,aAAa,CAAC,GAAG,CAAC,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,aAAa,CAAC,GAAG,CAAC,iBAAiB,CAAC,EAAE,EAAE,aAAa,CAAC,GAAG,CAAC,YAAY,CAAC,IAAI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AAC,GAAG,EAAE,KAAK,IAAI,EAAE;QAC1C,MAAM,uBAAuB,EAAE,CAAC;QAChC,GAAG,CAAC,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC,yBAAyB,CAAC,CAAC;IACpD,CAAC,CAAC,CAAC;IACH,OAAO,EAAE,GAAG,EAAE,QAAQ,EAAE,OAAO,CAAC,QAAQ,EAAE,MAAM,EAAE,CAAC;AACrD,CAAC"}
|
|
@@ -1,27 +1,24 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
const instrumentation_net_1 = require("@opentelemetry/instrumentation-net");
|
|
11
|
-
const instrumentation_pg_1 = require("@opentelemetry/instrumentation-pg");
|
|
12
|
-
const instrumentation_pino_1 = require("@opentelemetry/instrumentation-pino");
|
|
1
|
+
import { DnsInstrumentation } from '@opentelemetry/instrumentation-dns';
|
|
2
|
+
import { ExpressInstrumentation } from '@opentelemetry/instrumentation-express';
|
|
3
|
+
import { UndiciInstrumentation } from '@opentelemetry/instrumentation-undici';
|
|
4
|
+
import { GenericPoolInstrumentation } from '@opentelemetry/instrumentation-generic-pool';
|
|
5
|
+
import { HttpInstrumentation } from '@opentelemetry/instrumentation-http';
|
|
6
|
+
import { IORedisInstrumentation } from '@opentelemetry/instrumentation-ioredis';
|
|
7
|
+
import { NetInstrumentation } from '@opentelemetry/instrumentation-net';
|
|
8
|
+
import { PgInstrumentation } from '@opentelemetry/instrumentation-pg';
|
|
9
|
+
import { PinoInstrumentation } from '@opentelemetry/instrumentation-pino';
|
|
13
10
|
const InstrumentationMap = {
|
|
14
|
-
'@opentelemetry/instrumentation-http':
|
|
15
|
-
'@opentelemetry/instrumentation-dns':
|
|
16
|
-
'@opentelemetry/instrumentation-express':
|
|
17
|
-
'@opentelemetry/instrumentation-undici':
|
|
18
|
-
'@opentelemetry/instrumentation-generic-pool':
|
|
19
|
-
'@opentelemetry/instrumentation-ioredis':
|
|
20
|
-
'@opentelemetry/instrumentation-net':
|
|
21
|
-
'@opentelemetry/instrumentation-pg':
|
|
22
|
-
'@opentelemetry/instrumentation-pino':
|
|
11
|
+
'@opentelemetry/instrumentation-http': HttpInstrumentation,
|
|
12
|
+
'@opentelemetry/instrumentation-dns': DnsInstrumentation,
|
|
13
|
+
'@opentelemetry/instrumentation-express': ExpressInstrumentation,
|
|
14
|
+
'@opentelemetry/instrumentation-undici': UndiciInstrumentation,
|
|
15
|
+
'@opentelemetry/instrumentation-generic-pool': GenericPoolInstrumentation,
|
|
16
|
+
'@opentelemetry/instrumentation-ioredis': IORedisInstrumentation,
|
|
17
|
+
'@opentelemetry/instrumentation-net': NetInstrumentation,
|
|
18
|
+
'@opentelemetry/instrumentation-pg': PgInstrumentation,
|
|
19
|
+
'@opentelemetry/instrumentation-pino': PinoInstrumentation,
|
|
23
20
|
};
|
|
24
|
-
function getAutoInstrumentations(inputConfigs = {}) {
|
|
21
|
+
export function getAutoInstrumentations(inputConfigs = {}) {
|
|
25
22
|
const keys = Object.keys(InstrumentationMap);
|
|
26
23
|
return keys
|
|
27
24
|
.map((name) => {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"instrumentations.js","sourceRoot":"","sources":["../../src/telemetry/instrumentations.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"instrumentations.js","sourceRoot":"","sources":["../../src/telemetry/instrumentations.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,kBAAkB,EAAE,MAAM,oCAAoC,CAAC;AACxE,OAAO,EAAE,sBAAsB,EAAE,MAAM,wCAAwC,CAAC;AAChF,OAAO,EAAE,qBAAqB,EAAE,MAAM,uCAAuC,CAAC;AAC9E,OAAO,EAAE,0BAA0B,EAAE,MAAM,6CAA6C,CAAC;AACzF,OAAO,EAAE,mBAAmB,EAAE,MAAM,qCAAqC,CAAC;AAC1E,OAAO,EAAE,sBAAsB,EAAE,MAAM,wCAA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ry/api';
|
|
3
|
-
import type { AnyServiceLocals, ServiceExpress, ServiceLocals } from '../types';
|
|
4
|
-
import { ConfigurationSchema } from '../config/schema';
|
|
3
|
+
import type { AnyServiceLocals, ServiceExpress, ServiceLocals } from '../types.js';
|
|
4
|
+
import { ConfigurationSchema } from '../config/schema.js';
|
|
5
5
|
export declare function loggerMiddleware<SLocals extends AnyServiceLocals = ServiceLocals<ConfigurationSchema>>(app: ServiceExpress<SLocals>, histogram: Histogram, config?: ConfigurationSchema['logging']): RequestHandler;
|
|
6
6
|
export declare function errorHandlerMiddleware<SLocals extends AnyServiceLocals = ServiceLocals<ConfigurationSchema>>(app: ServiceExpress<SLocals>, histogram: Histogram, unnest?: boolean, returnError?: boolean): ErrorRequestHandler<import("express-serve-static-core").ParamsDictionary, any, any, import("qs").ParsedQs, Record<string, any>>;
|
|
7
7
|
export declare function notFoundMiddleware(): RequestHandler;
|
|
@@ -1,19 +1,11 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
};
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.loggerMiddleware = loggerMiddleware;
|
|
7
|
-
exports.errorHandlerMiddleware = errorHandlerMiddleware;
|
|
8
|
-
exports.notFoundMiddleware = notFoundMiddleware;
|
|
9
|
-
const request_ip_1 = __importDefault(require("request-ip"));
|
|
10
|
-
const error_1 = require("../error");
|
|
11
|
-
const env_1 = require("../env");
|
|
1
|
+
import { getClientIp } from 'request-ip';
|
|
2
|
+
import { ServiceError } from '../error.js';
|
|
3
|
+
import { getNodeEnv } from '../env.js';
|
|
12
4
|
const LOG_PREFS = Symbol('Logging information');
|
|
13
5
|
function getBasicInfo(req) {
|
|
14
6
|
const url = req.originalUrl || req.url;
|
|
15
7
|
const preInfo = {
|
|
16
|
-
ip:
|
|
8
|
+
ip: getClientIp(req) || '',
|
|
17
9
|
m: req.method,
|
|
18
10
|
};
|
|
19
11
|
if (req.headers['user-agent']) {
|
|
@@ -54,7 +46,7 @@ function finishLog(app, error, req, res, histogram) {
|
|
|
54
46
|
let unexpectedError = false;
|
|
55
47
|
if (error) {
|
|
56
48
|
endLog.e = error.message;
|
|
57
|
-
if (!(error instanceof
|
|
49
|
+
if (!(error instanceof ServiceError) || error.log_stack) {
|
|
58
50
|
endLog.st = error.stack;
|
|
59
51
|
}
|
|
60
52
|
if (!error.expected_error) {
|
|
@@ -87,8 +79,8 @@ function finishLog(app, error, req, res, histogram) {
|
|
|
87
79
|
logger.info(endLog, msg);
|
|
88
80
|
}
|
|
89
81
|
}
|
|
90
|
-
function loggerMiddleware(app, histogram, config) {
|
|
91
|
-
const nonProd =
|
|
82
|
+
export function loggerMiddleware(app, histogram, config) {
|
|
83
|
+
const nonProd = getNodeEnv() !== 'production';
|
|
92
84
|
const { logger, service } = app.locals;
|
|
93
85
|
return function serviceLogger(req, res, next) {
|
|
94
86
|
const logResponse = config?.logResponseBody || (nonProd && req.headers['x-log']?.includes('res'));
|
|
@@ -135,7 +127,7 @@ function loggerMiddleware(app, histogram, config) {
|
|
|
135
127
|
next();
|
|
136
128
|
};
|
|
137
129
|
}
|
|
138
|
-
function errorHandlerMiddleware(app, histogram, unnest, returnError) {
|
|
130
|
+
export function errorHandlerMiddleware(app, histogram, unnest, returnError) {
|
|
139
131
|
const svcErrorHandler = (error, req, res, next) => {
|
|
140
132
|
let loggable = error;
|
|
141
133
|
const body = error.response?.body || error.body;
|
|
@@ -169,9 +161,9 @@ function errorHandlerMiddleware(app, histogram, unnest, returnError) {
|
|
|
169
161
|
};
|
|
170
162
|
return svcErrorHandler;
|
|
171
163
|
}
|
|
172
|
-
function notFoundMiddleware() {
|
|
164
|
+
export function notFoundMiddleware() {
|
|
173
165
|
const serviceNotFoundHandler = (req, res, next) => {
|
|
174
|
-
const error = new
|
|
166
|
+
const error = new ServiceError(req.app, `Cannot ${req.method} ${req.path}`, {
|
|
175
167
|
status: 404,
|
|
176
168
|
code: 'NotFound',
|
|
177
169
|
domain: 'http',
|