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 ¶
- Variables
- func GetSpanFromContext(ctx context.Context) span.Span
- func ShutdownTracerProvider(ctx context.Context) error
- func StarCustomTracer(customTracer oteltrace.Tracer)
- func StartDefaultTracer(ctx context.Context) error
- func StartSpan(ctx context.Context, name string, kind SpanKind) (context.Context, span.Span)
- type Code
- type KeyValue
- type SpanKind
- type Tracer
Constants ¶
This section is empty.
Variables ¶
var ErrExporterClientNotSupported = errors.New("exporter client not supported")
ErrExporterClientNotSupported is returned when the exporter client is not supported
var ErrTracerProviderAlreadyInitialized = errors.New("tracer provider already initialized")
ErrTracerProviderAlreadyInitialized is returned when the tracer provider is already initialized
var ErrTracerProviderNotInitialized = errors.New("tracer provider not initialized")
ErrTracerProviderNotInitialized is returned when the tracer provider is not initialized
Functions ¶
func GetSpanFromContext ¶
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 ¶
ShutdownTracerProvider gracefully shuts down the global TracerProvider.
func StarCustomTracer ¶ added in v1.3.0
StarCustomTracer only needed for testing purposes
func StartDefaultTracer ¶
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.
Types ¶
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.