@interfere/nest 0.0.1-canary.3 → 0.0.1-canary.5

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/README.md CHANGED
@@ -1,26 +1,46 @@
1
1
  # @interfere/nest
2
2
 
3
- > **Status: canary.** Pre-1.0 API, expect breaking changes. Pin to a specific `10.0.0-canary.N` in CI.
4
-
5
- NestJS SDK for [Interfere](https://interfere.com). Wraps [`@interfere/node`](../node) with a global exception filter and OTel auto-instrumentation for controllers, guards, pipes, interceptors, and middleware.
3
+ NestJS SDK for [Interfere](https://interfere.com). Auto-captures uncaught exceptions and creates per-request spans for controllers, guards, pipes, interceptors, and middleware.
6
4
 
7
5
  ## Install
8
6
 
9
7
  ```sh
8
+ npm install @interfere/nest
9
+ # or
10
10
  bun add @interfere/nest
11
+ # or
12
+ pnpm add @interfere/nest
11
13
  ```
12
14
 
13
- ## Usage
15
+ ## Setup
16
+
17
+ The SDK uses two subpath imports to avoid loading `@nestjs/*` before instrumentation hooks are registered:
18
+
19
+ - `@interfere/nest/instrument` — SDK init, error capture, span utilities (no `@nestjs/*` imports)
20
+ - `@interfere/nest/module` — `InterfereModule` and `InterfereExceptionFilter` (imports `@nestjs/*`)
21
+
22
+ ### 1. Create `instrument.ts`
23
+
24
+ This file must be imported before any `@nestjs/*` module. It registers OTel instrumentation hooks that patch NestJS internals for automatic span creation.
14
25
 
15
26
  ```ts
16
- // instrument.ts — imported first in main.ts, before any @nestjs/* import
17
- import { init } from "@interfere/nest";
18
- init({ serviceName: "my-api", debug: true });
27
+ // src/instrument.ts
28
+ import { init } from "@interfere/nest/instrument";
29
+
30
+ init({
31
+ serviceName: "my-api",
32
+ debug: true, // logs init status and exporter results to stdout
33
+ });
19
34
  ```
20
35
 
36
+ `init()` is synchronous and works in both ESM and CJS projects.
37
+
38
+ ### 2. Import it first in `main.ts`
39
+
21
40
  ```ts
22
- // main.ts
41
+ // src/main.ts
23
42
  import "./instrument";
43
+
24
44
  import { NestFactory } from "@nestjs/core";
25
45
  import { AppModule } from "./app.module";
26
46
 
@@ -31,10 +51,14 @@ async function bootstrap() {
31
51
  bootstrap();
32
52
  ```
33
53
 
54
+ ### 3. Register the module in `app.module.ts`
55
+
56
+ `InterfereModule.forRoot()` registers a global exception filter that captures 5xx errors and uncaught throws. 4xx responses (client errors) are not reported — they still produce OTel request spans but don't create error events.
57
+
34
58
  ```ts
35
- // app.module.ts
59
+ // src/app.module.ts
36
60
  import { Module } from "@nestjs/common";
37
- import { InterfereModule } from "@interfere/nest";
61
+ import { InterfereModule } from "@interfere/nest/module";
38
62
 
39
63
  @Module({ imports: [InterfereModule.forRoot()] })
40
64
  export class AppModule {}
@@ -42,7 +66,11 @@ export class AppModule {}
42
66
 
43
67
  ## Build & Deploy
44
68
 
45
- Add a `postbuild` script so source maps are uploaded and the release is registered with the collector:
69
+ Install [`@interfere/cli`](../cli) as a dev dependency and add a `postbuild` script so source maps are uploaded and the release is registered with the collector. Without this step, the collector will reject spans from production deployments.
70
+
71
+ ```sh
72
+ npm install -D @interfere/cli
73
+ ```
46
74
 
47
75
  ```json
48
76
  {
@@ -53,11 +81,28 @@ Add a `postbuild` script so source maps are uploaded and the release is register
53
81
  }
54
82
  ```
55
83
 
84
+ The CLI derives the release slug from the same commit SHA the SDK uses at runtime (`INTERFERE_SOURCE_ID`, `GITHUB_SHA`, `VERCEL_GIT_COMMIT_SHA`, or `git rev-parse HEAD`). Both must see the same SHA for the slugs to match. See the [`@interfere/cli` README](../cli) for full options, Docker examples, and CI setup.
85
+
56
86
  ## Environment Variables
57
87
 
58
88
  | Variable | Where | Purpose |
59
89
  |---|---|---|
60
90
  | `INTERFERE_PUBLIC_KEY` | Runtime | Routes spans to your surface (`interfere_pk_*`) |
61
- | `INTERFERE_API_KEY` | CI / Build | Uploads source maps and registers releases (`interfere_ak_*`) |
91
+ | `INTERFERE_API_KEY` | CI / Build | Authenticates source map uploads and release registration (`interfere_ak_*`) |
92
+ | `INTERFERE_SOURCE_ID` | Both | Override the commit SHA used to derive the release slug. Falls back to `GITHUB_SHA`, `VERCEL_GIT_COMMIT_SHA`, or `git rev-parse HEAD`. |
93
+ | `INTERFERE_DEBUG` | Runtime | Set to `1` to enable debug logging without changing code. Equivalent to `debug: true` in `init()`. |
94
+
95
+ ## What gets captured
96
+
97
+ | Signal | When | Subpath |
98
+ |---|---|---|
99
+ | Request spans (middleware, guards, pipes, interceptors) | Every HTTP request | `@interfere/nest/instrument` |
100
+ | Error events (5xx, uncaught throws) | Exceptions that reach the global filter | `@interfere/nest/module` |
101
+ | Manual spans (`withSpan`, `captureError`) | Anywhere in your code | `@interfere/nest/instrument` |
102
+
103
+ ## Compatibility
62
104
 
63
- Full docs at <https://interfere.com/docs>.
105
+ - NestJS 10.x and 11.x
106
+ - Node.js >= 18.19.0
107
+ - Works with Express (default) and Fastify adapters
108
+ - CJS and ESM projects
package/dist/init.cjs CHANGED
@@ -1 +1 @@
1
- Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});let _interfere_node=require("@interfere/node"),_opentelemetry_instrumentation=require("@opentelemetry/instrumentation"),_opentelemetry_instrumentation_nestjs_core=require("@opentelemetry/instrumentation-nestjs-core"),instrumented=!1;function init(options={}){instrumented||=((0,_opentelemetry_instrumentation.registerInstrumentations)({instrumentations:[new _opentelemetry_instrumentation_nestjs_core.NestInstrumentation]}),!0),(0,_interfere_node.init)(options)}exports.init=init;
1
+ Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});const require_nest_instrumentation=require("./nest-instrumentation.cjs");let _interfere_node=require("@interfere/node"),node_module=require("node:module"),_opentelemetry_instrumentation=require("@opentelemetry/instrumentation"),_opentelemetry_instrumentation_nestjs_core=require("@opentelemetry/instrumentation-nestjs-core");const INIT_KEY=`__interfereNestInitialized__`,g=globalThis;function init(options={}){g[INIT_KEY]||(typeof node_module.register==`function`&&(0,node_module.register)(`import-in-the-middle/hook.mjs`,require("url").pathToFileURL(__filename).href),(0,_interfere_node.init)(options),(0,_opentelemetry_instrumentation.registerInstrumentations)({instrumentations:[new _opentelemetry_instrumentation_nestjs_core.NestInstrumentation,new require_nest_instrumentation.InterfereNestInstrumentation]}),g[INIT_KEY]=!0)}exports.init=init;
package/dist/init.d.cts CHANGED
@@ -2,11 +2,18 @@ import { InitOptions, InitOptions as InitOptions$1 } from "@interfere/node";
2
2
 
3
3
  //#region src/init.d.ts
4
4
  /**
5
- * Bootstraps `@interfere/node` and registers
6
- * `@opentelemetry/instrumentation-nestjs-core` for auto-spans across
7
- * controllers, guards, pipes, interceptors, and middleware. Must run
8
- * before `@nestjs/core` is imported — see the README for the
9
- * `instrument.ts` pattern.
5
+ * Bootstraps `@interfere/node` and registers auto-instrumentation for
6
+ * NestJS controllers, guards, pipes, interceptors, and middleware.
7
+ *
8
+ * Uses two complementary instrumentation strategies:
9
+ * - `@opentelemetry/instrumentation-nestjs-core` for NestFactory and
10
+ * router-level spans (when RITM hooks engage)
11
+ * - `InterfereNestInstrumentation` which patches `@Injectable` to wrap
12
+ * middleware, guards, pipes, and interceptors at the decorator level
13
+ * (always works, no RITM dependency for nested paths)
14
+ *
15
+ * Registers ESM loader hooks via `module.register()` so that
16
+ * `@nestjs/common` imports are intercepted for auto-instrumentation.
10
17
  */
11
18
  declare function init(options?: InitOptions$1): void;
12
19
  //#endregion
package/dist/init.d.mts CHANGED
@@ -2,11 +2,18 @@ import { InitOptions, InitOptions as InitOptions$1 } from "@interfere/node";
2
2
 
3
3
  //#region src/init.d.ts
4
4
  /**
5
- * Bootstraps `@interfere/node` and registers
6
- * `@opentelemetry/instrumentation-nestjs-core` for auto-spans across
7
- * controllers, guards, pipes, interceptors, and middleware. Must run
8
- * before `@nestjs/core` is imported — see the README for the
9
- * `instrument.ts` pattern.
5
+ * Bootstraps `@interfere/node` and registers auto-instrumentation for
6
+ * NestJS controllers, guards, pipes, interceptors, and middleware.
7
+ *
8
+ * Uses two complementary instrumentation strategies:
9
+ * - `@opentelemetry/instrumentation-nestjs-core` for NestFactory and
10
+ * router-level spans (when RITM hooks engage)
11
+ * - `InterfereNestInstrumentation` which patches `@Injectable` to wrap
12
+ * middleware, guards, pipes, and interceptors at the decorator level
13
+ * (always works, no RITM dependency for nested paths)
14
+ *
15
+ * Registers ESM loader hooks via `module.register()` so that
16
+ * `@nestjs/common` imports are intercepted for auto-instrumentation.
10
17
  */
11
18
  declare function init(options?: InitOptions$1): void;
12
19
  //#endregion
package/dist/init.mjs CHANGED
@@ -1,2 +1,2 @@
1
- import{init as init$1}from"@interfere/node";import{registerInstrumentations}from"@opentelemetry/instrumentation";import{NestInstrumentation}from"@opentelemetry/instrumentation-nestjs-core";let instrumented=!1;function init(options={}){instrumented||=(registerInstrumentations({instrumentations:[new NestInstrumentation]}),!0),init$1(options)}export{init};
1
+ import{InterfereNestInstrumentation}from"./nest-instrumentation.mjs";import{register}from"node:module";import{init as init$1}from"@interfere/node";import{registerInstrumentations}from"@opentelemetry/instrumentation";import{NestInstrumentation}from"@opentelemetry/instrumentation-nestjs-core";const INIT_KEY=`__interfereNestInitialized__`,g=globalThis;function init(options={}){g[INIT_KEY]||(typeof register==`function`&&register(`import-in-the-middle/hook.mjs`,import.meta.url),init$1(options),registerInstrumentations({instrumentations:[new NestInstrumentation,new InterfereNestInstrumentation]}),g[INIT_KEY]=!0)}export{init};
2
2
  //# sourceMappingURL=init.mjs.map
@@ -0,0 +1 @@
1
+ Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});const require_init=require("./init.cjs");let _interfere_node=require("@interfere/node");Object.defineProperty(exports,"captureError",{enumerable:!0,get:function(){return _interfere_node.captureError}}),Object.defineProperty(exports,"captureMessage",{enumerable:!0,get:function(){return _interfere_node.captureMessage}}),Object.defineProperty(exports,"close",{enumerable:!0,get:function(){return _interfere_node.close}}),Object.defineProperty(exports,"flush",{enumerable:!0,get:function(){return _interfere_node.flush}}),exports.init=require_init.init,Object.defineProperty(exports,"withSpan",{enumerable:!0,get:function(){return _interfere_node.withSpan}});
@@ -0,0 +1,3 @@
1
+ import { InitOptions, init } from "./init.cjs";
2
+ import { CaptureErrorContext, captureError, captureMessage, close, flush, withSpan } from "@interfere/node";
3
+ export { type CaptureErrorContext, type InitOptions, captureError, captureMessage, close, flush, init, withSpan };
@@ -0,0 +1,3 @@
1
+ import { InitOptions, init } from "./init.mjs";
2
+ import { CaptureErrorContext, captureError, captureMessage, close, flush, withSpan } from "@interfere/node";
3
+ export { type CaptureErrorContext, type InitOptions, captureError, captureMessage, close, flush, init, withSpan };
@@ -0,0 +1 @@
1
+ import{init}from"./init.mjs";import{captureError,captureMessage,close,flush,withSpan}from"@interfere/node";export{captureError,captureMessage,close,flush,init,withSpan};
@@ -0,0 +1 @@
1
+ Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});const require_exception_filter=require("./exception-filter.cjs"),require_module=require("./module.cjs");Object.defineProperty(exports,"InterfereExceptionFilter",{enumerable:!0,get:function(){return require_exception_filter.InterfereExceptionFilter}}),Object.defineProperty(exports,"InterfereModule",{enumerable:!0,get:function(){return require_module.InterfereModule}});
@@ -0,0 +1,3 @@
1
+ import { InterfereExceptionFilter } from "./exception-filter.cjs";
2
+ import { InterfereModule } from "./module.cjs";
3
+ export { InterfereExceptionFilter, InterfereModule };
@@ -0,0 +1,3 @@
1
+ import { InterfereExceptionFilter } from "./exception-filter.mjs";
2
+ import { InterfereModule } from "./module.mjs";
3
+ export { InterfereExceptionFilter, InterfereModule };
@@ -0,0 +1 @@
1
+ import{InterfereExceptionFilter}from"./exception-filter.mjs";import{InterfereModule}from"./module.mjs";export{InterfereExceptionFilter,InterfereModule};
@@ -0,0 +1 @@
1
+ Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});const require_package=require("./package.cjs");let _opentelemetry_instrumentation=require("@opentelemetry/instrumentation"),_opentelemetry_api=require("@opentelemetry/api");const SUPPORTED_VERSIONS=[`>=8.0.0 <12`],COMPONENT=`@nestjs/common`;var InterfereNestInstrumentation=class extends _opentelemetry_instrumentation.InstrumentationBase{constructor(config={}){super(require_package.name,require_package.version,config)}init(){let moduleDef=new _opentelemetry_instrumentation.InstrumentationNodeModuleDefinition(COMPONENT,SUPPORTED_VERSIONS);return moduleDef.files.push(this.getInjectableInstrumentation(SUPPORTED_VERSIONS)),moduleDef}getInjectableInstrumentation(versions){return new _opentelemetry_instrumentation.InstrumentationNodeModuleFile(`@nestjs/common/decorators/core/injectable.decorator.js`,versions,moduleExports=>((0,_opentelemetry_instrumentation.isWrapped)(moduleExports.Injectable)&&this._unwrap(moduleExports,`Injectable`),this._wrap(moduleExports,`Injectable`,original=>this.wrapInjectable(original)),moduleExports),moduleExports=>{this._unwrap(moduleExports,`Injectable`)})}wrapInjectable(original){let tracer=this.tracer;return function(options){return target=>target.__INTERFERE_PATCHED__?original(options)(target):(target.__INTERFERE_PATCHED__=!0,typeof target.prototype.use==`function`&&patchMethod(tracer,target,`use`,`middleware.nestjs`),typeof target.prototype.canActivate==`function`&&patchMethod(tracer,target,`canActivate`,`guard.nestjs`),typeof target.prototype.transform==`function`&&patchMethod(tracer,target,`transform`,`pipe.nestjs`),typeof target.prototype.intercept==`function`&&patchMethod(tracer,target,`intercept`,`interceptor.nestjs`),original(options)(target))}}};function patchMethod(tracer,target,method,op){let original=target.prototype[method];target.prototype[method]=function(...args){let span=tracer.startSpan(`${target.name}.${method}`,{kind:_opentelemetry_api.SpanKind.INTERNAL,attributes:{component:COMPONENT,"nestjs.type":op,"nestjs.callback":method,"nestjs.controller":target.name}}),ctx=_opentelemetry_api.trace.setSpan(_opentelemetry_api.context.active(),span);return _opentelemetry_api.context.with(ctx,()=>{try{let result=original.apply(this,args);return result&&typeof result.then==`function`?result.then(v=>(span.end(),v),err=>{throw span.recordException(err),span.setStatus({code:_opentelemetry_api.SpanStatusCode.ERROR}),span.end(),err}):(span.end(),result)}catch(err){throw span.recordException(err),span.setStatus({code:_opentelemetry_api.SpanStatusCode.ERROR}),span.end(),err}})}}exports.InterfereNestInstrumentation=InterfereNestInstrumentation;
@@ -0,0 +1,12 @@
1
+ import { InstrumentationBase, InstrumentationConfig, InstrumentationNodeModuleDefinition } from "@opentelemetry/instrumentation";
2
+
3
+ //#region src/nest-instrumentation.d.ts
4
+ declare class InterfereNestInstrumentation extends InstrumentationBase {
5
+ constructor(config?: InstrumentationConfig);
6
+ init(): InstrumentationNodeModuleDefinition;
7
+ private getInjectableInstrumentation;
8
+ private wrapInjectable;
9
+ }
10
+ //#endregion
11
+ export { InterfereNestInstrumentation };
12
+ //# sourceMappingURL=nest-instrumentation.d.cts.map
@@ -0,0 +1,12 @@
1
+ import { InstrumentationBase, InstrumentationConfig, InstrumentationNodeModuleDefinition } from "@opentelemetry/instrumentation";
2
+
3
+ //#region src/nest-instrumentation.d.ts
4
+ declare class InterfereNestInstrumentation extends InstrumentationBase {
5
+ constructor(config?: InstrumentationConfig);
6
+ init(): InstrumentationNodeModuleDefinition;
7
+ private getInjectableInstrumentation;
8
+ private wrapInjectable;
9
+ }
10
+ //#endregion
11
+ export { InterfereNestInstrumentation };
12
+ //# sourceMappingURL=nest-instrumentation.d.mts.map
@@ -0,0 +1,2 @@
1
+ import{name,version}from"./package.mjs";import{InstrumentationBase,InstrumentationNodeModuleDefinition,InstrumentationNodeModuleFile,isWrapped}from"@opentelemetry/instrumentation";import{SpanKind,SpanStatusCode,context,trace}from"@opentelemetry/api";const SUPPORTED_VERSIONS=[`>=8.0.0 <12`],COMPONENT=`@nestjs/common`;var InterfereNestInstrumentation=class extends InstrumentationBase{constructor(config={}){super(name,version,config)}init(){let moduleDef=new InstrumentationNodeModuleDefinition(COMPONENT,SUPPORTED_VERSIONS);return moduleDef.files.push(this.getInjectableInstrumentation(SUPPORTED_VERSIONS)),moduleDef}getInjectableInstrumentation(versions){return new InstrumentationNodeModuleFile(`@nestjs/common/decorators/core/injectable.decorator.js`,versions,moduleExports=>(isWrapped(moduleExports.Injectable)&&this._unwrap(moduleExports,`Injectable`),this._wrap(moduleExports,`Injectable`,original=>this.wrapInjectable(original)),moduleExports),moduleExports=>{this._unwrap(moduleExports,`Injectable`)})}wrapInjectable(original){let tracer=this.tracer;return function(options){return target=>target.__INTERFERE_PATCHED__?original(options)(target):(target.__INTERFERE_PATCHED__=!0,typeof target.prototype.use==`function`&&patchMethod(tracer,target,`use`,`middleware.nestjs`),typeof target.prototype.canActivate==`function`&&patchMethod(tracer,target,`canActivate`,`guard.nestjs`),typeof target.prototype.transform==`function`&&patchMethod(tracer,target,`transform`,`pipe.nestjs`),typeof target.prototype.intercept==`function`&&patchMethod(tracer,target,`intercept`,`interceptor.nestjs`),original(options)(target))}}};function patchMethod(tracer,target,method,op){let original=target.prototype[method];target.prototype[method]=function(...args){let span=tracer.startSpan(`${target.name}.${method}`,{kind:SpanKind.INTERNAL,attributes:{component:COMPONENT,"nestjs.type":op,"nestjs.callback":method,"nestjs.controller":target.name}}),ctx=trace.setSpan(context.active(),span);return context.with(ctx,()=>{try{let result=original.apply(this,args);return result&&typeof result.then==`function`?result.then(v=>(span.end(),v),err=>{throw span.recordException(err),span.setStatus({code:SpanStatusCode.ERROR}),span.end(),err}):(span.end(),result)}catch(err){throw span.recordException(err),span.setStatus({code:SpanStatusCode.ERROR}),span.end(),err}})}}export{InterfereNestInstrumentation};
2
+ //# sourceMappingURL=nest-instrumentation.mjs.map
@@ -0,0 +1 @@
1
+ var name=`@interfere/nest`,version=`0.0.1-canary.5`;Object.defineProperty(exports,"name",{enumerable:!0,get:function(){return name}}),Object.defineProperty(exports,"version",{enumerable:!0,get:function(){return version}});
@@ -0,0 +1,2 @@
1
+ var name=`@interfere/nest`,version=`0.0.1-canary.5`;export{name,version};
2
+ //# sourceMappingURL=package.mjs.map
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@interfere/nest",
3
- "version": "0.0.1-canary.3",
3
+ "version": "0.0.1-canary.5",
4
4
  "license": "MIT",
5
5
  "description": "NestJS SDK for Interfere. Auto-captures uncaught exceptions from controllers, providers, and middleware via a global ExceptionFilter, plus re-exports the @interfere/node OTel instrumentation.",
6
6
  "keywords": [
@@ -43,6 +43,28 @@
43
43
  "types": "./dist/index.d.cts",
44
44
  "default": "./dist/index.cjs"
45
45
  }
46
+ },
47
+ "./instrument": {
48
+ "monorepo": "./src/instrument.ts",
49
+ "import": {
50
+ "types": "./dist/instrument.d.mts",
51
+ "default": "./dist/instrument.mjs"
52
+ },
53
+ "require": {
54
+ "types": "./dist/instrument.d.cts",
55
+ "default": "./dist/instrument.cjs"
56
+ }
57
+ },
58
+ "./module": {
59
+ "monorepo": "./src/module-entry.ts",
60
+ "import": {
61
+ "types": "./dist/module-entry.d.mts",
62
+ "default": "./dist/module-entry.mjs"
63
+ },
64
+ "require": {
65
+ "types": "./dist/module-entry.d.cts",
66
+ "default": "./dist/module-entry.cjs"
67
+ }
46
68
  }
47
69
  },
48
70
  "sideEffects": false,
@@ -55,7 +77,8 @@
55
77
  "typecheck": "tsc --noEmit --incremental"
56
78
  },
57
79
  "dependencies": {
58
- "@interfere/node": "^0.0.1-canary.3",
80
+ "@interfere/node": "^0.0.1-canary.5",
81
+ "@opentelemetry/api": "^1.9.1",
59
82
  "@opentelemetry/instrumentation": "^0.218.0",
60
83
  "@opentelemetry/instrumentation-nestjs-core": "^0.64.0"
61
84
  },