@openapi-typescript-infra/service 4.25.0 → 4.27.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/build/bin/start-service.js +2 -2
- package/build/bin/start-service.js.map +1 -1
- package/build/bootstrap.d.ts +5 -0
- package/build/bootstrap.js +1 -1
- package/build/bootstrap.js.map +1 -1
- package/build/development/repl.d.ts +6 -1
- package/build/development/repl.js +51 -1
- package/build/development/repl.js.map +1 -1
- package/build/index.d.ts +1 -0
- package/build/index.js +3 -0
- package/build/index.js.map +1 -1
- package/build/telemetry/index.d.ts +1 -0
- package/build/telemetry/index.js +13 -2
- package/build/telemetry/index.js.map +1 -1
- package/build/telemetry/instrumentations.d.ts +0 -2
- package/build/telemetry/instrumentations.js +0 -21
- package/build/telemetry/instrumentations.js.map +1 -1
- package/build/tsconfig.build.tsbuildinfo +1 -1
- package/package.json +31 -31
- package/src/bin/start-service.ts +2 -2
- package/src/bootstrap.ts +1 -1
- package/src/development/repl.ts +66 -1
- package/src/index.ts +1 -0
- package/src/telemetry/index.ts +19 -3
- package/src/telemetry/instrumentations.ts +0 -31
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@openapi-typescript-infra/service",
|
|
3
|
-
"version": "4.
|
|
3
|
+
"version": "4.27.0",
|
|
4
4
|
"description": "An opinionated framework for building configuration driven services - web, api, or ob. Uses OpenAPI, pino logging, express, confit, Typescript and vitest.",
|
|
5
5
|
"main": "build/index.js",
|
|
6
6
|
"scripts": {
|
|
@@ -60,64 +60,64 @@
|
|
|
60
60
|
"dependencies": {
|
|
61
61
|
"@godaddy/terminus": "^4.12.1",
|
|
62
62
|
"@opentelemetry/api": "^1.9.0",
|
|
63
|
-
"@opentelemetry/exporter-prometheus": "^0.
|
|
64
|
-
"@opentelemetry/instrumentation-dns": "^0.
|
|
65
|
-
"@opentelemetry/instrumentation-express": "^0.
|
|
66
|
-
"@opentelemetry/instrumentation-generic-pool": "^0.
|
|
67
|
-
"@opentelemetry/instrumentation-graphql": "^0.
|
|
68
|
-
"@opentelemetry/instrumentation-http": "^0.
|
|
69
|
-
"@opentelemetry/instrumentation-ioredis": "^0.
|
|
70
|
-
"@opentelemetry/instrumentation-net": "^0.
|
|
71
|
-
"@opentelemetry/instrumentation-pg": "^0.
|
|
72
|
-
"@opentelemetry/instrumentation-pino": "^0.
|
|
73
|
-
"@opentelemetry/instrumentation-undici": "^0.
|
|
74
|
-
"@opentelemetry/resource-detector-container": "^0.3
|
|
75
|
-
"@opentelemetry/resource-detector-gcp": "^0.29.
|
|
76
|
-
"@opentelemetry/sdk-node": "^0.
|
|
77
|
-
"@opentelemetry/semantic-conventions": "^1.
|
|
63
|
+
"@opentelemetry/exporter-prometheus": "^0.53.0",
|
|
64
|
+
"@opentelemetry/instrumentation-dns": "^0.39.0",
|
|
65
|
+
"@opentelemetry/instrumentation-express": "^0.43.0",
|
|
66
|
+
"@opentelemetry/instrumentation-generic-pool": "^0.39.0",
|
|
67
|
+
"@opentelemetry/instrumentation-graphql": "^0.43.0",
|
|
68
|
+
"@opentelemetry/instrumentation-http": "^0.53.0",
|
|
69
|
+
"@opentelemetry/instrumentation-ioredis": "^0.43.0",
|
|
70
|
+
"@opentelemetry/instrumentation-net": "^0.39.0",
|
|
71
|
+
"@opentelemetry/instrumentation-pg": "^0.45.1",
|
|
72
|
+
"@opentelemetry/instrumentation-pino": "^0.42.0",
|
|
73
|
+
"@opentelemetry/instrumentation-undici": "^0.6.0",
|
|
74
|
+
"@opentelemetry/resource-detector-container": "^0.4.3",
|
|
75
|
+
"@opentelemetry/resource-detector-gcp": "^0.29.12",
|
|
76
|
+
"@opentelemetry/sdk-node": "^0.53.0",
|
|
77
|
+
"@opentelemetry/semantic-conventions": "^1.27.0",
|
|
78
78
|
"@sesamecare-oss/confit": "^2.2.1",
|
|
79
|
-
"@sesamecare-oss/opentelemetry-node-metrics": "^1.0
|
|
79
|
+
"@sesamecare-oss/opentelemetry-node-metrics": "^1.1.0",
|
|
80
80
|
"ajv": "^8.17.1",
|
|
81
|
-
"cookie-parser": "^1.4.
|
|
81
|
+
"cookie-parser": "^1.4.7",
|
|
82
82
|
"dotenv": "^16.4.5",
|
|
83
|
-
"express": "^5.0.
|
|
84
|
-
"express-openapi-validator": "^5.
|
|
83
|
+
"express": "^5.0.1",
|
|
84
|
+
"express-openapi-validator": "^5.3.7",
|
|
85
85
|
"glob": "^8.1.0",
|
|
86
86
|
"lodash": "^4.17.21",
|
|
87
87
|
"minimist": "^1.2.8",
|
|
88
|
-
"pino": "^9.
|
|
88
|
+
"pino": "^9.4.0",
|
|
89
89
|
"read-pkg-up": "^7.0.1",
|
|
90
90
|
"request-ip": "^3.3.0"
|
|
91
91
|
},
|
|
92
92
|
"devDependencies": {
|
|
93
|
-
"@commitlint/cli": "^19.
|
|
94
|
-
"@commitlint/config-conventional": "^19.
|
|
93
|
+
"@commitlint/cli": "^19.5.0",
|
|
94
|
+
"@commitlint/config-conventional": "^19.5.0",
|
|
95
95
|
"@openapi-typescript-infra/coconfig": "^4.4.0",
|
|
96
96
|
"@semantic-release/commit-analyzer": "^13.0.0",
|
|
97
97
|
"@semantic-release/exec": "^6.0.3",
|
|
98
|
-
"@semantic-release/github": "^
|
|
98
|
+
"@semantic-release/github": "^11.0.0",
|
|
99
99
|
"@semantic-release/release-notes-generator": "^14.0.1",
|
|
100
100
|
"@types/cookie-parser": "^1.4.7",
|
|
101
|
-
"@types/express": "^
|
|
101
|
+
"@types/express": "^5.0.0",
|
|
102
102
|
"@types/glob": "^8.1.0",
|
|
103
|
-
"@types/lodash": "^4.17.
|
|
103
|
+
"@types/lodash": "^4.17.10",
|
|
104
104
|
"@types/minimist": "^1.2.5",
|
|
105
|
-
"@types/node": "^20.
|
|
105
|
+
"@types/node": "^20.16.11",
|
|
106
106
|
"@types/request-ip": "^0.0.41",
|
|
107
107
|
"@types/supertest": "^6.0.2",
|
|
108
108
|
"@typescript-eslint/eslint-plugin": "^6.21.0",
|
|
109
109
|
"@typescript-eslint/parser": "^6.21.0",
|
|
110
110
|
"coconfig": "^1.5.2",
|
|
111
|
-
"eslint": "^8.57.
|
|
111
|
+
"eslint": "^8.57.1",
|
|
112
112
|
"eslint-config-prettier": "^9.1.0",
|
|
113
|
-
"eslint-plugin-import": "^2.
|
|
113
|
+
"eslint-plugin-import": "^2.31.0",
|
|
114
114
|
"pino-pretty": "^11.2.2",
|
|
115
115
|
"pinst": "^3.0.0",
|
|
116
116
|
"supertest": "^7.0.0",
|
|
117
117
|
"ts-node": "^10.9.2",
|
|
118
118
|
"tsconfig-paths": "^4.2.0",
|
|
119
|
-
"typescript": "^5.
|
|
120
|
-
"vitest": "^2.
|
|
119
|
+
"typescript": "^5.6.3",
|
|
120
|
+
"vitest": "^2.1.2"
|
|
121
121
|
},
|
|
122
122
|
"resolutions": {
|
|
123
123
|
"qs": "^6.11.0"
|
package/src/bin/start-service.ts
CHANGED
|
@@ -19,9 +19,9 @@ const noTelemetry = (argv.repl || isDev()) && !argv.telemetry;
|
|
|
19
19
|
bootstrap({
|
|
20
20
|
...argv,
|
|
21
21
|
telemetry: !noTelemetry,
|
|
22
|
-
}).then(({ app, server }) => {
|
|
22
|
+
}).then(({ app, codepath, server }) => {
|
|
23
23
|
if (argv.repl) {
|
|
24
|
-
serviceRepl(app, () => {
|
|
24
|
+
serviceRepl(app, codepath, () => {
|
|
25
25
|
server?.close();
|
|
26
26
|
});
|
|
27
27
|
}
|
package/src/bootstrap.ts
CHANGED
|
@@ -129,5 +129,5 @@ export async function bootstrap<
|
|
|
129
129
|
const { startApp, listen } = await import('./express-app/app.js');
|
|
130
130
|
const app = await startApp<SLocals, RLocals>(opts);
|
|
131
131
|
const server = argv?.nobind ? undefined : await listen(app);
|
|
132
|
-
return { server, app };
|
|
132
|
+
return { server, app, codepath };
|
|
133
133
|
}
|
package/src/development/repl.ts
CHANGED
|
@@ -1,11 +1,15 @@
|
|
|
1
|
-
import repl from 'repl';
|
|
1
|
+
import repl, { REPLServer } from 'repl';
|
|
2
|
+
import fs from 'fs';
|
|
2
3
|
import path from 'path';
|
|
3
4
|
|
|
5
|
+
import { glob } from 'glob';
|
|
6
|
+
|
|
4
7
|
import { AnyServiceLocals, ServiceExpress, ServiceLocals } from '../types';
|
|
5
8
|
import { ConfigurationSchema } from '../config/schema';
|
|
6
9
|
|
|
7
10
|
export function serviceRepl<SLocals extends AnyServiceLocals = ServiceLocals<ConfigurationSchema>>(
|
|
8
11
|
app: ServiceExpress<SLocals>,
|
|
12
|
+
codepath: string | undefined,
|
|
9
13
|
onExit: () => void,
|
|
10
14
|
) {
|
|
11
15
|
const rl = repl.start({
|
|
@@ -25,5 +29,66 @@ export function serviceRepl<SLocals extends AnyServiceLocals = ServiceLocals<Con
|
|
|
25
29
|
}
|
|
26
30
|
});
|
|
27
31
|
app.locals.service.attachRepl?.(app, rl);
|
|
32
|
+
|
|
33
|
+
loadReplFunctions(app, codepath, rl);
|
|
34
|
+
|
|
28
35
|
rl.on('exit', onExit);
|
|
29
36
|
}
|
|
37
|
+
|
|
38
|
+
function loadReplFunctions<SLocals extends AnyServiceLocals = ServiceLocals<ConfigurationSchema>>(
|
|
39
|
+
app: ServiceExpress<SLocals>,
|
|
40
|
+
codepath: string | undefined,
|
|
41
|
+
rl: REPLServer,
|
|
42
|
+
) {
|
|
43
|
+
if (!codepath) {
|
|
44
|
+
return;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
const files = glob.sync(path.join(codepath, '**/*.{js,ts}'));
|
|
48
|
+
|
|
49
|
+
files.forEach((file) => {
|
|
50
|
+
try {
|
|
51
|
+
// Read the file content as text
|
|
52
|
+
const fileContent = fs.readFileSync(file, 'utf-8');
|
|
53
|
+
|
|
54
|
+
// Check if @repl is present
|
|
55
|
+
if (/addToRepl\(/.test(fileContent)) {
|
|
56
|
+
// eslint-disable-next-line global-require, import/no-dynamic-require, @typescript-eslint/no-var-requires
|
|
57
|
+
const module = require(file); // Only require if @repl is found
|
|
58
|
+
|
|
59
|
+
// Look for functions with the __isReplFunction marker
|
|
60
|
+
Object.values(module).forEach((exported) => {
|
|
61
|
+
if (!exported) {
|
|
62
|
+
return;
|
|
63
|
+
}
|
|
64
|
+
if (typeof exported === 'function' || typeof exported === 'object') {
|
|
65
|
+
const obj = exported as Record<string, unknown>;
|
|
66
|
+
for (const key of Object.keys(obj)) {
|
|
67
|
+
if ((obj[key] as { __openApiServiceReplFunction?: boolean }).__openApiServiceReplFunction) {
|
|
68
|
+
const fn = obj[key] as (app: ServiceExpress<SLocals>, ...args: unknown[]) => unknown;
|
|
69
|
+
rl.context[key] = (...args: unknown[]) => fn(app, ...args);
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
});
|
|
74
|
+
}
|
|
75
|
+
} catch (err) {
|
|
76
|
+
console.error(`Failed to load REPL functions from ${file}:`, err);
|
|
77
|
+
}
|
|
78
|
+
});
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
/**
|
|
82
|
+
* This decorator-like function can be applied to functions and the service will load and expose
|
|
83
|
+
* the function when the repl is engaged.
|
|
84
|
+
*/
|
|
85
|
+
export function addToRepl<SLocals extends AnyServiceLocals = ServiceLocals<ConfigurationSchema>>(
|
|
86
|
+
fn: (app: ServiceExpress<SLocals>, ...args: unknown[]) => unknown,
|
|
87
|
+
name?: string,
|
|
88
|
+
) {
|
|
89
|
+
const functionName = name || fn.name;
|
|
90
|
+
if (!functionName) {
|
|
91
|
+
throw new Error('Function must have a name or a name must be provided.');
|
|
92
|
+
}
|
|
93
|
+
(fn as unknown as { __openApiServiceReplFunction: string }).__openApiServiceReplFunction = functionName;
|
|
94
|
+
}
|
package/src/index.ts
CHANGED
package/src/telemetry/index.ts
CHANGED
|
@@ -1,4 +1,12 @@
|
|
|
1
1
|
import { OTLPTraceExporter } from '@opentelemetry/exporter-trace-otlp-proto';
|
|
2
|
+
import {
|
|
3
|
+
envDetectorSync,
|
|
4
|
+
hostDetectorSync,
|
|
5
|
+
osDetectorSync,
|
|
6
|
+
processDetectorSync,
|
|
7
|
+
} from '@opentelemetry/resources';
|
|
8
|
+
import { containerDetector } from '@opentelemetry/resource-detector-container';
|
|
9
|
+
import { gcpDetector } from '@opentelemetry/resource-detector-gcp';
|
|
2
10
|
import * as opentelemetry from '@opentelemetry/sdk-node';
|
|
3
11
|
import { PrometheusExporter } from '@opentelemetry/exporter-prometheus';
|
|
4
12
|
|
|
@@ -12,7 +20,7 @@ import type {
|
|
|
12
20
|
import type { ListenFn, StartAppFn } from '../express-app/index';
|
|
13
21
|
import type { ConfigurationSchema } from '../config/schema';
|
|
14
22
|
|
|
15
|
-
import { getAutoInstrumentations
|
|
23
|
+
import { getAutoInstrumentations } from './instrumentations';
|
|
16
24
|
import { DummySpanExporter } from './DummyExporter';
|
|
17
25
|
|
|
18
26
|
// For troubleshooting, set the log level to DiagLogLevel.DEBUG
|
|
@@ -53,9 +61,17 @@ export async function startGlobalTelemetry(serviceName: string) {
|
|
|
53
61
|
serviceName,
|
|
54
62
|
autoDetectResources: false,
|
|
55
63
|
traceExporter: getExporter(),
|
|
56
|
-
|
|
64
|
+
resourceDetectors: [
|
|
65
|
+
envDetectorSync,
|
|
66
|
+
hostDetectorSync,
|
|
67
|
+
osDetectorSync,
|
|
68
|
+
processDetectorSync,
|
|
69
|
+
containerDetector,
|
|
70
|
+
gcpDetector,
|
|
71
|
+
],
|
|
57
72
|
metricReader: prometheusExporter,
|
|
58
73
|
instrumentations,
|
|
74
|
+
logRecordProcessors: [],
|
|
59
75
|
views: [
|
|
60
76
|
new opentelemetry.metrics.View({
|
|
61
77
|
instrumentName: 'http_request_duration_seconds',
|
|
@@ -107,5 +123,5 @@ export async function startWithTelemetry<
|
|
|
107
123
|
await shutdownGlobalTelemetry();
|
|
108
124
|
app.locals.logger.info('OpenTelemetry shut down');
|
|
109
125
|
});
|
|
110
|
-
return { app, server };
|
|
126
|
+
return { app, codepath: options.codepath, server };
|
|
111
127
|
}
|
|
@@ -8,17 +8,6 @@ import { IORedisInstrumentation } from '@opentelemetry/instrumentation-ioredis';
|
|
|
8
8
|
import { NetInstrumentation } from '@opentelemetry/instrumentation-net';
|
|
9
9
|
import { PgInstrumentation } from '@opentelemetry/instrumentation-pg';
|
|
10
10
|
import { PinoInstrumentation } from '@opentelemetry/instrumentation-pino';
|
|
11
|
-
import { containerDetector } from '@opentelemetry/resource-detector-container';
|
|
12
|
-
import { gcpDetector } from '@opentelemetry/resource-detector-gcp';
|
|
13
|
-
import {
|
|
14
|
-
Resource,
|
|
15
|
-
detectResources,
|
|
16
|
-
detectResourcesSync,
|
|
17
|
-
envDetectorSync,
|
|
18
|
-
hostDetectorSync,
|
|
19
|
-
osDetectorSync,
|
|
20
|
-
processDetectorSync,
|
|
21
|
-
} from '@opentelemetry/resources';
|
|
22
11
|
|
|
23
12
|
const InstrumentationMap = {
|
|
24
13
|
'@opentelemetry/instrumentation-http': HttpInstrumentation,
|
|
@@ -58,23 +47,3 @@ export function getAutoInstrumentations(
|
|
|
58
47
|
})
|
|
59
48
|
.filter((i) => !!i) as Instrumentation[];
|
|
60
49
|
}
|
|
61
|
-
|
|
62
|
-
// Async function to get combined resources
|
|
63
|
-
export async function getResource(): Promise<Resource> {
|
|
64
|
-
const syncDetectors = [
|
|
65
|
-
envDetectorSync,
|
|
66
|
-
hostDetectorSync,
|
|
67
|
-
osDetectorSync,
|
|
68
|
-
processDetectorSync,
|
|
69
|
-
];
|
|
70
|
-
const asyncDetectors = [
|
|
71
|
-
containerDetector,
|
|
72
|
-
gcpDetector,
|
|
73
|
-
];
|
|
74
|
-
|
|
75
|
-
const asyncResources = await detectResources({ detectors: asyncDetectors });
|
|
76
|
-
const syncResources = detectResourcesSync({ detectors: syncDetectors });
|
|
77
|
-
|
|
78
|
-
// Combine async and sync resources
|
|
79
|
-
return syncResources.merge(asyncResources);
|
|
80
|
-
}
|