@lensmcp/nest-instrumentation 1.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.
@@ -0,0 +1,25 @@
1
+ /**
2
+ * `@TraceProvider({ memory: true })` — opt a provider into memory
3
+ * container tracking. The provider tracker reads this metadata at
4
+ * bootstrap and, for each tagged provider (or all providers when
5
+ * `memory.scope === 'all'`), scans the instance's own enumerable
6
+ * fields for Map / Set / Array containers and wraps them via
7
+ * `trackContainer`.
8
+ *
9
+ * Implemented without `reflect-metadata` writes beyond a plain
10
+ * property flag so it stays decoupled from Nest's metadata system.
11
+ */
12
+ const TRACE_PROVIDER_FLAG = Symbol.for('@lensmcp/nest-instrumentation/trace-provider');
13
+ export function TraceProvider(options = {}) {
14
+ return (target) => {
15
+ target[TRACE_PROVIDER_FLAG] = {
16
+ memory: options.memory ?? true,
17
+ };
18
+ };
19
+ }
20
+ export function readTraceProvider(ctor) {
21
+ if (!ctor || (typeof ctor !== 'function' && typeof ctor !== 'object')) {
22
+ return undefined;
23
+ }
24
+ return ctor[TRACE_PROVIDER_FLAG];
25
+ }
package/lib/types.d.ts ADDED
@@ -0,0 +1,52 @@
1
+ import type { BaseEvent } from '@lensmcp/protocol-types';
2
+ /**
3
+ * Where to send instrumentation events. Phase 3 ships a synchronous
4
+ * in-process bus (the Nest app runs inside the same process as the
5
+ * lensmcp-mcp server during dev), an IPC client over a Unix socket
6
+ * (cross-process; supervisor wiring lands in 1.5/3.5), and a no-op
7
+ * sink that just collects events in memory for testing.
8
+ */
9
+ export type EventSink = (event: BaseEvent) => void;
10
+ export interface LensmcpModuleOptions {
11
+ /** Project name stamped onto every event (used for resource routing). */
12
+ projectName: string;
13
+ /** Per-request session id; defaults to `process.env.LENSMCP_SESSION_ID` or a fresh one. */
14
+ sessionId?: string;
15
+ /** Override the event sink. Defaults to a sink that posts JSONL to a Unix socket if `LENSMCP_IPC_SOCKET` is set; otherwise to stdout for visibility. */
16
+ emit?: EventSink;
17
+ /** Which trace layers to enable. */
18
+ trace?: {
19
+ requests?: boolean;
20
+ guards?: boolean;
21
+ controllers?: boolean;
22
+ services?: boolean;
23
+ db?: boolean;
24
+ redis?: boolean;
25
+ queues?: boolean;
26
+ /**
27
+ * Auto-wrap every singleton provider's methods with span +
28
+ * db-call-count tracing at bootstrap — no `@TraceMethod` needed.
29
+ * Set by `createLensmcpNestApp`. Methods already decorated with
30
+ * `@TraceMethod` (or marked `@LensmcpIgnore`) are skipped.
31
+ */
32
+ autoInstrumentMethods?: boolean;
33
+ };
34
+ /** Memory tracking (Phase 7). */
35
+ memory?: {
36
+ /** off = no tracking; light = container size + growth; deep = + heap snapshots (7.5). */
37
+ mode?: 'off' | 'light' | 'deep';
38
+ /** tagged = only `@TraceProvider({ memory: true })` providers; all = every provider. */
39
+ scope?: 'tagged' | 'all';
40
+ };
41
+ }
42
+ export interface ResolvedOptions {
43
+ projectName: string;
44
+ sessionId: string;
45
+ emit: EventSink;
46
+ trace: Required<NonNullable<LensmcpModuleOptions['trace']>>;
47
+ memory: {
48
+ mode: 'off' | 'light' | 'deep';
49
+ scope: 'tagged' | 'all';
50
+ };
51
+ }
52
+ //# sourceMappingURL=types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/lib/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,yBAAyB,CAAC;AAEzD;;;;;;GAMG;AACH,MAAM,MAAM,SAAS,GAAG,CAAC,KAAK,EAAE,SAAS,KAAK,IAAI,CAAC;AAEnD,MAAM,WAAW,oBAAoB;IACnC,yEAAyE;IACzE,WAAW,EAAE,MAAM,CAAC;IACpB,2FAA2F;IAC3F,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,wJAAwJ;IACxJ,IAAI,CAAC,EAAE,SAAS,CAAC;IACjB,oCAAoC;IACpC,KAAK,CAAC,EAAE;QACN,QAAQ,CAAC,EAAE,OAAO,CAAC;QACnB,MAAM,CAAC,EAAE,OAAO,CAAC;QACjB,WAAW,CAAC,EAAE,OAAO,CAAC;QACtB,QAAQ,CAAC,EAAE,OAAO,CAAC;QACnB,EAAE,CAAC,EAAE,OAAO,CAAC;QACb,KAAK,CAAC,EAAE,OAAO,CAAC;QAChB,MAAM,CAAC,EAAE,OAAO,CAAC;QACjB;;;;;WAKG;QACH,qBAAqB,CAAC,EAAE,OAAO,CAAC;KACjC,CAAC;IACF,iCAAiC;IACjC,MAAM,CAAC,EAAE;QACP,yFAAyF;QACzF,IAAI,CAAC,EAAE,KAAK,GAAG,OAAO,GAAG,MAAM,CAAC;QAChC,wFAAwF;QACxF,KAAK,CAAC,EAAE,QAAQ,GAAG,KAAK,CAAC;KAC1B,CAAC;CACH;AAED,MAAM,WAAW,eAAe;IAC9B,WAAW,EAAE,MAAM,CAAC;IACpB,SAAS,EAAE,MAAM,CAAC;IAClB,IAAI,EAAE,SAAS,CAAC;IAChB,KAAK,EAAE,QAAQ,CAAC,WAAW,CAAC,oBAAoB,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC;IAC5D,MAAM,EAAE;QACN,IAAI,EAAE,KAAK,GAAG,OAAO,GAAG,MAAM,CAAC;QAC/B,KAAK,EAAE,QAAQ,GAAG,KAAK,CAAC;KACzB,CAAC;CACH"}
package/lib/types.js ADDED
@@ -0,0 +1 @@
1
+ export {};
package/package.json ADDED
@@ -0,0 +1,53 @@
1
+ {
2
+ "name": "@lensmcp/nest-instrumentation",
3
+ "version": "1.0.0",
4
+ "type": "module",
5
+ "main": "./index.js",
6
+ "module": "./index.js",
7
+ "types": "./index.d.ts",
8
+ "exports": {
9
+ "./package.json": "./package.json",
10
+ ".": {
11
+ "types": "./index.d.ts",
12
+ "import": "./index.js",
13
+ "default": "./index.js"
14
+ }
15
+ },
16
+ "dependencies": {
17
+ "@lensmcp/core": "1.0.0",
18
+ "@lensmcp/memory-tracker": "1.0.0",
19
+ "@lensmcp/protocol-types": "1.0.0",
20
+ "tslib": "^2.3.0"
21
+ },
22
+ "peerDependencies": {
23
+ "@nestjs/common": ">=10.0.0 <12.0.0",
24
+ "@nestjs/core": ">=10.0.0 <12.0.0",
25
+ "rxjs": "^7.0.0"
26
+ },
27
+ "license": "Apache-2.0",
28
+ "homepage": "https://github.com/kiwiapps-ltd/lensmcp#readme",
29
+ "bugs": {
30
+ "url": "https://github.com/kiwiapps-ltd/lensmcp/issues"
31
+ },
32
+ "engines": {
33
+ "node": ">=18"
34
+ },
35
+ "publishConfig": {
36
+ "access": "public"
37
+ },
38
+ "description": "Zero-config NestJS instrumentation for LensMCP — createLensmcpNestApp.",
39
+ "keywords": [
40
+ "lensmcp",
41
+ "mcp",
42
+ "observability",
43
+ "ai-agents",
44
+ "claude",
45
+ "nestjs",
46
+ "tracing"
47
+ ],
48
+ "repository": {
49
+ "type": "git",
50
+ "url": "git+https://github.com/kiwiapps-ltd/lensmcp.git",
51
+ "directory": "libs/nest-instrumentation"
52
+ }
53
+ }