tracing

package
v0.0.0-...-2da20e2 Latest Latest
Warning

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

Go to latest
Published: Apr 16, 2026 License: MIT Imports: 15 Imported by: 0

Documentation

Overview

Package tracing provides OpenTelemetry tracer initialization utilities.

Index

Constants

View Source
const (
	// UptraceDriver is used to identify the Uptrace OpenTelemetry implementation.
	// See: https://uptrace.dev/get/opentelemetry-go
	UptraceDriver = "uptrace"

	// LogDriver identifies a basic tracer that writes span information to logs.
	LogDriver = "log"
)
View Source
const ShutdownTimeout = 5 * time.Second

ShutdownTimeout ...

Variables

View Source
var (
	// ErrInvalidDriver indicates that the configured tracing driver name is not recognized or supported.
	ErrInvalidDriver = errors.New("invalid trace driver")
)

Functions

func New

func New(ctx context.Context) (t trace.Tracer, err error)

New initializes and returns the configured OpenTelemetry Tracer based on the application settings. If tracing is disabled in the configuration, it returns a no-op tracer.

func NewLogTracer

func NewLogTracer() trace.Tracer

NewLogTracer returns a new instance of Log tracer.

func NewNoOpTracer

func NewNoOpTracer() trace.Tracer

NewNoOpTracer initializes the OpenTelemetry global TracerProvider with a No-Operation (NoOp) provider.

A NoOp Tracer is used when tracing is explicitly disabled in the application configuration. It satisfies the OpenTelemetry interface but performs no tracing or data collection, ensuring that tracing calls in the application code do not cause errors or overhead.

func NewUptraceTracer

func NewUptraceTracer(ctx context.Context) trace.Tracer

NewUptraceTracer initializes and configures the OpenTelemetry tracing provider to send traces to Uptrace.

Types

type Log

type Log struct {
	noop.Tracer
}

Log is a custom OpenTelemetry Tracer implementation primarily used for debugging. It embeds noop.Tracer to satisfy the trace.Tracer interface without performing standard OpenTelemetry collection/export logic. Instead, it logs the caller's function name and file location when a span is started.

func (*Log) Start

func (t *Log) Start(ctx context.Context, _ string, _ ...trace.SpanStartOption) (context.Context, trace.Span)

Start implements the trace.Tracer interface method. Instead of creating a real distributed trace span, this method uses reflection (runtime.Caller) to determine the function and file line that called the tracer, and prints this information to the console for debugging purposes.

Jump to

Keyboard shortcuts

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