@vectorx/functions-framework 0.0.0-beta-20251225064112 → 0.0.0-beta-20251227042256
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/lib/async-context.js +10 -0
- package/lib/index.js +1 -0
- package/lib/logger.js +10 -1
- package/lib/middlewares/middle-apm-injection.js +5 -0
- package/lib/middlewares/middle-common-logger.js +5 -0
- package/lib/request.js +0 -4
- package/lib/utils/apm.js +6 -0
- package/package.json +2 -2
- package/types/async-context.d.ts +1 -0
- package/types/index.d.ts +1 -0
package/lib/async-context.js
CHANGED
|
@@ -12,6 +12,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
12
12
|
exports.newExecutionContext = newExecutionContext;
|
|
13
13
|
exports.getCurrentEventID = getCurrentEventID;
|
|
14
14
|
exports.getCurrentAsyncContext = getCurrentAsyncContext;
|
|
15
|
+
exports.updateApmMeasurementData = updateApmMeasurementData;
|
|
15
16
|
exports.isInFrameworkAsyncContext = isInFrameworkAsyncContext;
|
|
16
17
|
exports.done = done;
|
|
17
18
|
exports.wrapWithAsyncContext = wrapWithAsyncContext;
|
|
@@ -34,6 +35,15 @@ function getCurrentEventID() {
|
|
|
34
35
|
function getCurrentAsyncContext() {
|
|
35
36
|
return asyncLocalStorage.getStore();
|
|
36
37
|
}
|
|
38
|
+
function updateApmMeasurementData(updates) {
|
|
39
|
+
const context = asyncLocalStorage.getStore();
|
|
40
|
+
if (context !== undefined) {
|
|
41
|
+
if (!context.apmMeasurementData) {
|
|
42
|
+
context.apmMeasurementData = {};
|
|
43
|
+
}
|
|
44
|
+
Object.assign(context.apmMeasurementData, updates);
|
|
45
|
+
}
|
|
46
|
+
}
|
|
37
47
|
function isInFrameworkAsyncContext() {
|
|
38
48
|
const context = asyncLocalStorage.getStore();
|
|
39
49
|
return context !== undefined && context.id === CONTEXT_ID;
|
package/lib/index.js
CHANGED
package/lib/logger.js
CHANGED
|
@@ -68,7 +68,16 @@ class FunctionsLogger {
|
|
|
68
68
|
const eventId = (asyncContext === null || asyncContext === void 0 ? void 0 : asyncContext.eventID) || "";
|
|
69
69
|
if (this.apmReporter && (asyncContext === null || asyncContext === void 0 ? void 0 : asyncContext.apmMeasurementData)) {
|
|
70
70
|
const measurementData = Object.assign({}, asyncContext.apmMeasurementData);
|
|
71
|
-
|
|
71
|
+
let kit_event_scene;
|
|
72
|
+
try {
|
|
73
|
+
const parsedMessage = JSON.parse(message);
|
|
74
|
+
if (parsedMessage.scene) {
|
|
75
|
+
kit_event_scene = parsedMessage.scene;
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
catch (_a) {
|
|
79
|
+
}
|
|
80
|
+
this.apmReporter.report(apm_config_1.APM_MEASUREMENT_NAME, Object.assign(Object.assign({}, measurementData), { kit_runtime_event_type: LogType.ACCESS, kit_runtime_event_id: eventId, kit_runtime_event_data: message, kit_event_scene: kit_event_scene, kit_event_extInfo: {} }));
|
|
72
81
|
}
|
|
73
82
|
}
|
|
74
83
|
logUserCodelog() {
|
|
@@ -31,6 +31,11 @@ function apmMiddleware() {
|
|
|
31
31
|
kit_function_framework_version: kitInfo.functionsFrameworkVersion,
|
|
32
32
|
kit_cloud_env: env,
|
|
33
33
|
kit_runtime_event_id: (0, async_context_1.getCurrentEventID)(),
|
|
34
|
+
kit_event_scene: undefined,
|
|
35
|
+
kit_model_name: undefined,
|
|
36
|
+
kit_model_service_url: undefined,
|
|
37
|
+
kit_model_status_code: undefined,
|
|
38
|
+
kit_model_rt: undefined,
|
|
34
39
|
};
|
|
35
40
|
ctx.state.apmMeasurementData = baseMeasurementData;
|
|
36
41
|
yield next();
|
|
@@ -59,6 +59,11 @@ function loggerMiddleware() {
|
|
|
59
59
|
userAgent: ctx.headers["user-agent"],
|
|
60
60
|
};
|
|
61
61
|
logger_1.functionsLogger.logAccesslog(logger_1.LogLevel.INFO, JSON.stringify(accessLog));
|
|
62
|
+
const asyncContext = (0, async_context_1.getCurrentAsyncContext)();
|
|
63
|
+
if (asyncContext === null || asyncContext === void 0 ? void 0 : asyncContext.userCodeLogsFlushTimer) {
|
|
64
|
+
clearTimeout(asyncContext.userCodeLogsFlushTimer);
|
|
65
|
+
asyncContext.userCodeLogsFlushTimer = undefined;
|
|
66
|
+
}
|
|
62
67
|
logger_1.functionsLogger.logUserCodelog();
|
|
63
68
|
process.stdout.write(chalk_1.default.greenBright(`▶️ ${chalk_1.default.gray(`[${new Date().toLocaleString()} - ${eventId.slice(0, -10)}]`)} - ${duration}ms\n`));
|
|
64
69
|
process.stdout.write(chalk_1.default.greenBright(`\n`));
|
package/lib/request.js
CHANGED
|
@@ -112,10 +112,6 @@ class Request {
|
|
|
112
112
|
const requestOptions = Object.assign(Object.assign({ method,
|
|
113
113
|
headers }, (payload !== undefined && { body: payload })), { credentials: withCredentials ? "include" : "same-origin", signal });
|
|
114
114
|
try {
|
|
115
|
-
console.log("===== request =====", {
|
|
116
|
-
realUrl,
|
|
117
|
-
requestOptions,
|
|
118
|
-
});
|
|
119
115
|
const response = yield (0, node_fetch_1.default)(realUrl, requestOptions), result = {
|
|
120
116
|
header: {},
|
|
121
117
|
statusCode: response.status,
|
package/lib/utils/apm.js
CHANGED
|
@@ -108,6 +108,12 @@ class ApmReporter {
|
|
|
108
108
|
const merged = list.map((i) => {
|
|
109
109
|
return Object.assign(Object.assign(Object.assign({}, this.apmContext), i.sequence), { measurement_name: i.measurement_name, measurement_data: Object.assign({}, i.measurement_data) });
|
|
110
110
|
});
|
|
111
|
+
if (typeof global !== "undefined" && global.originalConsole) {
|
|
112
|
+
global.originalConsole.log("==== merged ====", merged);
|
|
113
|
+
}
|
|
114
|
+
else {
|
|
115
|
+
console.log("==== merged ====", merged);
|
|
116
|
+
}
|
|
111
117
|
return (0, node_fetch_1.default)(apm_config_1.defaultConfig.endpoint, {
|
|
112
118
|
method: "post",
|
|
113
119
|
body: JSON.stringify(merged),
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@vectorx/functions-framework",
|
|
3
|
-
"version": "0.0.0-beta-
|
|
3
|
+
"version": "0.0.0-beta-20251227042256",
|
|
4
4
|
"description": "VectorX Functions Framework",
|
|
5
5
|
"main": "lib/index.js",
|
|
6
6
|
"types": "types/index.d.ts",
|
|
@@ -25,7 +25,7 @@
|
|
|
25
25
|
"node": ">=18.0.0"
|
|
26
26
|
},
|
|
27
27
|
"dependencies": {
|
|
28
|
-
"@vectorx/ai-types": "0.0.0-beta-
|
|
28
|
+
"@vectorx/ai-types": "0.0.0-beta-20251227042256",
|
|
29
29
|
"async_hooks": "^1.0.0",
|
|
30
30
|
"chalk": "4",
|
|
31
31
|
"commander": "^12.1.0",
|
package/types/async-context.d.ts
CHANGED
|
@@ -11,6 +11,7 @@ export interface ExecutionContext {
|
|
|
11
11
|
export declare function newExecutionContext(eventId: string, apmData?: Record<string, any>): ExecutionContext;
|
|
12
12
|
export declare function getCurrentEventID(): string;
|
|
13
13
|
export declare function getCurrentAsyncContext(): ExecutionContext | undefined;
|
|
14
|
+
export declare function updateApmMeasurementData(updates: Record<string, any>): void;
|
|
14
15
|
export declare function isInFrameworkAsyncContext(): boolean;
|
|
15
16
|
export declare function done(): Promise<void>;
|
|
16
17
|
export declare function wrapWithAsyncContext<T>(executionContext: ExecutionContext, fn: () => Promise<T>): Promise<T>;
|
package/types/index.d.ts
CHANGED