@fluojs/metrics 1.0.1 → 1.0.3

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.ko.md CHANGED
@@ -42,6 +42,16 @@ class AppModule {}
42
42
 
43
43
  Scrape endpoint는 active `prom-client` Registry output을 해당 Registry의 Prometheus content type으로 반환합니다. `MetricsModule.forRoot()`는 `registry` option을 전달하지 않는 한 격리된 Registry를 생성합니다. framework metric과 application-defined metric이 하나의 scrape surface를 의도적으로 공유해야 할 때만 shared `Registry`를 전달하세요.
44
44
 
45
+ ## 공개 책임
46
+
47
+ | 표면 | 책임 | 경계 |
48
+ | --- | --- | --- |
49
+ | `MetricsModule.forRoot(...)` | Prometheus scrape endpoint, default metrics, optional HTTP instrumentation, platform telemetry, registry ownership을 wiring합니다. | `provider`는 현재 `'prometheus'`만 받습니다. `path: false`는 scrape route와 route-scoped endpoint middleware를 비활성화합니다. |
50
+ | `MetricsService` | Active Registry 위에서 custom `Counter`, `Gauge`, `Histogram`을 만들기 위한 application-facing facade입니다. | 비즈니스/application metric은 package internals 대신 이 서비스를 사용하세요. |
51
+ | `METER_PROVIDER` / `PrometheusMeterProvider` | Provider token이 필요한 first-party package integration용 low-level meter bridge입니다. | Application code는 package-level integration을 직접 조합하는 경우가 아니면 보통 이 token이 필요하지 않습니다. |
52
+ | `middleware` | Framework HTTP metrics와 endpoint-scoped middleware 뒤의 module middleware chain에 참여하는 module-level middleware입니다. | Route-scoped가 아니므로 scrape route만 보호하려면 `endpointMiddleware`를 사용하세요. |
53
+ | `endpointMiddleware` | 설정된 scrape endpoint에만 바인딩되는 class-based `@fluojs/http` middleware constructor입니다. | `path: false`일 때는 무시됩니다. 함수나 global middleware declaration은 이 option의 계약 밖입니다. |
54
+
45
55
  ## 공통 패턴
46
56
 
47
57
  ### HTTP path label 정규화
@@ -91,7 +101,7 @@ MetricsModule.forRoot({
91
101
  });
92
102
  ```
93
103
 
94
- `endpointMiddleware`는 class-based `@fluojs/http` middleware constructor를 받으며 metrics scrape endpoint에만 바인딩됩니다. middleware function이나 global middleware declaration은 이 option의 패키지 계약이 아닙니다. HTTP 계측이 활성화된 경우 endpoint middleware가 던진 실패도 내장 HTTP request/error collector에 기록됩니다.
104
+ `endpointMiddleware`는 class-based `@fluojs/http` middleware constructor를 받으며 metrics scrape endpoint에만 바인딩됩니다. middleware function이나 global middleware declaration은 이 option의 패키지 계약이 아닙니다. `middleware`는 module-level middleware로 남아 endpoint-scoped middleware 뒤의 module chain에서 실행되고, `endpointMiddleware`는 `path: false`로 scrape route를 비활성화하면 완전히 건너뜁니다. HTTP 계측이 활성화된 경우 endpoint middleware가 던진 실패도 내장 HTTP request/error collector에 기록됩니다.
95
105
 
96
106
  ### Framework metric과 app metric이 하나의 registry를 공유하기
97
107
 
@@ -163,7 +173,7 @@ MetricsModule.forRoot({
163
173
  - `METER_PROVIDER` (Token)
164
174
  - `PrometheusMeterProvider`
165
175
  - `HttpMetricsMiddleware` 및 HTTP path-label 옵션 타입
166
- - `provider`(현재는 `'prometheus'`만 지원) endpoint `middleware`를 포함한 module option
176
+ - `provider`(현재는 `'prometheus'`만 지원), module-level `middleware`, endpoint-scoped `endpointMiddleware`를 포함한 module option
167
177
  - `prom-client`의 `Registry`
168
178
 
169
179
  ### 운영 기본값
package/README.md CHANGED
@@ -42,6 +42,16 @@ class AppModule {}
42
42
 
43
43
  The scrape endpoint returns the active `prom-client` registry output with that registry's Prometheus content type. `MetricsModule.forRoot()` creates an isolated registry unless you pass a `registry` option; pass a shared `Registry` only when framework metrics and application-defined metrics intentionally share one scrape surface.
44
44
 
45
+ ## Public Responsibilities
46
+
47
+ | Surface | Responsibility | Boundary |
48
+ | --- | --- | --- |
49
+ | `MetricsModule.forRoot(...)` | Wires the Prometheus scrape endpoint, default metrics, optional HTTP instrumentation, platform telemetry, and registry ownership. | `provider` currently accepts only `'prometheus'`; `path: false` disables the scrape route and route-scoped endpoint middleware. |
50
+ | `MetricsService` | Application-facing facade for custom `Counter`, `Gauge`, and `Histogram` metrics on the active registry. | Use this for business/application metrics instead of reaching into package internals. |
51
+ | `METER_PROVIDER` / `PrometheusMeterProvider` | Low-level meter bridge for first-party package integrations that need a provider token. | Application code usually does not need this token unless it is composing package-level integrations. |
52
+ | `middleware` | Module-level middleware that participates in the module middleware chain after framework HTTP metrics and endpoint-scoped middleware. | It is not route-scoped; use `endpointMiddleware` when only the scrape route should be protected. |
53
+ | `endpointMiddleware` | Class-based `@fluojs/http` middleware constructors bound only to the configured scrape endpoint. | Ignored when `path: false`; functions or global middleware declarations are outside this option's contract. |
54
+
45
55
  ## Common Patterns
46
56
 
47
57
  ### Normalize HTTP path labels
@@ -91,7 +101,7 @@ MetricsModule.forRoot({
91
101
  });
92
102
  ```
93
103
 
94
- `endpointMiddleware` accepts class-based `@fluojs/http` middleware constructors and binds them only to the metrics scrape endpoint. Middleware functions or global middleware declarations are not the package contract for this option. When HTTP instrumentation is enabled, failures thrown by endpoint middleware are recorded in the built-in HTTP request and error collectors.
104
+ `endpointMiddleware` accepts class-based `@fluojs/http` middleware constructors and binds them only to the metrics scrape endpoint. Middleware functions or global middleware declarations are not the package contract for this option. `middleware` remains module-level middleware and runs as part of the module chain after endpoint-scoped middleware, while `endpointMiddleware` is skipped entirely when `path: false` disables the scrape route. When HTTP instrumentation is enabled, failures thrown by endpoint middleware are recorded in the built-in HTTP request and error collectors.
95
105
 
96
106
  ### Share one registry for framework and app metrics
97
107
 
@@ -163,7 +173,7 @@ MetricsModule.forRoot({
163
173
  - `METER_PROVIDER`
164
174
  - `PrometheusMeterProvider`
165
175
  - `HttpMetricsMiddleware` and HTTP path-label option types
166
- - Module options including `provider` (currently only `'prometheus'`) and endpoint `middleware`
176
+ - Module options including `provider` (currently only `'prometheus'`), module-level `middleware`, and endpoint-scoped `endpointMiddleware`
167
177
  - `Registry` from `prom-client`
168
178
 
169
179
  ### Operational defaults
@@ -4,23 +4,36 @@ import { type Registry } from 'prom-client';
4
4
  import { type HttpMetricsPathLabelMode, type HttpMetricsPathLabelNormalizer } from './http-metrics-middleware.js';
5
5
  /** HTTP-specific metric labeling options exposed by `MetricsModule.forRoot(...)`. */
6
6
  export interface MetricsHttpOptions {
7
+ /** How request paths are converted into Prometheus label values. Defaults to route templates. */
7
8
  pathLabelMode?: HttpMetricsPathLabelMode;
9
+ /** Custom path-label normalizer for bounded application-specific label values. */
8
10
  pathLabelNormalizer?: HttpMetricsPathLabelNormalizer;
11
+ /** Label value used when no normalized path can be derived. */
9
12
  unknownPathLabel?: string;
13
+ /** Explicit opt-in required before raw URL paths may be used as labels. */
10
14
  allowUnsafeRawPathLabelMode?: boolean;
11
15
  }
12
16
  /**
13
17
  * Module options for exposing Prometheus metrics and runtime platform telemetry.
14
18
  */
15
19
  export interface MetricsModuleOptions {
20
+ /** Enables built-in HTTP request collectors when `true` or configured with path-label options. */
16
21
  http?: boolean | MetricsHttpOptions;
22
+ /** Scrape endpoint path. Defaults to `/metrics`; `false` disables the scrape endpoint and endpoint-scoped middleware. */
17
23
  path?: string | false;
24
+ /** Meter provider implementation. Currently only `prometheus` is supported. */
18
25
  provider?: 'prometheus';
26
+ /** Whether Prometheus process and Node.js default collectors are registered once per registry. Defaults to `true`. */
19
27
  defaultMetrics?: boolean;
28
+ /** Module-level middleware applied after framework HTTP metrics and endpoint-scoped middleware. */
20
29
  middleware?: MiddlewareLike[];
30
+ /** Class-based middleware bound only to the configured scrape endpoint. Ignored when `path: false`. */
21
31
  endpointMiddleware?: Array<new (...args: any[]) => Middleware>;
32
+ /** Fixed labels attached to built-in runtime platform telemetry gauges. */
22
33
  platformTelemetry?: {
34
+ /** Deployment environment label value. Defaults to `unknown`. */
23
35
  env?: string;
36
+ /** Instance label value. Defaults to `local`. */
24
37
  instance?: string;
25
38
  };
26
39
  /** External Prometheus registry to share between built-in and custom metrics. */
@@ -1 +1 @@
1
- {"version":3,"file":"metrics-module.d.ts","sourceRoot":"","sources":["../src/metrics-module.ts"],"names":[],"mappings":"AAC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a,aAAa;IACxB,OAAO,CAAC,MAAM,CAAC,oBAAoB,CAA2B;IAE9D;;;;;;;;;;;;;OAaG;IACH,MAAM,CAAC,OAAO,CAAC,OAAO,GAAE,oBAAyB,GAAG,UAAU;CAqE/D"}
package/package.json CHANGED
@@ -8,7 +8,7 @@
8
8
  "monitoring",
9
9
  "observability"
10
10
  ],
11
- "version": "1.0.1",
11
+ "version": "1.0.3",
12
12
  "private": false,
13
13
  "license": "MIT",
14
14
  "repository": {
@@ -36,9 +36,9 @@
36
36
  ],
37
37
  "dependencies": {
38
38
  "prom-client": "^15.1.3",
39
- "@fluojs/di": "^1.0.1",
40
- "@fluojs/http": "^1.0.0",
41
- "@fluojs/runtime": "^1.0.1"
39
+ "@fluojs/di": "^1.0.3",
40
+ "@fluojs/http": "^1.1.0",
41
+ "@fluojs/runtime": "^1.1.1"
42
42
  },
43
43
  "devDependencies": {
44
44
  "@types/node": "^22.0.0",