Skip to content

implement json span writing - #86

Merged
backnotprop merged 21 commits into
mainfrom
feat/otl-span-logs
Dec 19, 2025
Merged

implement json span writing#86
backnotprop merged 21 commits into
mainfrom
feat/otl-span-logs

Conversation

@backnotprop

Copy link
Copy Markdown
Contributor

No description provided.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull request overview

This PR implements a hierarchical telemetry system for capturing the complete event processing lifecycle using OpenTelemetry-compatible spans. The implementation replaces the previous DebugCapture approach with a structured TelemetryContext that tracks events through three stages: ingest (raw event), enrich (preprocessing), and evaluate (policy evaluation).

Key changes:

  • Introduces span-based telemetry with OTLP-compatible fields (span_id, parent_span_id, timestamps)
  • Implements TelemetryContext with Drop guard to ensure telemetry writes even on panic/early exit
  • Integrates telemetry capture throughout the engine evaluation pipeline
  • Adds JSON and text file output formats, plus OTLP export capability

Reviewed changes

Copilot reviewed 9 out of 9 changed files in this pull request and generated 12 comments.

Show a summary per file
File Description
cupcake-core/src/telemetry/mod.rs Module definition and public API exports for the telemetry system
cupcake-core/src/telemetry/span.rs Span types (IngestSpan, EnrichSpan, EvaluateSpan) with OTLP fields and timing
cupcake-core/src/telemetry/context.rs TelemetryContext with Drop guard and lifecycle management
cupcake-core/src/telemetry/writer.rs File-based telemetry output (JSON and human-readable text formats)
cupcake-core/src/telemetry/otlp.rs OTLP protocol export implementation for external observability systems
cupcake-core/src/engine/mod.rs Engine integration to record evaluation spans during policy processing
cupcake-cli/src/main.rs CLI integration to create telemetry context and capture preprocessing
cupcake-core/src/debug/tests.rs Test updates to use TelemetryContext instead of DebugCapture
cupcake-core/src/lib.rs Module registration for telemetry

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread cupcake-core/src/telemetry/mod.rs Outdated
Comment thread cupcake-core/src/telemetry/otlp.rs Outdated
Comment thread cupcake-core/src/telemetry/otlp.rs Outdated
Comment thread cupcake-core/src/telemetry/otlp.rs Outdated
Comment thread cupcake-core/src/telemetry/otlp.rs Outdated
Comment thread cupcake-core/src/telemetry/span.rs Outdated
Comment thread cupcake-cli/src/main.rs Outdated
Comment thread cupcake-cli/src/main.rs
Comment thread cupcake-core/src/engine/mod.rs
Comment thread cupcake-core/src/telemetry/otlp.rs Outdated
backnotprop and others added 7 commits December 11, 2025 19:02
- Rename DebugCapture to SignalTelemetry (accurate name for its purpose)
- Remove dead fields: signals_configured, errors (written but never read)
- Remove add_error() method (only consumer was dead)
- Remove ~550 lines of dead formatting/output code from debug.rs
- Delete debug/tests.rs (tested dead code)
- Update engine/mod.rs to use new type and field names
- Remove dead write statements to signals_configured and errors

The struct is now a minimal container (~35 lines) that collects
signal execution data for telemetry. TelemetryContext handles all
actual output (debug files + telemetry JSON).

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Step 1 of engine/mod.rs refactor (Surgical Plus approach):

- Create engine/config.rs with:
  - find_shell_command() and SHELL_COMMAND static
  - ProjectPaths struct and impl (~125 lines)
  - EngineConfig struct and impl (~35 lines)

- Move PolicyUnit struct to metadata.rs (enables future routing.rs extraction)

- Update mod.rs re-exports for public API compatibility

mod.rs reduced from 2506 to 2290 lines (~216 lines extracted)

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
- Add executor.rs module with Executor struct that handles all OS/IO
  interactions (signal gathering, action execution)
- Add execute_global_actions() and gather_global_signals() methods
- Update evaluate() to create Executor early for both global and project
  evaluation paths
- Update evaluate_global() to accept Executor parameter
- Remove legacy methods from mod.rs:
  - gather_signals_with_rulebook
  - execute_signals_from_rulebook
  - execute_actions_with_rulebook
  - execute_rule_specific_actions
  - execute_single_action
- Gate route_with_map under #[cfg(feature = "catalog")]
- Fix Python test fixtures: move test_basic.rego to policies/claude/
- Update setup_test_policies to copy both policies/ and system/ dirs

This eliminates DRY violation and security maintenance risk from
duplicate action execution code.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
- routing_debug.rs: Remove unused CLI inspection methods
  (inspect_route, list_all_routes)
- trace.rs: Remove extract_event_name and extract_tool_name
  (only used in tests, not production code)
- routing.rs: Remove redundant create_all_routing_keys_from_metadata
  wrapper that just called create_routing_key_from_metadata
- Update mod.rs to use create_routing_key_from_metadata directly

Note: fixtures/bundle.tar.gz is already gitignored by root .gitignore

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Address reviewer concern: hardcoded preprocessing operations in telemetry
did not reflect what was actually applied.

Changes:
- Add PreprocessResult struct to track which operations were performed
- Update preprocess_input to return PreprocessResult
- Update helper functions to return bool indicating if they applied changes:
  - preprocess_claude_bash_command
  - preprocess_cursor_shell_command
  - normalize_write_edit_content_fields
  - resolve_and_attach_symlinks
- Update main.rs to use actual operations from PreprocessResult

Now telemetry accurately reports only operations that were actually
performed based on config and input data, rather than always reporting
the same hardcoded list.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 19 out of 20 changed files in this pull request and generated 2 comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread cupcake-core/src/telemetry/span.rs Outdated
Comment thread cupcake-core/src/engine/executor.rs
@backnotprop
backnotprop requested a review from captjt December 15, 2025 16:07
captjt
captjt previously approved these changes Dec 16, 2025
@backnotprop
backnotprop merged commit ede0a5d into main Dec 19, 2025
3 checks passed
@backnotprop
backnotprop deleted the feat/otl-span-logs branch December 19, 2025 15:50
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.

3 participants