trace

package
v0.9.11 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 12, 2026 License: MIT Imports: 3 Imported by: 0

Documentation

Overview

Package trace provides distributed tracing context helpers for APM instrumentation.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ContinueTrace

func ContinueTrace(ctx context.Context) (context.Context, string)

ContinueTrace continues an existing trace with a new span. If the context has no trace ID, creates a new trace. Returns the updated context and the new span ID.

func GenerateSpanID

func GenerateSpanID() string

GenerateSpanID generates a new random span ID (16 hex characters). A span ID represents a single operation within a trace.

func GenerateTraceID

func GenerateTraceID() string

GenerateTraceID generates a new random trace ID (32 hex characters). A trace ID represents a single distributed trace across multiple services.

func GetParentID

func GetParentID(ctx context.Context) string

GetParentID returns the parent span ID from the context, or empty string if not set.

func GetSpanID

func GetSpanID(ctx context.Context) string

GetSpanID returns the span ID from the context, or empty string if not set.

func GetTraceContext

func GetTraceContext(ctx context.Context) (traceID, spanID, parentID string)

GetTraceContext extracts all trace context values from the context. Returns traceID, spanID, and parentID.

func GetTraceID

func GetTraceID(ctx context.Context) string

GetTraceID returns the trace ID from the context, or empty string if not set.

func StartTrace

func StartTrace(ctx context.Context) (context.Context, string, string)

StartTrace creates a new trace context with fresh trace and span IDs. Returns the new context, trace ID, and span ID.

func WithNewSpan

func WithNewSpan(ctx context.Context) (context.Context, string)

WithNewSpan creates a new span ID and updates the context. Returns the new context and the generated span ID.

func WithSpan

func WithSpan(ctx context.Context, spanID string) context.Context

WithSpan returns a new context with a new span ID, preserving the trace ID. The current span ID becomes the parent ID for child span correlation.

func WithTrace

func WithTrace(ctx context.Context, traceID, spanID string) context.Context

WithTrace returns a new context with the given trace ID and span ID. This is typically called at the start of a request to establish the trace context.

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL