@mohasinac/instrumentation 1.1.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/dist/index.cjs ADDED
@@ -0,0 +1,37 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+
20
+ // src/index.ts
21
+ var index_exports = {};
22
+ __export(index_exports, {
23
+ createInstrumentation: () => createInstrumentation
24
+ });
25
+ module.exports = __toCommonJS(index_exports);
26
+ function createInstrumentation(config) {
27
+ return {
28
+ register: async () => {
29
+ if (process.env.NEXT_RUNTIME === "edge") return;
30
+ await config.onNodeServer();
31
+ }
32
+ };
33
+ }
34
+ // Annotate the CommonJS export names for ESM import in node:
35
+ 0 && (module.exports = {
36
+ createInstrumentation
37
+ });
@@ -0,0 +1,66 @@
1
+ /**
2
+ * @mohasinac/instrumentation
3
+ *
4
+ * Minimal Next.js instrumentation hook factory.
5
+ *
6
+ * ## What belongs HERE (in Next.js instrumentation)
7
+ *
8
+ * - Provider/DI registration via registerProviders() — this MUST run before
9
+ * any API route handler calls getProviders().
10
+ *
11
+ * ## What belongs in Firebase Functions instead of Next.js instrumentation
12
+ *
13
+ * On Vercel Hobby (free) tier, each serverless function invocation is billed
14
+ * and cold-start time is limited. Heavy observability setup should live in
15
+ * Firebase Functions (free tier: 2 M invocations/month, 400 K GB-seconds):
16
+ *
17
+ * - APM / OpenTelemetry tracing — use a Firebase scheduled function to poll
18
+ * or process trace data asynchronously.
19
+ * - Error alerting / log aggregation — use Firestore triggers or scheduled
20
+ * jobs in functions/src/ (already present in this project).
21
+ * - Health checks / uptime monitoring — Firebase scheduled function pinging
22
+ * an internal pub/sub or writing to Firestore.
23
+ * - Performance budget checks — scheduled Firebase function reading Cloud
24
+ * Run metrics and writing summaries to Firestore.
25
+ *
26
+ * ## Usage (in app root instrumentation.ts)
27
+ *
28
+ * ```ts
29
+ * import { createInstrumentation } from "@mohasinac/instrumentation";
30
+ *
31
+ * const { register } = createInstrumentation({
32
+ * onNodeServer: async () => {
33
+ * await import("./src/providers.config");
34
+ * },
35
+ * });
36
+ *
37
+ * export { register };
38
+ * ```
39
+ */
40
+ interface InstrumentationConfig {
41
+ /**
42
+ * Called ONCE when the Node.js runtime initialises (never on Edge runtime).
43
+ * Use this to register providers and do any one-time server setup that must
44
+ * complete before the first API route handler runs.
45
+ *
46
+ * Keep this function fast (< 50 ms). Any slow I/O, monitoring agents, or
47
+ * APM SDKs should live in Firebase Functions instead.
48
+ */
49
+ onNodeServer: () => Promise<void>;
50
+ }
51
+ interface InstrumentationHook {
52
+ /**
53
+ * The `register` export required by Next.js instrumentation.ts.
54
+ * Next.js calls this exactly once per server process start.
55
+ */
56
+ register: () => Promise<void>;
57
+ }
58
+ /**
59
+ * Creates a Next.js-compatible instrumentation hook.
60
+ *
61
+ * The returned `register` function is a no-op on the Edge runtime and calls
62
+ * `onNodeServer` exactly once on the Node.js runtime.
63
+ */
64
+ declare function createInstrumentation(config: InstrumentationConfig): InstrumentationHook;
65
+
66
+ export { type InstrumentationConfig, type InstrumentationHook, createInstrumentation };
@@ -0,0 +1,66 @@
1
+ /**
2
+ * @mohasinac/instrumentation
3
+ *
4
+ * Minimal Next.js instrumentation hook factory.
5
+ *
6
+ * ## What belongs HERE (in Next.js instrumentation)
7
+ *
8
+ * - Provider/DI registration via registerProviders() — this MUST run before
9
+ * any API route handler calls getProviders().
10
+ *
11
+ * ## What belongs in Firebase Functions instead of Next.js instrumentation
12
+ *
13
+ * On Vercel Hobby (free) tier, each serverless function invocation is billed
14
+ * and cold-start time is limited. Heavy observability setup should live in
15
+ * Firebase Functions (free tier: 2 M invocations/month, 400 K GB-seconds):
16
+ *
17
+ * - APM / OpenTelemetry tracing — use a Firebase scheduled function to poll
18
+ * or process trace data asynchronously.
19
+ * - Error alerting / log aggregation — use Firestore triggers or scheduled
20
+ * jobs in functions/src/ (already present in this project).
21
+ * - Health checks / uptime monitoring — Firebase scheduled function pinging
22
+ * an internal pub/sub or writing to Firestore.
23
+ * - Performance budget checks — scheduled Firebase function reading Cloud
24
+ * Run metrics and writing summaries to Firestore.
25
+ *
26
+ * ## Usage (in app root instrumentation.ts)
27
+ *
28
+ * ```ts
29
+ * import { createInstrumentation } from "@mohasinac/instrumentation";
30
+ *
31
+ * const { register } = createInstrumentation({
32
+ * onNodeServer: async () => {
33
+ * await import("./src/providers.config");
34
+ * },
35
+ * });
36
+ *
37
+ * export { register };
38
+ * ```
39
+ */
40
+ interface InstrumentationConfig {
41
+ /**
42
+ * Called ONCE when the Node.js runtime initialises (never on Edge runtime).
43
+ * Use this to register providers and do any one-time server setup that must
44
+ * complete before the first API route handler runs.
45
+ *
46
+ * Keep this function fast (< 50 ms). Any slow I/O, monitoring agents, or
47
+ * APM SDKs should live in Firebase Functions instead.
48
+ */
49
+ onNodeServer: () => Promise<void>;
50
+ }
51
+ interface InstrumentationHook {
52
+ /**
53
+ * The `register` export required by Next.js instrumentation.ts.
54
+ * Next.js calls this exactly once per server process start.
55
+ */
56
+ register: () => Promise<void>;
57
+ }
58
+ /**
59
+ * Creates a Next.js-compatible instrumentation hook.
60
+ *
61
+ * The returned `register` function is a no-op on the Edge runtime and calls
62
+ * `onNodeServer` exactly once on the Node.js runtime.
63
+ */
64
+ declare function createInstrumentation(config: InstrumentationConfig): InstrumentationHook;
65
+
66
+ export { type InstrumentationConfig, type InstrumentationHook, createInstrumentation };
package/dist/index.js ADDED
@@ -0,0 +1,12 @@
1
+ // src/index.ts
2
+ function createInstrumentation(config) {
3
+ return {
4
+ register: async () => {
5
+ if (process.env.NEXT_RUNTIME === "edge") return;
6
+ await config.onNodeServer();
7
+ }
8
+ };
9
+ }
10
+ export {
11
+ createInstrumentation
12
+ };
package/package.json ADDED
@@ -0,0 +1,35 @@
1
+ {
2
+ "name": "@mohasinac/instrumentation",
3
+ "version": "1.1.0",
4
+ "publishConfig": {
5
+ "access": "public"
6
+ },
7
+ "type": "module",
8
+ "main": "./dist/index.cjs",
9
+ "module": "./dist/index.js",
10
+ "types": "./dist/index.d.ts",
11
+ "exports": {
12
+ ".": {
13
+ "types": "./dist/index.d.ts",
14
+ "import": "./dist/index.js",
15
+ "require": "./dist/index.cjs"
16
+ }
17
+ },
18
+ "files": [
19
+ "dist"
20
+ ],
21
+ "scripts": {
22
+ "build": "tsup src/index.ts --format esm,cjs --dts",
23
+ "dev": "tsup src/index.ts --format esm,cjs --dts --watch",
24
+ "typecheck": "tsc --noEmit",
25
+ "lint": "eslint src"
26
+ },
27
+ "peerDependencies": {
28
+ "next": ">=14"
29
+ },
30
+ "devDependencies": {
31
+ "tsup": "^8.5.0",
32
+ "typescript": "^5.9.3",
33
+ "eslint": "^9.37.0"
34
+ }
35
+ }