A no-op implementation of TracerSystem following the Null Object Pattern.
The NullTracer provides the same API as TracerSystem but performs no operations,
eliminating the need for conditional checks in client code. All record methods
return :ok but do nothing, and all query methods return empty lists.
Usage
# Use the singleton null tracer instance
alias Mojentic.Tracer
# Pass to components that optionally accept a tracer
broker = Broker.new("gpt-4", gateway, tracer: Tracer.null_tracer())
# All operations are no-ops
Tracer.null_tracer() |> NullTracer.record_llm_call(...) # Does nothing
Tracer.null_tracer() |> NullTracer.get_events() # Returns []Benefits
- Eliminates conditional tracing checks throughout codebase
- Same API as TracerSystem for seamless substitution
- Zero overhead when tracing is disabled
- Cleaner code without
if tracer != nilchecks
Summary
Functions
No-op: Does nothing.
No-op: Does nothing.
No-op: Does nothing.
Always returns false.
Always returns an empty list.
Always returns an empty list.
No-op: Does not record the agent interaction.
No-op: Does not record the event.
No-op: Does not record the LLM call.
No-op: Does not record the LLM response.
No-op: Does not record the tool call.
Functions
@spec clear(atom()) :: :ok
No-op: Does nothing.
Examples
:ok = NullTracer.clear(:null_tracer)
@spec disable(atom()) :: :ok
No-op: Does nothing.
Examples
:ok = NullTracer.disable(:null_tracer)
@spec enable(atom()) :: :ok
No-op: Does nothing.
Examples
:ok = NullTracer.enable(:null_tracer)
@spec enabled?(atom()) :: false
Always returns false.
Examples
false = NullTracer.enabled?(:null_tracer)
Always returns an empty list.
Examples
[] = NullTracer.get_events(:null_tracer)
[] = NullTracer.get_events(:null_tracer, event_type: LLMCallTracerEvent)
@spec get_last_n_tracer_events(atom(), non_neg_integer(), keyword()) :: []
Always returns an empty list.
Examples
[] = NullTracer.get_last_n_tracer_events(:null_tracer, 10)
No-op: Does not record the agent interaction.
Examples
:ok = NullTracer.record_agent_interaction(:null_tracer,
from_agent: "A",
to_agent: "B",
event_type: "request",
correlation_id: "abc"
)
@spec record_event(atom(), Mojentic.Tracer.TracerEvents.TracerEvent.t()) :: :ok
No-op: Does not record the event.
Examples
event = %TracerEvent{...}
:ok = NullTracer.record_event(:null_tracer, event)
No-op: Does not record the LLM call.
Examples
:ok = NullTracer.record_llm_call(:null_tracer,
model: "gpt-4",
messages: [],
correlation_id: "abc"
)
No-op: Does not record the LLM response.
Examples
:ok = NullTracer.record_llm_response(:null_tracer,
model: "gpt-4",
content: "Hello",
correlation_id: "abc"
)
No-op: Does not record the tool call.
Examples
:ok = NullTracer.record_tool_call(:null_tracer,
tool_name: "date_resolver",
arguments: %{},
result: "2024-11-15",
correlation_id: "abc"
)