Documentation ¶
Index ¶
- Constants
- func AddBaggageItem(ctx context.Context, key, value string) context.Context
- func AddBaggageItems(ctx context.Context, items map[string]string) context.Context
- func Attribute(k string, v any) attribute.KeyValue
- func Extract(ctx context.Context, kv map[string]string) context.Context
- func ExtractHTTPHeaders(ctx context.Context, headers http.Header) context.Context
- func GetBaggage(ctx context.Context) baggage.Baggage
- func GetBaggageItem(ctx context.Context, key string) string
- func Inject(ctx context.Context, kv map[string]string)
- func InjectHTTPHeaders(ctx context.Context, headers http.Header)
- func LogAttribute(k string, v any) log.KeyValue
- func RemoveBaggageItem(ctx context.Context, key string) context.Context
- type Collector
- type Config
- type Log
- type LoggerOptions
- type Metric
- type MetricOptions
- type Service
- type Span
- type Telemetry
- type Trace
- type TracerOptions
Constants ¶
const ( Debug = "DEBUG" Info = "INFO" Warn = "WARN" Error = "ERROR" Fatal = "FATAL" )
Variables ¶
This section is empty.
Functions ¶
func AddBaggageItem ¶
AddBaggageItem adds a key-value pair to the baggage.
func AddBaggageItems ¶
AddBaggageItems adds multiple key-value pairs to the baggage.
func ExtractHTTPHeaders ¶
func GetBaggage ¶
GetBaggage retrieves the baggage from the context.
func GetBaggageItem ¶
GetBaggageItem retrieves the value of a baggage item by key.
Types ¶
type Config ¶
type Config struct { // Service configuration. Service // Collector configuration. Collector // Flag to enable tracing. WithTraces bool // Flag to enable metrics. WithMetrics bool // Flag to enable logging. WithLogs bool // Options for resource configuration. ResourceOptions []sdkresource.Option // Options for tracer configuration. TracerOptions TracerOptions // Options for logger configuration. LoggerOptions LoggerOptions // Options for metric configuration. MetricOptions MetricOptions }
Config holds the configuration for the telemetry setup.
type Log ¶
type Log interface { // Log returns the original logger. Log() log.Logger // original logger Debug(ctx context.Context, msg string, kv ...log.KeyValue) Info(ctx context.Context, msg string, kv ...log.KeyValue) Warning(ctx context.Context, msg string, kv ...log.KeyValue) Error(ctx context.Context, msg string, kv ...log.KeyValue) Fatal(ctx context.Context, msg string, kv ...log.KeyValue) }
Log interface provides methods for logging operations.
type LoggerOptions ¶
type LoggerOptions struct { // Options for the OTLP log exporter. ExporterOption []otlploggrpc.Option // Options for the logger provider. ProviderOption []sdklog.LoggerProviderOption // Options for the logger. LoggerOption []log.LoggerOption }
LoggerOptions holds the options for logger configuration.
type Metric ¶
type Metric interface { // Metric returns the underlying OpenTelemetry meter. Metric() metric.Meter Int64Counter(name string, options ...metric.Int64CounterOption) (metric.Int64Counter, error) Int64UpDownCounter(name string, options ...metric.Int64UpDownCounterOption) (metric.Int64UpDownCounter, error) Int64Histogram(name string, options ...metric.Int64HistogramOption) (metric.Int64Histogram, error) Int64Gauge(name string, options ...metric.Int64GaugeOption) (metric.Int64Gauge, error) Int64ObservableCounter(name string, options ...metric.Int64ObservableCounterOption) (metric.Int64ObservableCounter, error) Int64ObservableUpDownCounter(name string, options ...metric.Int64ObservableUpDownCounterOption) (metric.Int64ObservableUpDownCounter, error) Int64ObservableGauge(name string, options ...metric.Int64ObservableGaugeOption) (metric.Int64ObservableGauge, error) Float64Counter(name string, options ...metric.Float64CounterOption) (metric.Float64Counter, error) Float64UpDownCounter(name string, options ...metric.Float64UpDownCounterOption) (metric.Float64UpDownCounter, error) Float64Histogram(name string, options ...metric.Float64HistogramOption) (metric.Float64Histogram, error) Float64Gauge(name string, options ...metric.Float64GaugeOption) (metric.Float64Gauge, error) Float64ObservableCounter(name string, options ...metric.Float64ObservableCounterOption) (metric.Float64ObservableCounter, error) Float64ObservableUpDownCounter(name string, options ...metric.Float64ObservableUpDownCounterOption) (metric.Float64ObservableUpDownCounter, error) Float64ObservableGauge(name string, options ...metric.Float64ObservableGaugeOption) (metric.Float64ObservableGauge, error) RegisterCallback(f metric.Callback, instruments ...metric.Observable) (metric.Registration, error) }
Metric interface provides methods for creating and managing various types of metrics.
type MetricOptions ¶
type MetricOptions struct { // Options for the OTLP metric exporter. ExporterOptions []otlpmetricgrpc.Option // Options for the metric provider. ProviderOptions []sdkmetric.Option // Options for the meter. MeterOptions []metric.MeterOption }
MetricOptions holds the options for metric configuration.
type Service ¶
type Service struct { // Name of the service. Name string // Namespace of the service. Namespace string // Version of the service. Version string }
Service holds the service-related configuration.
type Span ¶
type Span interface { // Span returns the underlying OpenTelemetry span. Span() trace.Span // think about naming // AddEvent adds an event to the span with the given name and attributes. AddEvent(name string, kv ...attribute.KeyValue) // AddErrorEvent adds an error event to the span with the given name, error, and attributes. AddErrorEvent(name string, err error, kv ...attribute.KeyValue) // SetAttribute sets an attribute on the span. SetAttribute(kv ...attribute.KeyValue) // End ends the span with the given options. End(opts ...trace.SpanEndOption) // aka Finish() // RecordError records an error on the span with the given attributes. RecordError(err error, kv ...attribute.KeyValue) // TraceID returns the trace ID of the span. TraceID() string // SpanID returns the span ID of the span. SpanID() string }
Span represents an OpenTelemetry span and provides methods to interact with it.
type Telemetry ¶
type Telemetry interface { // Trace returns the tracer instance. Trace() Trace // Log returns the logger instance. Log() Log // Metric returns the meter instance. Metric() Metric // Shutdown gracefully shuts down the telemetry providers. Shutdown(ctx context.Context) error }
Telemetry implements the OpenTelemetry API. It provides methods to start spans, log messages, and create metrics.
Example: t.Trace().StartSpan(ctx, "name") t.Log().Info(ctx, "message") t.Metric().NewInt64Counter("name")
type Trace ¶
type Trace interface { // Trace returns the original tracer. Trace() trace.Tracer // original trace // StartSpan starts a new span with the given name and options. StartSpan(ctx context.Context, name string, opts ...trace.SpanStartOption) (context.Context, Span) // SpanFromContext retrieves the span from the given context. SpanFromContext(ctx context.Context) Span // ContextWithSpan returns a new context with the given span. ContextWithSpan(ctx context.Context, span trace.Span) context.Context // ContextWithRemoteSpanContext returns a new context with the remote span context. ContextWithRemoteSpanContext(ctx context.Context, span trace.Span) context.Context }
Trace interface provides methods for tracing operations.
type TracerOptions ¶
type TracerOptions struct { // Options for the OTLP trace client. ClientOption []otlptracegrpc.Option // Options for the tracer provider. ProviderOption []sdktrace.TracerProviderOption // Options for the batch span processor. BatchSpanProcessorOption []sdktrace.BatchSpanProcessorOption // Options for the tracer. TracerOption []trace.TracerOption }
TracerOptions holds the options for tracer configuration.