package lazytracing
import "golazy.dev/lazytelemetry/lazytracing"
Functions
func SpanID
SpanID returns the active span id from ctx.
func SpanID(ctx context.Context) string
func TraceID
TraceID returns the active trace id from ctx.
func TraceID(ctx context.Context) string
func WithTraceContext
WithTraceContext attaches trace context to ctx.
func WithTraceContext(ctx context.Context, traceContext TraceContext) context.Context
Types
type Event
Event records a named span event.
type Event struct {
Name string
Time time.Time
Attributes []slog.Attr
}
type Span
Span is a lightweight in-process span.
type Span struct {
// contains filtered or unexported fields
}
func SpanFromContext
SpanFromContext returns the active span attached to ctx.
func SpanFromContext(ctx context.Context) *Span
func StartSpan
StartSpan starts a lightweight span and returns a context containing it.
func StartSpan(ctx context.Context, name string, attributes ...slog.Attr) (context.Context, *Span)
func (s *Span) AddAttributes
AddAttributes appends attributes to the span.
func (s *Span) AddAttributes(attributes ...slog.Attr)
func (s *Span) AddEvent
AddEvent records a span event.
func (s *Span) AddEvent(name string, attributes ...slog.Attr)
func (s *Span) Attributes
Attributes returns a copy of the span attributes.
func (s *Span) Attributes() []slog.Attr
func (s *Span) Duration
Duration returns the span duration when it has ended, or the elapsed time since start otherwise.
func (s *Span) Duration() time.Duration
func (s *Span) End
End finishes the span.
func (s *Span) End()
func (s *Span) Error
Error returns the recorded span error.
func (s *Span) Error() error
func (s *Span) Events
Events returns a copy of recorded span events.
func (s *Span) Events() []Event
func (s *Span) Name
Name returns the span name.
func (s *Span) Name() string
func (s *Span) ParentID
ParentID returns the parent span id when known.
func (s *Span) ParentID() string
func (s *Span) RecordError
RecordError records err on the span.
func (s *Span) RecordError(err error)
func (s *Span) SpanID
SpanID returns the span id.
func (s *Span) SpanID() string
func (s *Span) TraceID
TraceID returns the span trace id.
func (s *Span) TraceID() string
type TraceContext
TraceContext stores W3C trace context identifiers without depending on an OpenTelemetry SDK.
type TraceContext struct {
TraceID string
SpanID string
TraceFlags string
TraceState string
Remote bool
}
func ParseTraceparent
ParseTraceparent parses the W3C traceparent header.
func ParseTraceparent(traceparent, tracestate string) (TraceContext, bool)
func TraceContextFromContext
TraceContextFromContext returns the trace context attached to ctx.
func TraceContextFromContext(ctx context.Context) (TraceContext, bool)
Package lazytracing provides lightweight span helpers for GoLazy telemetry.