@fluojs/metrics 1.0.0-beta.4 → 1.0.1

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
@@ -91,7 +91,7 @@ MetricsModule.forRoot({
91
91
  });
92
92
  ```
93
93
 
94
- `endpointMiddleware`는 class-based `@fluojs/http` middleware constructor를 받으며 metrics scrape endpoint에만 바인딩됩니다. middleware function이나 global middleware declaration은 이 option의 패키지 계약이 아닙니다.
94
+ `endpointMiddleware`는 class-based `@fluojs/http` middleware constructor를 받으며 metrics scrape endpoint에만 바인딩됩니다. middleware function이나 global middleware declaration은 이 option의 패키지 계약이 아닙니다. HTTP 계측이 활성화된 경우 endpoint middleware가 던진 실패도 내장 HTTP request/error collector에 기록됩니다.
95
95
 
96
96
  ### Framework metric과 app metric이 하나의 registry를 공유하기
97
97
 
@@ -171,7 +171,7 @@ MetricsModule.forRoot({
171
171
  - `path`의 기본값은 `'/metrics'`이며, `path: false`로 스크레이프 엔드포인트를 완전히 비활성화할 수 있습니다.
172
172
  - scrape response는 active Registry의 Prometheus content type과 Registry contents를 사용합니다.
173
173
  - `defaultMetrics`의 기본값은 `true`이며, `defaultMetrics: false`로 해당 Registry의 Prometheus 기본 프로세스/Node.js collector를 끌 수 있습니다.
174
- - `endpointMiddleware`는 class-based route-scoped middleware를 스크레이프 엔드포인트에만 바인딩합니다.
174
+ - `endpointMiddleware`는 class-based route-scoped middleware를 스크레이프 엔드포인트에만 바인딩합니다. HTTP 계측이 활성화된 경우 endpoint middleware 실패는 내장 HTTP collector에 집계됩니다.
175
175
  - HTTP 메트릭은 `http: true` 또는 `http` 옵션 객체를 전달한 경우에만 설치되며, 설치된 뒤에는 기본적으로 템플릿 기반 경로 라벨 정규화를 사용합니다.
176
176
  - 내장 HTTP collector와 플랫폼 텔레메트리 Gauge는 같은 Registry를 공유하는 모듈 인스턴스 사이에서 framework-owned이고 예상 label schema를 가진 경우에만 재사용되며, 커스텀 애플리케이션 메트릭 이름 충돌은 Prometheus의 중복 이름 실패 동작을 유지합니다.
177
177
  - raw path 라벨은 `allowUnsafeRawPathLabelMode: true`를 명시한 bounded internal route에서만 사용해야 합니다.
package/README.md CHANGED
@@ -91,7 +91,7 @@ MetricsModule.forRoot({
91
91
  });
92
92
  ```
93
93
 
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.
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.
95
95
 
96
96
  ### Share one registry for framework and app metrics
97
97
 
@@ -171,7 +171,7 @@ MetricsModule.forRoot({
171
171
  - `path` defaults to `'/metrics'`, and `path: false` disables the scrape endpoint entirely.
172
172
  - The scrape response uses the active registry's Prometheus content type and registry contents.
173
173
  - `defaultMetrics` defaults to `true`, and `defaultMetrics: false` disables Prometheus default process and Node.js collectors for that registry.
174
- - `endpointMiddleware` binds class-based route-scoped middleware only to the scrape endpoint.
174
+ - `endpointMiddleware` binds class-based route-scoped middleware only to the scrape endpoint; with HTTP instrumentation enabled, endpoint middleware failures are counted by the built-in HTTP collectors.
175
175
  - HTTP metrics are installed only when `http: true` or an `http` options object is provided, and then default to template-normalized path labels.
176
176
  - Built-in HTTP collectors and platform telemetry gauges are reused when module instances share one registry only if they are framework-owned and have the expected label schema; custom application metric name collisions keep Prometheus' duplicate-name failure behavior.
177
177
  - Raw path labels require `allowUnsafeRawPathLabelMode: true` and should stay limited to bounded internal routes.
@@ -125,6 +125,7 @@ function getOrCreateHttpCounter(registry, config) {
125
125
  if (!FRAMEWORK_HTTP_COUNTERS.has(existing)) {
126
126
  throw new Error(`Metric name "${config.name}" is already registered by the application. Built-in HTTP metrics require framework-owned collectors.`);
127
127
  }
128
+ assertHttpMetricLabelSchema(existing, config);
128
129
  return existing;
129
130
  }
130
131
  const counter = createPrometheusCounter(registry, {
@@ -141,6 +142,7 @@ function getOrCreateHttpHistogram(registry, config) {
141
142
  if (!FRAMEWORK_HTTP_HISTOGRAMS.has(existing)) {
142
143
  throw new Error(`Metric name "${config.name}" is already registered by the application. Built-in HTTP metrics require framework-owned collectors.`);
143
144
  }
145
+ assertHttpMetricLabelSchema(existing, config);
144
146
  return existing;
145
147
  }
146
148
  const histogram = createPrometheusHistogram(registry, {
@@ -151,6 +153,13 @@ function getOrCreateHttpHistogram(registry, config) {
151
153
  FRAMEWORK_HTTP_HISTOGRAMS.add(histogram);
152
154
  return histogram;
153
155
  }
156
+ function assertHttpMetricLabelSchema(metric, config) {
157
+ const registeredLabels = (metric.labelNames ?? []).join(',');
158
+ const expectedLabels = config.labelNames.join(',');
159
+ if (registeredLabels !== expectedLabels) {
160
+ throw new Error(`Metric name "${config.name}" is already registered with labels [${registeredLabels}]. Built-in HTTP metrics require labels [${expectedLabels}].`);
161
+ }
162
+ }
154
163
  function normalizePathToTemplate(path, params) {
155
164
  if (!path) {
156
165
  return '/';
@@ -54,7 +54,7 @@ export class MetricsModule {
54
54
  });
55
55
  }
56
56
  const endpointMiddleware = metricsPath ? (options.endpointMiddleware ?? []).map(middlewareClass => forRoutes(middlewareClass, metricsPath)) : [];
57
- const middleware = [...endpointMiddleware, ...(httpOptions ? [new HttpMetricsMiddleware(registry, httpOptions)] : []), ...(options.middleware ?? [])];
57
+ const middleware = [...(httpOptions ? [new HttpMetricsMiddleware(registry, httpOptions)] : []), ...endpointMiddleware, ...(options.middleware ?? [])];
58
58
  const providers = [{
59
59
  provide: MetricsService,
60
60
  useValue: metricsService
package/package.json CHANGED
@@ -8,7 +8,7 @@
8
8
  "monitoring",
9
9
  "observability"
10
10
  ],
11
- "version": "1.0.0-beta.4",
11
+ "version": "1.0.1",
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.0-beta.7",
40
- "@fluojs/http": "^1.0.0-beta.10",
41
- "@fluojs/runtime": "^1.0.0-beta.12"
39
+ "@fluojs/di": "^1.0.1",
40
+ "@fluojs/http": "^1.0.0",
41
+ "@fluojs/runtime": "^1.0.1"
42
42
  },
43
43
  "devDependencies": {
44
44
  "@types/node": "^22.0.0",