oteltracer

package
v0.0.0-...-2218a28 Latest Latest
Warning

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

Go to latest
Published: Feb 16, 2025 License: Apache-2.0 Imports: 15 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrOTLPEndpointRequired = errors.New("endpoint must be provided")
View Source
var ErrUnsupportedEndpoint = errors.New("unsupported: Endpoint must contain port 4318 (HTTP) or 4317 (gRPC)")

Functions

This section is empty.

Types

type AppInfo

type AppInfo struct {
	Host    string
	Port    string
	Name    string
	Version string
	Env     string
}

type Config

type Config struct {
	Endpoint string `mapstructure:"endpoint"`
}

type OpenTelemetry

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

OpenTelemetry encapsulates the OpenTelemetry components required for distributed tracing. It provides a tracer instance for span creation and a tracer provider for managing lifecycle and configurations. This struct facilitates the seamless integration of OpenTelemetry into applications.

func New

func New(ops Options) *OpenTelemetry

New creates a new instance of OpenTelemetry with the provided configuration.

func (*OpenTelemetry) Configure

func (o *OpenTelemetry) Configure() error

Configure initializes the OpenTelemetry by setting up the tracer provider and exporter.

func (*OpenTelemetry) Shutdown

func (o *OpenTelemetry) Shutdown(ctx context.Context) error

Shutdown gracefully shuts down the tracer provider and flushes any remaining spans to the exporter.

func (*OpenTelemetry) Span

func (o *OpenTelemetry) Span(
	ctx context.Context,
	name string,
) (context.Context, contract.Span)

Span creates and starts a new span with the specified name and attributes.

type Options

type Options struct {
	Config  Config
	AppInfo AppInfo
}

type Span

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

Span wraps a trace.Span and provides additional utility methods to manage and enrich the span with attributes, events, and errors.

func NewSpan

func NewSpan(span trace.Span) *Span

NewSpan creates a new Span instance by wrapping the provided trace.Span.

func (*Span) AddEvent

func (s *Span) AddEvent(name string, attrs ...map[string]interface{})

AddEvent adds an event to the span, optionally with attributes. Attributes can be provided as one or more maps of key-value pairs. If no attributes are provided, only the event name is added.

func (*Span) End

func (s *Span) End(enableStackTrace ...bool)

End ends the span, optionally enabling stack trace capture. If no argument is provided, stack trace capture is disabled by default.

func (*Span) RecordError

func (s *Span) RecordError(err error, attrs ...map[string]interface{})

RecordError records an error on the span, optionally with attributes. Attributes can be provided as one or more maps of key-value pairs. This is useful for adding context to the error being recorded.

func (*Span) SetAttribute

func (s *Span) SetAttribute(key, value string)

SetAttribute set attribute on the span. Attribute are passed as key-value pair and converted into OpenTelemetry-compatible attribute.

func (*Span) SetAttributes

func (s *Span) SetAttributes(attrs map[string]interface{})

SetAttributes sets multiple attributes on the span. Attributes are passed as a map of key-value pairs and are converted into OpenTelemetry-compatible attributes.

func (*Span) SetName

func (s *Span) SetName(name string)

SetName updates the name of the span. This is useful when the span name needs to be dynamically changed based on runtime information.

func (*Span) SetStatus

func (s *Span) SetStatus(code uint32, description string)

SetStatus sets the status of the span. The status is represented by a code (e.g., OK, ERROR) and a description providing additional context.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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