@jennifersoft/jennifer5-instrumentation 5.6.5-1

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/package.json ADDED
@@ -0,0 +1,50 @@
1
+ {
2
+ "name": "@jennifersoft/jennifer5-instrumentation",
3
+ "version": "5.6.5-1",
4
+ "description": "Instrumentation hooks for Jennifer APM",
5
+ "main": "dist/index.js",
6
+ "module": "dist/index.mjs",
7
+ "types": "dist/index.d.ts",
8
+ "exports": {
9
+ ".": {
10
+ "types": "./dist/index.d.ts",
11
+ "require": "./dist/index.js",
12
+ "import": "./dist/index.mjs"
13
+ },
14
+ "./auto": {
15
+ "require": "./register.js",
16
+ "import": "./register.mjs"
17
+ },
18
+ "./register.js": "./register.js",
19
+ "./register.mjs": "./register.mjs"
20
+ },
21
+ "scripts": {
22
+ "errorCheck": "tsc --noEmit",
23
+ "build": "tsup",
24
+ "dev": "tsup --watch",
25
+ "clean": "rm -rf dist",
26
+ "test": "bun test"
27
+ },
28
+ "dependencies": {
29
+ "@jennifersoft/jennifer5-agent": "5.6.5-1",
30
+ "import-in-the-middle": "3.0.1",
31
+ "require-in-the-middle": "^8.0.1"
32
+ },
33
+ "engines": {
34
+ "node": ">= 18"
35
+ },
36
+ "license": "Apache-2.0",
37
+ "author": "taylor@jennifersoft.com",
38
+ "publishConfig": {
39
+ "access": "public"
40
+ },
41
+ "files": [
42
+ "dist",
43
+ "register.js",
44
+ "register.mjs",
45
+ "LICENSE",
46
+ "MIT-jshttp-cookie.txt",
47
+ "LICENSE-3rdparty.csv",
48
+ "NOTICE"
49
+ ]
50
+ }
package/register.js ADDED
@@ -0,0 +1,63 @@
1
+ // Jennifer5 Instrumentation Auto-Register (CommonJS)
2
+ // Use with: node --require @jennifersoft/jennifer5-instrumentation/register.js app.js
3
+
4
+ /**
5
+ * Check if the current process is a package manager (npm, yarn, pnpm, bun)
6
+ * to prevent instrumentation from being applied to package managers themselves.
7
+ */
8
+ function isPackageManager() {
9
+ const argv1 = process.argv[1] || "";
10
+ const packageManagers = ["npm", "yarn", "pnpm", "bun"];
11
+
12
+ // Check if process.argv[1] contains package manager names
13
+ return packageManagers.some(
14
+ (pm) =>
15
+ argv1.includes(`${pm}.js`) ||
16
+ argv1.includes(`${pm}-cli.js`) ||
17
+ argv1.endsWith(`/${pm}`) ||
18
+ argv1.endsWith(`\\${pm}`)
19
+ );
20
+ }
21
+
22
+ function applyPm2EnvForJennifer() {
23
+ const raw = process.env.pm2_env;
24
+ if (!raw) return;
25
+ try {
26
+ const parsed = JSON.parse(raw);
27
+ for (const [key, value] of Object.entries(parsed)) {
28
+ if (key.startsWith("JENNIFER") && value !== undefined) {
29
+ process.env[key] = String(value);
30
+ }
31
+ }
32
+ } catch {}
33
+ }
34
+
35
+ function isSupportedPlatformArch() {
36
+ return process.platform === "linux" && process.arch === "x64";
37
+ }
38
+
39
+ const enable = (process.env.JENNIFER_ENABLE ?? "1").toLowerCase();
40
+
41
+ // Skip instrumentation if:
42
+ // - JENNIFER_ENABLE is disabled
43
+ // - Running as a package manager
44
+ // - Unsupported platform/arch
45
+ if (enable !== "0" && enable !== "false" && !isPackageManager() && isSupportedPlatformArch()) {
46
+ const { init, info } = require("@jennifersoft/jennifer5-agent");
47
+ const {
48
+ registerRitmHooks,
49
+ startGcMetricsCollection,
50
+ startHeapMetricsCollection,
51
+ } = require("./dist/index.js");
52
+
53
+ applyPm2EnvForJennifer();
54
+ init();
55
+ // Initialize Jennifer core
56
+ info(`process argv: [${process.argv.join(",")}]`);
57
+ // Register all instrumentation hooks
58
+ registerRitmHooks();
59
+ // Start GC metrics collection (every 1 second)
60
+ startGcMetricsCollection(1000);
61
+ // Start heap metrics collection (every 1 second)
62
+ startHeapMetricsCollection(1000);
63
+ }
package/register.mjs ADDED
@@ -0,0 +1,67 @@
1
+ // Jennifer5 Instrumentation Auto-Register (ES Module)
2
+ // Use with: node --import @jennifersoft/jennifer5-instrumentation/register.mjs app.mjs
3
+ //
4
+ // This uses Node.js module.register() API to register the ESM loader hook
5
+ // Requires Node.js 18.19.0+ or 20.6+
6
+
7
+ import { register } from "node:module";
8
+
9
+ /**
10
+ * Check if the current process is a package manager (npm, yarn, pnpm, bun)
11
+ * to prevent instrumentation from being applied to package managers themselves.
12
+ */
13
+ function isPackageManager() {
14
+ const argv1 = process.argv[1] || "";
15
+ const packageManagers = ["npm", "yarn", "pnpm", "bun"];
16
+
17
+ // Check if process.argv[1] contains package manager names
18
+ return packageManagers.some(
19
+ (pm) =>
20
+ argv1.includes(`${pm}.js`) ||
21
+ argv1.includes(`${pm}-cli.js`) ||
22
+ argv1.endsWith(`/${pm}`) ||
23
+ argv1.endsWith(`\\${pm}`)
24
+ );
25
+ }
26
+
27
+ function applyPm2EnvForJennifer() {
28
+ const raw = process.env.pm2_env;
29
+ if (!raw) return;
30
+ try {
31
+ const parsed = JSON.parse(raw);
32
+ for (const [key, value] of Object.entries(parsed)) {
33
+ if (key.startsWith("JENNIFER") && value !== undefined) {
34
+ process.env[key] = String(value);
35
+ }
36
+ }
37
+ } catch {}
38
+ }
39
+
40
+ function isSupportedPlatformArch() {
41
+ return process.platform === "linux" && process.arch === "x64";
42
+ }
43
+
44
+ const enable = (process.env.JENNIFER_ENABLE ?? "1").toLowerCase();
45
+
46
+ if (enable !== "0" && enable !== "false" && !isPackageManager() && isSupportedPlatformArch()) {
47
+ const { init, info } = await import("@jennifersoft/jennifer5-agent");
48
+ const {
49
+ registerIitmHooks,
50
+ registerRitmHooks,
51
+ startGcMetricsCollection,
52
+ startHeapMetricsCollection,
53
+ } = await import("./dist/index.mjs");
54
+
55
+ register("import-in-the-middle/hook.mjs", import.meta.url);
56
+
57
+ applyPm2EnvForJennifer();
58
+ init();
59
+ info(`process argv: [${process.argv.join(",")}]`);
60
+
61
+ registerIitmHooks();
62
+ registerRitmHooks();
63
+ // Start GC metrics collection (every 1 second)
64
+ startGcMetricsCollection(1000);
65
+ // Start heap metrics collection (every 1 second)
66
+ startHeapMetricsCollection(1000);
67
+ }