Skip to content

fix(openclaw): use nix-provided kubectl for OTLP endpoint resolution - #1452

Merged
shunkakinoki merged 3 commits into
mainfrom
fix/openclaw-otlp-kubectl
Apr 12, 2026
Merged

fix(openclaw): use nix-provided kubectl for OTLP endpoint resolution#1452
shunkakinoki merged 3 commits into
mainfrom
fix/openclaw-otlp-kubectl

Conversation

@shunkakinoki

@shunkakinoki shunkakinoki commented Apr 12, 2026

Copy link
Copy Markdown
Owner

Summary

  • OTLP endpoint was hydrating to localhost:4318 because kubectl wasn't in PATH during home-manager activation
  • Add @kubectl@ placeholder to hydrate.sh resolved via pkgs.kubectl in default.nix
  • On non-Kyber hosts, kubectl is replaced with /usr/bin/true (falls back to localhost gracefully)

Test plan

  • shellspec spec/openclaw_hydrate_spec.sh passes
  • Both JSON templates validate
  • Verified kubectl get svc alloy -n alloy resolves to 10.43.138.193 on kyber
  • Verified test trace POST to that endpoint returns HTTP 200

Summary by cubic

Fixes OTLP endpoint resolution by using Nix-provided kubectl during hydration so telemetry points to the Alloy service instead of localhost:4318. Enables diagnostics-otel with a safe fallback on non-Kyber hosts; Obsidian activation changes were reverted and are not included.

  • New Features

    • Enabled top-level diagnostics and diagnostics-otel in both OpenClaw templates, using __OTEL_ENDPOINT__ with http/protobuf and service name openclaw.
  • Bug Fixes

    • Resolve OTLP endpoint at hydration via @kubectl@ mapped to ${pkgs.kubectl}/bin/kubectl to read the Alloy service ClusterIP.
    • On non-Kyber hosts, map @kubectl@ to /usr/bin/true to fall back to localhost:4318.
    • Reverted Obsidian activate.sh edits; no Obsidian changes remain in this PR.

Written for commit 90bc1aa. Summary will update on new commits.

@mesa-dot-dev

mesa-dot-dev Bot commented Apr 12, 2026

Copy link
Copy Markdown

You do not have enough credits to review this pull request. Please purchase more credits to continue.

@coderabbitai

coderabbitai Bot commented Apr 12, 2026

Copy link
Copy Markdown

Caution

Review failed

The pull request is closed.

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: a57b4512-5960-45db-b5b4-6d1127743123

📥 Commits

Reviewing files that changed from the base of the PR and between 0442e4c and 90bc1aa.

📒 Files selected for processing (2)
  • config/openclaw/default.nix
  • config/openclaw/hydrate.sh

Disabled knowledge base sources:

  • Linear integration is disabled

You can enable these sources in your CodeRabbit configuration.


📝 Walkthrough

Summary by CodeRabbit

  • Chores
    • Updated internal configuration handling for OpenTelemetry endpoint resolution in gateway mode to use Nix-substituted binaries instead of system-level commands.

Walkthrough

This change extends the OpenClaw Nix hydration script configuration to substitute a Nix-managed kubectl binary into template variables during script generation. The substituted binary is conditionally resolved based on host configuration, and is used by the hydration script when retrieving OTEL endpoint information in gateway mode.

Changes

Cohort / File(s) Summary
OpenClaw Hydration Configuration
config/openclaw/default.nix, config/openclaw/hydrate.sh
Adds kubectl variable substitution to hydrateScript template inputs; conditionally set to either Nix-packaged kubectl or no-op binary based on host configuration. Updates hydrate.sh to use substituted @kubectl@ instead of system kubectl when resolving OTEL endpoint via alloy Service clusterIP in gateway mode.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Possibly related PRs

Suggested labels

enhancement

Poem

🐰 A kubectl in Nix's gentle care,
Replaces the system's path with flair,
Hydrating scripts with precision true,
Gateway modes get their OTEL through!

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately describes the main change: using Nix-provided kubectl for OTLP endpoint resolution during hydration, which directly addresses the core issue fixed in this PR.
Description check ✅ Passed The description clearly explains the problem (kubectl not in PATH), the solution (using @kubectl@ placeholder resolved via Nix), and includes a comprehensive test plan with verification steps on actual hosts.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/openclaw-otlp-kubectl

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@mesa-dot-dev

mesa-dot-dev Bot commented Apr 12, 2026

Copy link
Copy Markdown

Mesa Description

TL;DR

Fixes OpenTelemetry (OTLP) endpoint resolution for OpenClaw by dynamically determining the Alloy service's ClusterIP using a Nix-provided kubectl, ensuring telemetry is sent to the correct service instead of localhost:4318, and enables OTEL diagnostics in both OpenClaw templates with a safe fallback.

What changed?

  • config/openclaw/default.nix: Conditionally defines the kubectl path, using pkgs.kubectl on 'Kyber' hosts and /usr/bin/true otherwise.
  • config/openclaw/hydrate.sh: Introduces dynamic OpenTelemetry (OTEL) endpoint resolution; attempts to find the alloy service's ClusterIP using kubectl and defaults to localhost:4318 if not found. The resolved endpoint replaces a placeholder in the configuration.
  • config/openclaw/openclaw.template.json: Adds a diagnostics section, enabling general diagnostics and setting up OpenTelemetry (OTel) for traces, metrics, and logs with a specified endpoint, protocol, and service name. Also adds and enables a diagnostics-otel plugin.
  • config/openclaw/openclaw.tpl.json: Updates the OpenClaw configuration template.

Description generated by Mesa. Update settings

- Obsidian headless daemon logs ENOENT on every start because
  wiki.json (per-vault config) was never created by activate.sh.
  Now seeds missing <vault-id>.json files with {} on activation.
- Enable diagnostics-otel plugin and top-level diagnostics config
  in both openclaw templates (traces, metrics, logs via http/protobuf).
@shunkakinoki
shunkakinoki force-pushed the fix/openclaw-otlp-kubectl branch from 0442e4c to 90bc1aa Compare April 12, 2026 13:43
@shunkakinoki
shunkakinoki merged commit 4d9d6f3 into main Apr 12, 2026
22 of 29 checks passed
@shunkakinoki
shunkakinoki deleted the fix/openclaw-otlp-kubectl branch April 12, 2026 13:44

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request introduces OpenTelemetry (OTEL) diagnostics to the OpenClaw configuration. Key changes include adding kubectl to the Nix environment, updating the hydration script to dynamically resolve the OTEL endpoint via Kubernetes service discovery, and enabling the diagnostics section and plugin in the configuration templates. A review comment identifies a potential issue in the hydration script where the endpoint URL could become invalid if the kubectl command returns an empty string, and provides a suggestion to handle this using shell parameter expansion.


# Resolve Alloy OTLP ClusterIP for local telemetry export
OTEL_ENDPOINT="http://$(kubectl get svc alloy -n alloy -o jsonpath='{.spec.clusterIP}' 2>/dev/null || echo localhost):4318"
OTEL_ENDPOINT="http://$(@kubectl@ get svc alloy -n alloy -o jsonpath='{.spec.clusterIP}' 2>/dev/null || echo localhost):4318"

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

The fallback logic for OTEL_ENDPOINT does not work as intended when @kubectl@ is substituted with /usr/bin/true (which occurs on non-Kyber hosts). Since true exits with code 0 but produces no output, the command substitution $(...) returns an empty string, resulting in an invalid endpoint URL: http://:4318.

Using shell parameter expansion ${VAR:-default} ensures that the fallback to localhost works correctly even when the command succeeds with empty output.

Suggested change
OTEL_ENDPOINT="http://$(@kubectl@ get svc alloy -n alloy -o jsonpath='{.spec.clusterIP}' 2>/dev/null || echo localhost):4318"
OTEL_ENDPOINT=$(@kubectl@ get svc alloy -n alloy -o jsonpath='{.spec.clusterIP}' 2>/dev/null || echo localhost)
OTEL_ENDPOINT="http://${OTEL_ENDPOINT:-localhost}:4318"
References
  1. Maintain consistency with established patterns for writing scripts that are extracted from Nix expressions, ensuring placeholders like @kubectl@ are handled correctly even when substituted with no-op commands.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant