package lazytracing ¶
import "golazy.dev/lazytelemetry/lazytracing"
Functions ¶
func ClearAllocationSamples ¶
ClearAllocationSamples removes lazydev allocation samples for span and its descendants after request capture has been written.
func ClearAllocationSamples(span *Span)
func Log ¶
Log records a message in the Go runtime trace when ctx carries an active span. Span event recording is owned by the logging package.
func Log(ctx context.Context, category string, message string)
func RequestID ¶
RequestID returns the request id attached to ctx.
func RequestID(ctx context.Context) string
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 WithAllocationSampling ¶
WithAllocationSampling enables lazydev allocation sampling for spans started from ctx.
func WithAllocationSampling(ctx context.Context) context.Context
func WithRequestID ¶
WithRequestID attaches requestID to ctx for span and runtime trace correlation.
func WithRequestID(ctx context.Context, requestID string) context.Context
func WithTraceContext ¶
WithTraceContext attaches trace context to ctx.
func WithTraceContext(ctx context.Context, traceContext TraceContext) context.Context
Types ¶
type AllocationSummary ¶
AllocationSummary contains cumulative process allocation deltas observed while a lazydev span was active.
type AllocationSummary struct {
TotalAllocBytesDelta uint64
MallocsDelta uint64
FreesDelta uint64
}
func SpanAllocationSummary ¶
SpanAllocationSummary returns the allocation delta sampled for span.
func SpanAllocationSummary(span *Span) (AllocationSummary, bool)
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 StartRegion ¶
StartRegion starts a child span and Go runtime trace region when ctx already carries an active span. It returns ctx unchanged and a nil span when telemetry is not active for the request.
func StartRegion(ctx context.Context, name string, attributes ...slog.Attr) (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) Children ¶
Children returns a copy of direct child spans.
func (s *Span) Children() []*Span
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) EndedAt ¶
EndedAt returns the time the span ended, or the zero time when it is still open.
func (s *Span) EndedAt() time.Time
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) GoroutineID ¶
GoroutineID returns the goroutine identifier captured for development diagnostics. Production builds return zero.
func (s *Span) GoroutineID() uint64
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) StartedAt ¶
StartedAt returns the time the span started.
func (s *Span) StartedAt() time.Time
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.