Skip to content

The cross-harness, self-improving memory layer for AI agents. Join our community: https://discord.com/invite/zdNChS2fBu

add openclaw filter

Justin D'Souza37d81dc76ba1
diff --git a/cli/beacon/cmd/endpoint.go b/cli/beacon/cmd/endpoint.go
index 17c5fb20..98866d4a 100644
--- a/cli/beacon/cmd/endpoint.go
+++ b/cli/beacon/cmd/endpoint.go
@@ -30,41 +30,42 @@ import (
)
var endpointOpts struct {
- userMode bool
- systemMode bool
- logPath string
- harnesses string
- hookHarnesses string
- outputDir string
- jsonOutput bool
- grpcPort int
- httpPort int
- collectorPath string
- includeRuntimeMetrics bool
- includeCodexSpans bool
- keepLogs bool
- keepConfig bool
- noStart bool
- coworkHeaders string
- coworkEndpoint string
- coworkResourceAttributes string
- coworkNgrok bool
- coworkOpen bool
- coworkSince string
- openClawEndpoint string
- openClawSince string
- elasticPackDir string
- hookLevel string
- contentRetention string
- splunkHECEndpoint string
- splunkHECToken string
- splunkIndex string
- splunkSource string
- splunkSourcetype string
- splunkInsecureSkipVerify bool
- splunkCAFile string
- dashboardAddr string
- dashboardOpen bool
+ userMode bool
+ systemMode bool
+ logPath string
+ harnesses string
+ hookHarnesses string
+ outputDir string
+ jsonOutput bool
+ grpcPort int
+ httpPort int
+ collectorPath string
+ includeRuntimeMetrics bool
+ includeCodexSpans bool
+ includeOpenClawRuntimeMetrics bool
+ keepLogs bool
+ keepConfig bool
+ noStart bool
+ coworkHeaders string
+ coworkEndpoint string
+ coworkResourceAttributes string
+ coworkNgrok bool
+ coworkOpen bool
+ coworkSince string
+ openClawEndpoint string
+ openClawSince string
+ elasticPackDir string
+ hookLevel string
+ contentRetention string
+ splunkHECEndpoint string
+ splunkHECToken string
+ splunkIndex string
+ splunkSource string
+ splunkSourcetype string
+ splunkInsecureSkipVerify bool
+ splunkCAFile string
+ dashboardAddr string
+ dashboardOpen bool
}
var endpointCmd = &cobra.Command{
@@ -439,6 +440,7 @@ func init() {
endpointInstallCmd.Flags().StringVar(&endpointOpts.collectorPath, "collector", "", "Path to a beacon-otelcol binary")
endpointInstallCmd.Flags().BoolVar(&endpointOpts.includeRuntimeMetrics, "include-runtime-metrics", false, "Include generic process/runtime OTLP metrics in the runtime JSONL log")
endpointInstallCmd.Flags().BoolVar(&endpointOpts.includeCodexSpans, "include-codex-spans", false, "Include high-volume Codex OTLP spans for troubleshooting")
+ endpointInstallCmd.Flags().BoolVar(&endpointOpts.includeOpenClawRuntimeMetrics, "include-openclaw-runtime-metrics", false, "Include high-volume OpenClaw operational OTLP metrics in the runtime JSONL log")
endpointInstallCmd.Flags().BoolVar(&endpointOpts.noStart, "no-start", false, "Write files without starting the launchd service")
endpointInstallCmd.Flags().StringVar(&endpointOpts.contentRetention, "content-retention", "full", "Content retention mode: metadata, redacted, or full")
registerSplunkFlags(endpointInstallCmd)
@@ -448,6 +450,7 @@ func init() {
endpointRepairCmd.Flags().StringVar(&endpointOpts.collectorPath, "collector", "", "Path to a beacon-otelcol binary")
endpointRepairCmd.Flags().BoolVar(&endpointOpts.includeRuntimeMetrics, "include-runtime-metrics", false, "Include generic process/runtime OTLP metrics in the runtime JSONL log")
endpointRepairCmd.Flags().BoolVar(&endpointOpts.includeCodexSpans, "include-codex-spans", false, "Include high-volume Codex OTLP spans for troubleshooting")
+ endpointRepairCmd.Flags().BoolVar(&endpointOpts.includeOpenClawRuntimeMetrics, "include-openclaw-runtime-metrics", false, "Include high-volume OpenClaw operational OTLP metrics in the runtime JSONL log")
endpointRepairCmd.Flags().BoolVar(&endpointOpts.noStart, "no-start", false, "Write files without starting the launchd service")
endpointRepairCmd.Flags().StringVar(&endpointOpts.contentRetention, "content-retention", "full", "Content retention mode: metadata, redacted, or full")
registerSplunkFlags(endpointRepairCmd)
@@ -979,17 +982,18 @@ func runEndpointDashboard(cmd *cobra.Command, args []string) error {
func runEndpointInstall(cmd *cobra.Command, args []string) error {
result, err := lifecycle.Install(lifecycle.InstallOptions{
- UserMode: endpointUserMode(),
- LogPath: endpointOpts.logPath,
- Harnesses: splitCSV(endpointOpts.harnesses),
- GRPCPort: endpointOpts.grpcPort,
- HTTPPort: endpointOpts.httpPort,
- CollectorPath: endpointOpts.collectorPath,
- StartService: !endpointOpts.noStart,
- ContentRetention: endpointconfig.ContentRetention(endpointOpts.contentRetention),
- IncludeRuntimeMetrics: endpointOpts.includeRuntimeMetrics,
- IncludeCodexSpans: endpointOpts.includeCodexSpans,
- SplunkHEC: splunkHECOptions(),
+ UserMode: endpointUserMode(),
+ LogPath: endpointOpts.logPath,
+ Harnesses: splitCSV(endpointOpts.harnesses),
+ GRPCPort: endpointOpts.grpcPort,
+ HTTPPort: endpointOpts.httpPort,
+ CollectorPath: endpointOpts.collectorPath,
+ StartService: !endpointOpts.noStart,
+ ContentRetention: endpointconfig.ContentRetention(endpointOpts.contentRetention),
+ IncludeRuntimeMetrics: endpointOpts.includeRuntimeMetrics,
+ IncludeCodexSpans: endpointOpts.includeCodexSpans,
+ IncludeOpenClawRuntimeMetrics: endpointOpts.includeOpenClawRuntimeMetrics,
+ SplunkHEC: splunkHECOptions(),
})
if err != nil {
return err
@@ -1111,17 +1115,18 @@ func runEndpointUninstall(cmd *cobra.Command, args []string) error {
func runEndpointRepair(cmd *cobra.Command, args []string) error {
result, err := lifecycle.Repair(lifecycle.InstallOptions{
- UserMode: endpointUserMode(),
- LogPath: endpointOpts.logPath,
- Harnesses: splitCSV(endpointOpts.harnesses),
- GRPCPort: endpointOpts.grpcPort,
- HTTPPort: endpointOpts.httpPort,
- CollectorPath: endpointOpts.collectorPath,
- StartService: !endpointOpts.noStart,
- ContentRetention: endpointconfig.ContentRetention(endpointOpts.contentRetention),
- IncludeRuntimeMetrics: endpointOpts.includeRuntimeMetrics,
- IncludeCodexSpans: endpointOpts.includeCodexSpans,
- SplunkHEC: splunkHECOptions(),
+ UserMode: endpointUserMode(),
+ LogPath: endpointOpts.logPath,
+ Harnesses: splitCSV(endpointOpts.harnesses),
+ GRPCPort: endpointOpts.grpcPort,
+ HTTPPort: endpointOpts.httpPort,
+ CollectorPath: endpointOpts.collectorPath,
+ StartService: !endpointOpts.noStart,
+ ContentRetention: endpointconfig.ContentRetention(endpointOpts.contentRetention),
+ IncludeRuntimeMetrics: endpointOpts.includeRuntimeMetrics,
+ IncludeCodexSpans: endpointOpts.includeCodexSpans,
+ IncludeOpenClawRuntimeMetrics: endpointOpts.includeOpenClawRuntimeMetrics,
+ SplunkHEC: splunkHECOptions(),
})
if err != nil {
return err
diff --git a/cli/beacon/cmd/endpoint_test.go b/cli/beacon/cmd/endpoint_test.go
index fb2a89cf..6237d175 100644
--- a/cli/beacon/cmd/endpoint_test.go
+++ b/cli/beacon/cmd/endpoint_test.go
@@ -274,6 +274,9 @@ func TestEndpointInstallAndRepairSupportDebugTelemetryFlags(t *testing.T) {
if cmd.Flags().Lookup("include-codex-spans") == nil {
t.Fatalf("%s command missing --include-codex-spans flag", cmd.Use)
}
+ if cmd.Flags().Lookup("include-openclaw-runtime-metrics") == nil {
+ t.Fatalf("%s command missing --include-openclaw-runtime-metrics flag", cmd.Use)
+ }
}
}
diff --git a/cli/beacon/internal/endpoint/collector/collector.go b/cli/beacon/internal/endpoint/collector/collector.go
index 66818b2a..c0ef6c9c 100644
--- a/cli/beacon/internal/endpoint/collector/collector.go
+++ b/cli/beacon/internal/endpoint/collector/collector.go
@@ -123,6 +123,10 @@ func ConfigYAML(cfg endpointconfig.Config) string {
if cfg.Collector.IncludeCodexSpans {
codexSpansYAML = " include_codex_spans: true\n"
}
+ openClawRuntimeMetricsYAML := ""
+ if cfg.Collector.IncludeOpenClawRuntimeMetrics {
+ openClawRuntimeMetricsYAML = " include_openclaw_runtime_metrics: true\n"
+ }
return fmt.Sprintf(`receivers:
otlp:
protocols:
@@ -169,7 +173,7 @@ service:
receivers: [otlp]
processors: [memory_limiter, batch]
exporters: %s
-`, cfg.Collector.GRPCPort, cfg.Collector.HTTPPort, cfg.LogPath, cfg.ContentRetention, runtimeMetricsYAML+codexSpansYAML+splunkExporter, exporters, exporters, exporters)
+`, cfg.Collector.GRPCPort, cfg.Collector.HTTPPort, cfg.LogPath, cfg.ContentRetention, runtimeMetricsYAML+codexSpansYAML+openClawRuntimeMetricsYAML+splunkExporter, exporters, exporters, exporters)
}
func splunkHECYAML(cfg endpointconfig.Config) string {
diff --git a/cli/beacon/internal/endpoint/collector/collector_test.go b/cli/beacon/internal/endpoint/collector/collector_test.go
index 0efbbe19..b72d95e2 100644
--- a/cli/beacon/internal/endpoint/collector/collector_test.go
+++ b/cli/beacon/internal/endpoint/collector/collector_test.go
@@ -55,6 +55,9 @@ func TestConfigYAMLIncludesReleaseContractFields(t *testing.T) {
if strings.Contains(yaml, "include_codex_spans") {
t.Fatalf("ConfigYAML should omit Codex span option unless explicitly enabled:\n%s", yaml)
}
+ if strings.Contains(yaml, "include_openclaw_runtime_metrics") {
+ t.Fatalf("ConfigYAML should omit OpenClaw runtime metrics option unless explicitly enabled:\n%s", yaml)
+ }
}
func TestConfigYAMLIncludesRuntimeMetricsOptIn(t *testing.T) {
@@ -77,6 +80,16 @@ func TestConfigYAMLIncludesCodexSpansOptIn(t *testing.T) {
}
}
+func TestConfigYAMLIncludesOpenClawRuntimeMetricsOptIn(t *testing.T) {
+ cfg := testConfig(t)
+ cfg.Collector.IncludeOpenClawRuntimeMetrics = true
+
+ yaml := ConfigYAML(cfg)
+ if !strings.Contains(yaml, "include_openclaw_runtime_metrics: true") {
+ t.Fatalf("ConfigYAML missing OpenClaw runtime metrics opt-in:\n%s", yaml)
+ }
+}
+
func TestConfigYAMLIncludesSplunkHECWhenConfigured(t *testing.T) {
cfg := testConfig(t)
cfg.Destinations = &endpointconfig.Destinations{SplunkHEC: &endpointconfig.SplunkHEC{
diff --git a/cli/beacon/internal/endpoint/config/config.go b/cli/beacon/internal/endpoint/config/config.go
index 8127e837..57b1b6b1 100644
--- a/cli/beacon/internal/endpoint/config/config.go
+++ b/cli/beacon/internal/endpoint/config/config.go
@@ -38,13 +38,14 @@ type Config struct {
}
type Collector struct {
- BinaryPath string `json:"binary_path,omitempty"`
- ConfigPath string `json:"config_path,omitempty"`
- GRPCPort int `json:"grpc_port"`
- HTTPPort int `json:"http_port"`
- SpoolPath string `json:"spool_path,omitempty"`
- IncludeRuntimeMetrics bool `json:"include_runtime_metrics,omitempty"`
- IncludeCodexSpans bool `json:"include_codex_spans,omitempty"`
+ BinaryPath string `json:"binary_path,omitempty"`
+ ConfigPath string `json:"config_path,omitempty"`
+ GRPCPort int `json:"grpc_port"`
+ HTTPPort int `json:"http_port"`
+ SpoolPath string `json:"spool_path,omitempty"`
+ IncludeRuntimeMetrics bool `json:"include_runtime_metrics,omitempty"`
+ IncludeCodexSpans bool `json:"include_codex_spans,omitempty"`
+ IncludeOpenClawRuntimeMetrics bool `json:"include_openclaw_runtime_metrics,omitempty"`
}
type Destinations struct {
diff --git a/cli/beacon/internal/endpoint/config/config_test.go b/cli/beacon/internal/endpoint/config/config_test.go
index 15d81575..e7987b46 100644
--- a/cli/beacon/internal/endpoint/config/config_test.go
+++ b/cli/beacon/internal/endpoint/config/config_test.go
@@ -41,6 +41,7 @@ func TestSaveLoadRoundTrip(t *testing.T) {
cfg.Collector.BinaryPath = filepath.Join(home, "bin", "otelcol")
cfg.Collector.IncludeRuntimeMetrics = true
cfg.Collector.IncludeCodexSpans = true
+ cfg.Collector.IncludeOpenClawRuntimeMetrics = true
cfg.EventCategories = []string{"tool", "session"}
cfg.ContentRetention = ContentRetentionRedacted
@@ -68,6 +69,9 @@ func TestSaveLoadRoundTrip(t *testing.T) {
if !loaded.Collector.IncludeCodexSpans {
t.Fatal("IncludeCodexSpans = false, want true")
}
+ if !loaded.Collector.IncludeOpenClawRuntimeMetrics {
+ t.Fatal("IncludeOpenClawRuntimeMetrics = false, want true")
+ }
if len(loaded.EventCategories) != 2 || loaded.EventCategories[1] != "session" {
t.Fatalf("EventCategories did not round-trip: %#v", loaded.EventCategories)
}
diff --git a/cli/beacon/internal/endpoint/lifecycle/lifecycle.go b/cli/beacon/internal/endpoint/lifecycle/lifecycle.go
index 5f87f859..22ac0f78 100644
--- a/cli/beacon/internal/endpoint/lifecycle/lifecycle.go
+++ b/cli/beacon/internal/endpoint/lifecycle/lifecycle.go
@@ -19,17 +19,18 @@ import (
)
type InstallOptions struct {
- UserMode bool
- LogPath string
- Harnesses []string
- GRPCPort int
- HTTPPort int
- CollectorPath string
- StartService bool
- ContentRetention endpointconfig.ContentRetention
- IncludeRuntimeMetrics bool
- IncludeCodexSpans bool
- SplunkHEC *endpointconfig.SplunkHEC
+ UserMode bool
+ LogPath string
+ Harnesses []string
+ GRPCPort int
+ HTTPPort int
+ CollectorPath string
+ StartService bool
+ ContentRetention endpointconfig.ContentRetention
+ IncludeRuntimeMetrics bool
+ IncludeCodexSpans bool
+ IncludeOpenClawRuntimeMetrics bool
+ SplunkHEC *endpointconfig.SplunkHEC
}
type UninstallOptions struct {
@@ -283,6 +284,7 @@ func buildConfig(opts InstallOptions) endpointconfig.Config {
cfg.Collector.BinaryPath = opts.CollectorPath
cfg.Collector.IncludeRuntimeMetrics = opts.IncludeRuntimeMetrics
cfg.Collector.IncludeCodexSpans = opts.IncludeCodexSpans
+ cfg.Collector.IncludeOpenClawRuntimeMetrics = opts.IncludeOpenClawRuntimeMetrics
if opts.ContentRetention != "" {
cfg.ContentRetention = opts.ContentRetention
}
diff --git a/collector-builder/exporter/beaconjsonexporter/config.go b/collector-builder/exporter/beaconjsonexporter/config.go
index 9a827c89..b92e51e5 100644
--- a/collector-builder/exporter/beaconjsonexporter/config.go
+++ b/collector-builder/exporter/beaconjsonexporter/config.go
@@ -9,13 +9,14 @@ const (
// Config controls local JSONL export for Beacon endpoint events.
type Config struct {
- Path string `mapstructure:"path"`
- MaxEventBytes int `mapstructure:"max_event_bytes"`
- RotateBytes int64 `mapstructure:"rotate_bytes"`
- RedactSecrets bool `mapstructure:"redact_secrets"`
- ContentRetention string `mapstructure:"content_retention"`
- IncludeRuntimeMetrics bool `mapstructure:"include_runtime_metrics"`
- IncludeCodexSpans bool `mapstructure:"include_codex_spans"`
+ Path string `mapstructure:"path"`
+ MaxEventBytes int `mapstructure:"max_event_bytes"`
+ RotateBytes int64 `mapstructure:"rotate_bytes"`
+ RedactSecrets bool `mapstructure:"redact_secrets"`
+ ContentRetention string `mapstructure:"content_retention"`
+ IncludeRuntimeMetrics bool `mapstructure:"include_runtime_metrics"`
+ IncludeCodexSpans bool `mapstructure:"include_codex_spans"`
+ IncludeOpenClawRuntimeMetrics bool `mapstructure:"include_openclaw_runtime_metrics"`
}
func createDefaultConfig() *Config {
diff --git a/collector-builder/exporter/beaconjsonexporter/exporter.go b/collector-builder/exporter/beaconjsonexporter/exporter.go
index 60d66fe2..c758b8d7 100644
--- a/collector-builder/exporter/beaconjsonexporter/exporter.go
+++ b/collector-builder/exporter/beaconjsonexporter/exporter.go
@@ -4,6 +4,7 @@ import (
"context"
"encoding/json"
"fmt"
+ "slices"
"strings"
"time"
@@ -126,7 +127,7 @@ func (e *beaconExporter) consumeMetrics(ctx context.Context, metrics pmetric.Met
scopeMetrics := resourceMetrics.ScopeMetrics().At(j)
for k := 0; k < scopeMetrics.Metrics().Len(); k++ {
metric := scopeMetrics.Metrics().At(k)
- if shouldDropMetric(resourceAttrs, metric.Name(), e.cfg.IncludeRuntimeMetrics) {
+ if shouldDropMetric(resourceAttrs, metric.Name(), e.cfg.IncludeRuntimeMetrics, e.cfg.IncludeOpenClawRuntimeMetrics) {
continue
}
event := e.eventFromMetric(resourceAttrs, metric)
@@ -166,10 +167,13 @@ func isNoisyCodexLog(attrs map[string]interface{}, body string) bool {
return strings.HasPrefix(eventName, "codex.")
}
-func shouldDropMetric(resourceAttrs map[string]interface{}, name string, includeRuntimeMetrics bool) bool {
+func shouldDropMetric(resourceAttrs map[string]interface{}, name string, includeRuntimeMetrics, includeOpenClawRuntimeMetrics bool) bool {
if shouldDropCodexMetric(resourceAttrs, name) {
return true
}
+ if shouldDropOpenClawMetric(resourceAttrs, name, includeOpenClawRuntimeMetrics) {
+ return true
+ }
if !includeRuntimeMetrics && shouldDropRuntimeMetric(name) {
return true
}
@@ -203,6 +207,52 @@ func shouldDropCodexMetric(resourceAttrs map[string]interface{}, name string) bo
return strings.HasPrefix(normalized, "codex.")
}
+func shouldDropOpenClawMetric(resourceAttrs map[string]interface{}, name string, includeOpenClawRuntimeMetrics bool) bool {
+ if includeOpenClawRuntimeMetrics {
+ return false
+ }
+ normalized := strings.ToLower(strings.TrimSpace(name))
+ if normalized == "" {
+ return false
+ }
+ if harnessName(resourceAttrs, name) != "openclaw_gateway" {
+ return false
+ }
+ if slices.Contains(openClawKeptMetricNames, normalized) {
+ return false
+ }
+ if slices.Contains(openClawDroppedMetricNames, normalized) {
+ return true
+ }
+ for _, prefix := range openClawDroppedMetricPrefixes {
+ if strings.HasPrefix(normalized, prefix) {
+ return true
+ }
+ }
+ return false
+}
+
+var openClawKeptMetricNames = []string{
+ "gen_ai.client.token.usage",
+ "openclaw.context.tokens",
+ "openclaw.tokens",
+}
+
+var openClawDroppedMetricNames = []string{
+ "openclaw.harness.duration_ms",
+ "openclaw.run.duration_ms",
+ "openclaw.session.state",
+ "openclaw.tool.execution.duration_ms",
+}
+
+var openClawDroppedMetricPrefixes = []string{
+ "openclaw.liveness.",
+ "openclaw.memory.",
+ "openclaw.queue.",
+ "openclaw.session.recovery.",
+ "openclaw.telemetry.exporter.",
+}
+
func (e *beaconExporter) eventFromLog(resourceAttrs map[string]interface{}, record plog.LogRecord) beaconEvent {
attrs := mergeMaps(resourceAttrs, attrsToMap(record.Attributes()))
ts := timestamp(record.Timestamp().AsTime())
diff --git a/collector-builder/exporter/beaconjsonexporter/exporter_test.go b/collector-builder/exporter/beaconjsonexporter/exporter_test.go
index 6a388765..8758693a 100644
--- a/collector-builder/exporter/beaconjsonexporter/exporter_test.go
+++ b/collector-builder/exporter/beaconjsonexporter/exporter_test.go
@@ -284,6 +284,103 @@ func TestConsumeMetricsIncludesRuntimeMetricsWhenConfigured(t *testing.T) {
}
}
+func TestConsumeMetricsDropsOpenClawOperationalMetricsByDefault(t *testing.T) {
+ path := filepath.Join(t.TempDir(), "runtime.jsonl")
+ exp, err := newExporter(&Config{
+ Path: path,
+ MaxEventBytes: defaultMaxEventBytes,
+ RotateBytes: defaultRotateBytes,
+ RedactSecrets: true,
+ ContentRetention: "metadata",
+ }, exporter.Settings{})
+ if err != nil {
+ t.Fatalf("newExporter returned error: %v", err)
+ }
+
+ metrics := pmetric.NewMetrics()
+ rm := metrics.ResourceMetrics().AppendEmpty()
+ rm.Resource().Attributes().PutStr("service.name", "openclaw-gateway")
+ sm := rm.ScopeMetrics().AppendEmpty()
+ for _, name := range []string{
+ "gen_ai.client.token.usage",
+ "openclaw.context.tokens",
+ "openclaw.harness.duration_ms",
+ "openclaw.liveness.cpu_core_ratio",
+ "openclaw.memory.rss_bytes",
+ "openclaw.queue.depth",
+ "openclaw.session.recovery.completed",
+ "openclaw.session.state",
+ "openclaw.telemetry.exporter.events",
+ "openclaw.tool.execution.duration_ms",
+ "openclaw.tokens",
+ } {
+ metric := sm.Metrics().AppendEmpty()
+ metric.SetName(name)
+ metric.SetEmptySum().DataPoints().AppendEmpty().SetIntValue(1)
+ }
+
+ if err := exp.consumeMetrics(context.Background(), metrics); err != nil {
+ t.Fatalf("consumeMetrics returned error: %v", err)
+ }
+ data, err := os.ReadFile(path)
+ if err != nil {
+ t.Fatalf("read runtime log: %v", err)
+ }
+ text := strings.TrimSpace(string(data))
+ for _, dropped := range []string{
+ "openclaw.harness.duration_ms",
+ "openclaw.liveness.cpu_core_ratio",
+ "openclaw.memory.rss_bytes",
+ "openclaw.queue.depth",
+ "openclaw.session.recovery.completed",
+ "openclaw.session.state",
+ "openclaw.telemetry.exporter.events",
+ "openclaw.tool.execution.duration_ms",
+ } {
+ if strings.Contains(text, dropped) {
+ t.Fatalf("OpenClaw operational metric %q should have been dropped, wrote: %s", dropped, text)
+ }
+ }
+ for _, kept := range []string{"gen_ai.client.token.usage", "openclaw.context.tokens", "openclaw.tokens"} {
+ if !strings.Contains(text, kept) {
+ t.Fatalf("OpenClaw token metric %q should have been kept, wrote: %s", kept, text)
+ }
+ }
+}
+
+func TestConsumeMetricsIncludesOpenClawOperationalMetricsWhenConfigured(t *testing.T) {
+ path := filepath.Join(t.TempDir(), "runtime.jsonl")
+ exp, err := newExporter(&Config{
+ Path: path,
+ MaxEventBytes: defaultMaxEventBytes,
+ RotateBytes: defaultRotateBytes,
+ RedactSecrets: true,
+ ContentRetention: "metadata",
+ IncludeOpenClawRuntimeMetrics: true,
+ }, exporter.Settings{})
+ if err != nil {
+ t.Fatalf("newExporter returned error: %v", err)
+ }
+
+ metrics := pmetric.NewMetrics()
+ rm := metrics.ResourceMetrics().AppendEmpty()
+ rm.Resource().Attributes().PutStr("service.name", "openclaw-gateway")
+ metric := rm.ScopeMetrics().AppendEmpty().Metrics().AppendEmpty()
+ metric.SetName("openclaw.memory.rss_bytes")
+ metric.SetEmptySum().DataPoints().AppendEmpty().SetIntValue(1)
+
+ if err := exp.consumeMetrics(context.Background(), metrics); err != nil {
+ t.Fatalf("consumeMetrics returned error: %v", err)
+ }
+ data, err := os.ReadFile(path)
+ if err != nil {
+ t.Fatalf("read runtime log: %v", err)
+ }
+ if !strings.Contains(string(data), "openclaw.memory.rss_bytes") {
+ t.Fatalf("OpenClaw operational metric should have been kept: %s", string(data))
+ }
+}
+
func TestConsumeMetricsDropsCodexMetricsByDefault(t *testing.T) {
path := filepath.Join(t.TempDir(), "runtime.jsonl")
exp, err := newExporter(&Config{