Documentation
¶
Overview ¶
Package seqotel provides OpenTelemetry integration for slog-seq, including automatic trace context enrichment for slog events and a SpanProcessor that forwards completed spans to Seq as CLEF events.
Use NewSeqOTelHandler to create a handler with trace correlation enabled:
handler := seqotel.NewSeqOTelHandler("http://seq:5341/ingest/clef",
slogseq.WithAPIKey("your-api-key"),
slogseq.WithBatchSize(50),
)
defer handler.Close()
slog.SetDefault(slog.New(handler))
Use NewLoggingSpanProcessor to forward spans to Seq:
processor := seqotel.NewLoggingSpanProcessor(handler) tp := trace.NewTracerProvider(trace.WithSpanProcessor(processor))
Index ¶
- type LoggingSpanProcessor
- func (p *LoggingSpanProcessor) ExportSpans(_ context.Context, spans []trace.ReadOnlySpan) error
- func (p *LoggingSpanProcessor) ForceFlush(_ context.Context) error
- func (p *LoggingSpanProcessor) OnEnd(s trace.ReadOnlySpan)
- func (p *LoggingSpanProcessor) OnStart(_ context.Context, _ trace.ReadWriteSpan)
- func (p *LoggingSpanProcessor) Shutdown(_ context.Context) error
- type SeqOTelHandler
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type LoggingSpanProcessor ¶
type LoggingSpanProcessor struct {
// contains filtered or unexported fields
}
LoggingSpanProcessor is an OpenTelemetry trace.SpanProcessor and trace.SpanExporter that converts completed spans and their events into CLEF events and dispatches them to Seq via a SeqOTelHandler.
Span events are emitted before the span itself to preserve chronological ordering. The processor does not manage the handler's lifecycle - the caller is responsible for closing the handler.
func NewLoggingSpanProcessor ¶
func NewLoggingSpanProcessor(handler *SeqOTelHandler) *LoggingSpanProcessor
NewLoggingSpanProcessor creates a LoggingSpanProcessor that forwards completed spans to Seq via the given SeqOTelHandler.
func (*LoggingSpanProcessor) ExportSpans ¶
func (p *LoggingSpanProcessor) ExportSpans(_ context.Context, spans []trace.ReadOnlySpan) error
ExportSpans converts a batch of completed spans and their events into CLEF events and dispatches them to the handler. This method satisfies the trace.SpanExporter interface.
func (*LoggingSpanProcessor) ForceFlush ¶
func (p *LoggingSpanProcessor) ForceFlush(_ context.Context) error
ForceFlush is a no-op. Events are flushed on the configured interval and fully drained when the handler is closed.
func (*LoggingSpanProcessor) OnEnd ¶
func (p *LoggingSpanProcessor) OnEnd(s trace.ReadOnlySpan)
OnEnd converts a completed span and its events into CLEF events and dispatches them to the handler. Span events are emitted first, followed by the span itself.
func (*LoggingSpanProcessor) OnStart ¶
func (p *LoggingSpanProcessor) OnStart(_ context.Context, _ trace.ReadWriteSpan)
OnStart is a no-op. This processor only acts on completed spans.
type SeqOTelHandler ¶
type SeqOTelHandler struct {
*slogseq.SeqHandler
}
SeqOTelHandler is a slog.Handler extending slogseq.SeqHandler with OpenTelemetry trace context enrichment.
Create one using NewSeqOTelHandler. Do not construct directly.
func NewLogger ¶
NewLogger is a convenience function that creates a SeqOTelHandler and wraps it in an slog.Logger. Refer to NewSeqOTelHandler for teardown information.
func NewSeqOTelHandler ¶
func NewSeqOTelHandler(seqURL string, opts ...slogseq.SeqOption) *SeqOTelHandler
NewSeqOTelHandler creates and starts a new SeqOTelHandler with OpenTelemetry trace context enrichment enabled. Log events are automatically correlated with active spans. Derived handlers (via WithAttrs and WithGroup) share the same workers and connection. Close must be called on the original handler when no longer needed, rendering all (sub-)handlers unusable.
See slogseq package documentation for all possible slogseq.SeqOption.