@openclaw/diagnostics-prometheus 2026.8.1 → 2026.8.33

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.
Files changed (2) hide show
  1. package/dist/index.js +21 -2
  2. package/package.json +4 -4
package/dist/index.js CHANGED
@@ -2,6 +2,7 @@ import { isInternalDiagnosticEventMetadata, redactSensitiveText } from "./api.js
2
2
  import { definePluginEntry } from "openclaw/plugin-sdk/plugin-entry";
3
3
  import { normalizeDiagnosticLane, normalizeDiagnosticValue } from "openclaw/plugin-sdk/diagnostic-runtime";
4
4
  import { asNonNegativeFiniteNumber } from "openclaw/plugin-sdk/number-runtime";
5
+ import { getPluginRuntimeGatewayRequestScope } from "openclaw/plugin-sdk/plugin-runtime";
5
6
  import { truncateUtf16Safe } from "openclaw/plugin-sdk/text-utility-runtime";
6
7
  //#region extensions/diagnostics-prometheus/src/service.ts
7
8
  const DURATION_BUCKETS_SECONDS = [
@@ -178,7 +179,8 @@ function createPrometheusMetricStore() {
178
179
  };
179
180
  }
180
181
  function safeErrorMessage(err) {
181
- return truncateUtf16Safe(redactSensitiveText(err instanceof Error ? err.message ?? err.name : String(err)).replaceAll("\0", " ").replace(/[\r\n\t\u2028\u2029]/gu, " "), 500);
182
+ const message = err instanceof Error ? err.message ?? err.name : String(err);
183
+ return truncateUtf16Safe(redactSensitiveText(message).replaceAll("\0", " ").replace(/[\r\n\t\u2028\u2029]/gu, " "), 500);
182
184
  }
183
185
  function shouldRecordDiagnosticEvent(metadata) {
184
186
  return metadata.trusted || isInternalDiagnosticEventMetadata(metadata);
@@ -545,11 +547,28 @@ function recordDiagnosticEvent(store, evt, metadata) {
545
547
  case "payload.large":
546
548
  store.counter("openclaw_payload_large_total", "Oversized payload diagnostics by surface and action.", payloadLargeLabels(evt));
547
549
  store.histogram("openclaw_payload_large_bytes", "Oversized payload byte sizes by surface and action.", payloadLargeLabels(evt), asNonNegativeFiniteNumber(evt.bytes), BYTE_BUCKETS);
548
- default:
549
550
  }
550
551
  }
552
+ const METRICS_READ_SCOPE = "operator.read";
553
+ const METRICS_READ_IMPLYING_SCOPES = [
554
+ METRICS_READ_SCOPE,
555
+ "operator.write",
556
+ "operator.admin"
557
+ ];
558
+ function hasMetricsReadScope() {
559
+ const runtimeScopes = getPluginRuntimeGatewayRequestScope()?.client?.connect?.scopes;
560
+ const scopes = Array.isArray(runtimeScopes) ? runtimeScopes : [];
561
+ return METRICS_READ_IMPLYING_SCOPES.some((scope) => scopes.includes(scope));
562
+ }
551
563
  function createMetricsHandler(store) {
552
564
  return (req, res) => {
565
+ if (!hasMetricsReadScope()) {
566
+ res.statusCode = 403;
567
+ res.setHeader("Cache-Control", "no-store");
568
+ res.setHeader("Content-Type", "text/plain; charset=utf-8");
569
+ res.end(`missing scope: ${METRICS_READ_SCOPE}`);
570
+ return true;
571
+ }
553
572
  if (req.method !== "GET" && req.method !== "HEAD") {
554
573
  res.statusCode = 405;
555
574
  res.setHeader("Allow", "GET, HEAD");
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@openclaw/diagnostics-prometheus",
3
- "version": "2026.8.1",
3
+ "version": "2026.8.33",
4
4
  "description": "OpenClaw diagnostics Prometheus exporter for runtime metrics.",
5
5
  "repository": {
6
6
  "type": "git",
@@ -18,10 +18,10 @@
18
18
  "minHostVersion": ">=2026.4.25"
19
19
  },
20
20
  "compat": {
21
- "pluginApi": ">=2026.8.1"
21
+ "pluginApi": ">=2026.8.33"
22
22
  },
23
23
  "build": {
24
- "openclawVersion": "2026.8.1"
24
+ "openclawVersion": "2026.8.33"
25
25
  },
26
26
  "release": {
27
27
  "publishToClawHub": true,
@@ -37,7 +37,7 @@
37
37
  "README.md"
38
38
  ],
39
39
  "peerDependencies": {
40
- "openclaw": ">=2026.8.1"
40
+ "openclaw": ">=2026.8.33"
41
41
  },
42
42
  "peerDependenciesMeta": {
43
43
  "openclaw": {