Skip to content

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

5.9 KB
Raw Blame

beaconjsonexporter

Production Collector exporter for Beacon Endpoint Agent.

This exporter is built into the custom beacon-otelcol distribution. It is responsible for converting OTLP logs, traces, metrics, and resource attributes into Wazuh-compatible Beacon endpoint JSONL events.

Required behavior:

  • Bind only through Collector receivers configured on localhost.
  • Write one complete JSON object per line.
  • Use the canonical vendor=beacon, product=endpoint-agent, schema_version=1.0 event contract.
  • Identify Claude Code and Claude Cowork OTLP resources and map prompts, tool/MCP calls, file access, approval decisions, API usage, token counts, costs, and errors into Beacon endpoint events.
  • For Claude Code and Claude Cowork logs, decode JSON-string tool_input and tool_parameters attributes into canonical command.* and file.* fields. Only actual tool results may become tool, command, or file actions; API, assistant, plugin, hook, skill, and other lifecycle logs use session actions, while MCP connection lifecycle uses mcp.connection.
  • Preserve explicitly supplied Beacon action/category attributes and retain the original OTLP attributes under raw.attributes.
  • Include configured content fields by default, with metadata and redacted modes available for stricter deployments.
  • Redact common secrets and cap event size before writing.
  • Emit health failure events when write failures occur.

Token and cost usage:

  • Metrics named gen_ai.client.token.usage or ending in .token.usage or .cost.usage (for example claude_code.token.usage and claude_code.cost.usage) expand to one event per datapoint so the value, token type, model, and session attributes survive into JSONL.
  • Token datapoints normalize into the canonical gen_ai.usage struct using the type/gen_ai.token.type attribute (input, output, cacheRead, cacheCreation, reasoning); cost datapoints map to gen_ai.usage.cost_usd. Unknown token types keep the raw value in raw.metric_value only.
  • Gemini CLI's counts overlap differently: its input includes the cache and its output excludes thinking tokens. The gemini_cli.api_response log record and the gemini_cli.token.usage series (input, output, thought, cache, tool) both map to input = prompt - cached + tool-use prompt, cache read = cached, output = candidates + thoughts, and reasoning = thoughts. The gen_ai.client.inference.operation.details record that restates the same response carries no usage, so a response is counted once.
  • Datapoint events use the datapoint timestamp and record raw.metric_temporality, raw.metric_monotonic, raw.metric_value, and (for histograms) raw.metric_count so downstream aggregation can dedupe cumulative series.
  • All other metrics, and usage metrics without datapoints, keep the single metric.observed event.
  • Codex's current live token source is the completed session_task.turn trace, not its anonymous histogram. The exporter keeps that one span by default, promotes thread.id/turn.id/model, and maps cache reads and cache writes to disjoint canonical usage fields. Legacy Codex metric events remain readable.
  • Span and log attributes under the OTel GenAI semconv input names (gen_ai.usage.input_tokens, and the older gen_ai.usage.prompt_tokens / llm.usage.prompt_tokens) count cached prompt tokens as part of input, so the exporter subtracts the cache read and cache creation (cache_write) counts reported beside them to store uncached input. An input smaller than those cache counts is already uncached and is stored as reported. Claude Code's bare input_tokens is Anthropic's uncached count and is never reduced; raw keeps every value as the runtime sent it.

Noise controls:

  • Generic process/runtime metrics are dropped by default unless include_runtime_metrics: true is set.
  • Codex spans are dropped by default except for a completed turn span carrying codex.turn.token_usage.*. Set include_codex_spans: true only when troubleshooting all Codex OTLP internals.
  • Codex metrics and transport/startup/debug logs remain suppressed by default so one prompt does not flood the endpoint runtime log.
  • Copilot CLI metrics are suppressed by default, including github.copilot.*, legacy copilot_chat.*, and gen_ai.client.* metrics. Activity comes from OTLP spans. Set include_runtime_metrics: true for troubleshooting.
  • OpenClaw metrics are suppressed by default, including openclaw.* and gen_ai.client.* token metrics. Activity comes from OTLP logs and traces. Set include_runtime_metrics: true for troubleshooting.

The production implementation should live here and be included by collector-builder/builder.yaml.

beacon_ingest extension

beaconingestextension (component type beacon_ingest) is the collector side of the restricted log access mode for system-mode endpoints. With it, the collector is the only writer of /var/log/beacon-agent/runtime.jsonl, which can then be 0640 root:beacon-log instead of world-writable:

  • It listens on a Unix socket (/var/run/beacon-agent/ingest.sock by default) that hooks send their events to (pkg/asymptoteobserve/localingest).
  • Each event's user is replaced with the sender's kernel-verified uid and account name, so a user can describe their own sessions but cannot write an event under someone else's account.
  • Events are appended through internal/runtimelog, the same lock, rotation and file-mode handling the exporter uses, so both writers can share one log.
  • Shutdown removes the socket; hooks then spool their events privately until the collector is back.
extensions:
  beacon_ingest:
    log_path: /var/log/beacon-agent/runtime.jsonl
    rotate_bytes: 10485760
    rotate_archives: 5
service:
  extensions: [health_check, beacon_ingest]

beacon endpoint install --system --log-access restricted renders this; nothing else enables it.