tracer

package
v1.5.1 Latest Latest
Warning

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

Go to latest
Published: Mar 20, 2026 License: MIT Imports: 18 Imported by: 0

Documentation

Overview

Package tracer provides a simple way to create a new Otel tracer. The package also provides an easy way to create spans. Both the Otel Span and Tracer are exposed to allow for more advanced use cases.

Index

Constants

This section is empty.

Variables

View Source
var ErrExporterClientNotSupported = errors.New("exporter client not supported")

ErrExporterClientNotSupported is returned when the exporter client is not supported

View Source
var ErrTracerProviderAlreadyInitialized = errors.New("tracer provider already initialized")

ErrTracerProviderAlreadyInitialized is returned when the tracer provider is already initialized

View Source
var ErrTracerProviderNotInitialized = errors.New("tracer provider not initialized")

ErrTracerProviderNotInitialized is returned when the tracer provider is not initialized

Functions

func GetSpanFromContext

func GetSpanFromContext(ctx context.Context) span.Span

GetSpanFromContext retrieves the current Span from the context.

This allows access to tracing information within that context. If no span is associated with the context, it returns a non-recording span, which is a placeholder that performs no operations. This is useful for tracing operations where span context is required.

Returns the current Span.

func ShutdownTracerProvider

func ShutdownTracerProvider(ctx context.Context) error

ShutdownTracerProvider gracefully shuts down the global TracerProvider.

func StarCustomTracer added in v1.3.0

func StarCustomTracer(customTracer oteltrace.Tracer)

StarCustomTracer only needed for testing purposes

func StartDefaultTracer

func StartDefaultTracer(ctx context.Context) error

StartDefaultTracer initializes and starts the default OpenTelemetry Tracer.

This function checks if tracing is enabled in the provided configuration. If tracing is enabled, It creates a new Tracer by using the default TraceProvider. It also validates that the tracer name (the service name in that case) is set in the configuration. If the tracer name is not provided, a noop Tracer is initialised as a default.

The function also sets the global default tracer to be used for tracing in the application. If tracing is not enabled, it returns nil without starting a tracer.

It returns an error if any occurred.

func StartSpan

func StartSpan(ctx context.Context, name string, kind SpanKind) (context.Context, span.Span)

StartSpan starts a new span with the given name and kind

It is using the default tracer. To start a new default tracer, first the function tracer.StartDefaultTracer(...) should be called.

It returns the new context and the new span

Types

type Code

type Code = codes.Code

type KeyValue

type KeyValue = attribute.KeyValue

type SpanKind

type SpanKind = oteltrace.SpanKind

type Tracer

type Tracer struct {
	// contains filtered or unexported fields
}

Tracer is a wrapper around the OpenTelemetry Tracer

func (*Tracer) StartSpan

func (t *Tracer) StartSpan(parentCtx context.Context, name string, kind SpanKind) (context.Context, internalSpan.Span)

StartSpan begins a new span for tracing with the specified name and kind.

This method takes a context, a span name, and a span kind as arguments. It checks if the Tracer instance is not nil, then starts a new span using the Tracer's Start method. The caller's information is added to the span's attributes to provide context about where the span was created. The function returns the updated context and a Span object that wraps the created span.

It returns the new context and the Span.

Jump to

Keyboard shortcuts

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