Crucible.TraceIntegration (CrucibleFramework v0.5.2)
View SourceIntegration module for crucible_trace within the experiment pipeline.
This module provides helpers for managing trace chains throughout the experiment lifecycle, including:
- Creating and initializing trace chains
- Emitting stage transition events
- Capturing decision points and alternatives
- Persisting and exporting traces
Usage
Traces are automatically managed when enabled in the experiment configuration. Each stage can emit trace events to capture its decision-making process.
Event Types
The following event types are emitted by the pipeline:
:stage_start- When a stage begins execution:stage_complete- When a stage completes successfully:stage_failed- When a stage encounters an error:hypothesis_formed- When forming a hypothesis about approach:pattern_applied- When applying a known pattern:alternative_considered- When considering alternatives:decision_made- When making a final decision
Example
# In a stage implementation
ctx = TraceIntegration.emit_event(
ctx,
:hypothesis_formed,
"Use ensemble for improved accuracy",
"Multiple models can provide better consensus",
alternatives: ["Single model", "Sequential cascade"],
confidence: 0.85
)
Summary
Functions
Calculate confidence statistics from the trace.
Emit a decision event with alternatives.
Emit a trace event to the current chain.
Emit a stage completion event.
Emit a stage failure event.
Emit a stage start event.
Get event count from the trace chain.
Generate an HTML visualization of the trace.
Export the trace chain to JSON.
Filter trace events by type.
Initialize a new trace chain for an experiment.
Get the most recent event from the trace.
Load a trace from disk.
Save the trace to disk.
Check if tracing is enabled for the context.
Types
@type trace_chain() :: CrucibleTrace.Chain.t()
@type trace_event() :: CrucibleTrace.Event.t()
Functions
@spec confidence_stats(Crucible.Context.t()) :: map()
Calculate confidence statistics from the trace.
Returns statistics about confidence levels across all decisions.
@spec emit_decision( Crucible.Context.t(), String.t(), String.t(), [String.t()], float() ) :: Crucible.Context.t()
Emit a decision event with alternatives.
Captures a decision point where alternatives were considered.
Emit a trace event to the current chain.
If tracing is not enabled (trace is nil), returns the context unchanged.
Parameters
ctx- The current contexttype- Event type atomdecision- What was decidedreasoning- Why this decision was madeopts- Additional event options
Options
:alternatives- List of alternatives considered:confidence- Confidence level (0.0-1.0):metadata- Additional metadata map:code_section- Related code section:spec_reference- Related specification reference
@spec emit_event(Crucible.Context.t(), atom(), String.t(), String.t(), keyword()) :: Crucible.Context.t()
@spec emit_stage_complete(Crucible.Context.t(), atom(), map()) :: Crucible.Context.t()
Emit a stage completion event.
Captures successful completion of a pipeline stage.
@spec emit_stage_failed(Crucible.Context.t(), atom(), term()) :: Crucible.Context.t()
Emit a stage failure event.
Captures when a pipeline stage encounters an error.
@spec emit_stage_start(Crucible.Context.t(), atom(), map()) :: Crucible.Context.t()
Emit a stage start event.
Captures the beginning of a pipeline stage execution.
@spec event_count(Crucible.Context.t()) :: non_neg_integer()
Get event count from the trace chain.
@spec export_html(Crucible.Context.t()) :: String.t() | nil
Generate an HTML visualization of the trace.
Returns the HTML content for visualizing the trace chain, or nil if tracing is not enabled.
@spec export_json(Crucible.Context.t()) :: String.t() | nil
Export the trace chain to JSON.
Returns the JSON representation of the trace chain, or nil if tracing is not enabled.
@spec filter_events(Crucible.Context.t(), atom()) :: [trace_event()]
Filter trace events by type.
Returns all events of a specific type from the trace chain.
@spec init_trace(Crucible.Context.t(), String.t()) :: Crucible.Context.t()
Initialize a new trace chain for an experiment.
Creates a new trace chain and adds it to the context.
@spec last_event(Crucible.Context.t()) :: trace_event() | nil
Get the most recent event from the trace.
@spec load_trace(String.t()) :: {:ok, trace_chain()} | {:error, {:missing_dependency, :crucible_trace} | term()}
Load a trace from disk.
Loads a previously saved trace chain from the filesystem.
@spec save_trace(Crucible.Context.t(), String.t()) :: :ok | {:error, term()}
Save the trace to disk.
Persists the trace chain to the filesystem.
@spec tracing_enabled?(Crucible.Context.t()) :: boolean()
Check if tracing is enabled for the context.