{"record":{"id":"beb4564582a805da","repo":"nestjs/nest","slug":"cannot-apply-global-interceptors-registration-mus","errorCode":null,"errorMessage":"Cannot apply global interceptors: registration must occur before initialization.","messagePattern":"Cannot apply global interceptors: registration must occur before initialization\\.","errorType":"console","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"packages/microservices/nest-microservice.ts","lineNumber":222,"sourceCode":"    );\n    this.applicationConfig.useGlobalPipes(...pipes);\n    pipes.forEach(item =>\n      this.graphInspector.insertOrphanedEnhancer({\n        subtype: 'pipe',\n        ref: item,\n      }),\n    );\n    return this;\n  }\n\n  /**\n   * Registers global interceptors (will be used for every pattern handler).\n   *\n   * @param {...NestInterceptor} interceptors\n   */\n  public useGlobalInterceptors(...interceptors: NestInterceptor[]): this {\n    if (this.isInitialized) {\n      this.logger.warn(\n        'Cannot apply global interceptors: registration must occur before initialization.',\n      );\n    }\n\n    interceptors = this.applyInstanceDecoratorIfRegistered<NestInterceptor>(\n      ...interceptors,\n    );\n    this.applicationConfig.useGlobalInterceptors(...interceptors);\n    interceptors.forEach(item =>\n      this.graphInspector.insertOrphanedEnhancer({\n        subtype: 'interceptor',\n        ref: item,\n      }),\n    );\n    return this;\n  }\n\n  public useGlobalGuards(...guards: CanActivate[]): this {","sourceCodeStart":204,"sourceCodeEnd":240,"githubUrl":"https://github.com/nestjs/nest/blob/3f8a0ce1832fb30053f55856088371b097bbf7e1/packages/microservices/nest-microservice.ts#L204-L240","documentation":"NestMicroservice.useGlobalInterceptors logs this warning when called after init()/listen() has completed. Interceptor chains for every pattern handler are assembled during initialization, so interceptors registered later are captured in the ApplicationConfig and shown in the internal graph as orphaned enhancers, but they never wrap the existing handlers. The call returns `this` and does not throw — the interceptors are just inert.","triggerScenarios":"Calling app.useGlobalInterceptors(new LoggingInterceptor()) after `await app.listen()` or `await app.init()` on a NestFactory.createMicroservice instance, or configuring the NestMicroservice returned by connectMicroservice() after startAllMicroservices() has initialized it.","commonSituations":"Logging/tracing/metrics interceptors wired up from async bootstrap code (APM agents, OpenTelemetry) that initializes after the service is already serving; interceptors registered in onApplicationBootstrap of a lazily loaded module; hybrid apps where the microservice part is configured later than the HTTP part.","solutions":["Register all global interceptors before `await app.listen()` / `await app.init()`.","If registration timing is uncertain, use @UseInterceptors() on individual pattern handlers instead.","Initialize tracing/APM SDKs before creating the microservice so their interceptors can be passed in bootstrap order.","Treat this warning as a CI failure — it means the interceptor will not run in production."],"exampleFix":"// before\nconst app = await NestFactory.createMicroservice(AppModule, opts);\nawait app.listen();\napp.useGlobalInterceptors(new TracingInterceptor()); // warning: never applied\n\n// after\nconst app = await NestFactory.createMicroservice(AppModule, opts);\napp.useGlobalInterceptors(new TracingInterceptor());\nawait app.listen();","handlingStrategy":"validation","validationCode":"const app = await NestFactory.createMicroservice(AppModule, opts);\nif ((app as any).isInitialized) {\n  throw new Error('Bootstrap order bug: register interceptors before init/listen');\n}\napp.useGlobalInterceptors(new LoggingInterceptor());\nawait app.listen();","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Initialize tracing/APM SDKs before creating the microservice so interceptors can be registered pre-init","Keep a single bootstrap function with a fixed order: create -> register enhancers -> listen","Smoke-test that the interceptor actually fires (assert log/trace output) after startup","Fail CI on this warning string in startup logs"],"tags":["nestjs","microservices","interceptors","lifecycle","bootstrap-order"],"backgroundTag":"global-enhancers-after-initialization","analyzedSha":"3f8a0ce1832fb30053f55856088371b097bbf7e1","analyzedAt":"2026-08-21T19:39:39.867Z","contentChangedAt":"2026-08-21T19:39:39.867Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}