Behavior for trace exporters.
Exporters are responsible for sending trace data to various backends. This allows AITrace to be pluggable and integrate with different observability systems.
Example Implementations
AITrace.Exporter.Console- Print traces to stdout for developmentAITrace.Exporter.File- Write traces to JSON filesAITrace.Exporter.Phoenix- Send traces via Phoenix channelsAITrace.Exporter.OpenTelemetry- Export to OTel-compatible systems
Implementing an Exporter
defmodule MyApp.CustomExporter do
@behaviour AITrace.Exporter
@impl true
def init(opts) do
# Initialize exporter state
{:ok, opts}
end
@impl true
def export(trace, state) do
# Send the trace somewhere
IO.inspect(trace)
{:ok, state}
end
@impl true
def shutdown(state) do
# Cleanup resources
:ok
end
end
Summary
Callbacks
Export a trace to the backend.
Initialize the exporter with the given options.
Shutdown the exporter and cleanup any resources.
Callbacks
@callback export(trace :: AITrace.Trace.t(), state :: any()) :: {:ok, state :: any()} | {:error, reason :: any()}
Export a trace to the backend.
The exporter should send the trace data to its destination and return
{:ok, new_state} on success, or {:error, reason} on failure.
Initialize the exporter with the given options.
Returns {:ok, state} on success, or {:error, reason} on failure.
@callback shutdown(state :: any()) :: :ok
Shutdown the exporter and cleanup any resources.
This is called when the exporter is being stopped.