Documentation
¶
Index ¶
- Constants
- Variables
- func AddSpanEvent(span trace.Span, name string, attrs ...attribute.KeyValue)
- func BrokerAttributes(brokerID uint64, host string, port uint16) []attribute.KeyValue
- func ConsumerAttributes(groupID, consumerID string) []attribute.KeyValue
- func ContextWithSpan(ctx context.Context, span trace.Span) context.Context
- func ErrorAttributes(errorType, message string, code int) []attribute.KeyValue
- func HeaderCarrierFromMap(m map[string]string) propagation.TextMapCarrier
- func MessageAttributes(key string, size int, offset int64) []attribute.KeyValue
- func PartitionAttributes(partitionID uint32, offset int64) []attribute.KeyValue
- func RecordError(span trace.Span, err error)
- func RequestAttributes(requestID uint64, requestType string) []attribute.KeyValue
- func SchemaAttributes(schemaID uint64, version uint32, schemaType string) []attribute.KeyValue
- func SetSpanAttributes(span trace.Span, attrs ...attribute.KeyValue)
- func SetSpanStatus(span trace.Span, code codes.Code, description string)
- func SpanContextFromContext(ctx context.Context) trace.SpanContext
- func SpanFromContext(ctx context.Context) trace.Span
- func StartSpan(ctx context.Context, tracer trace.Tracer, name string, opts ...SpanOption) (context.Context, trace.Span)
- func TopicAttributes(name string, partitions, replicas uint32) []attribute.KeyValue
- func TransactionAttributes(txID, status string) []attribute.KeyValue
- type Config
- type ExporterConfig
- type ExporterType
- type JaegerConfig
- type OTLPConfig
- type SamplingConfig
- type SpanOption
- type Tracer
- func (t *Tracer) AddEvent(ctx context.Context, name string, attrs map[string]interface{})
- func (t *Tracer) Extract(ctx context.Context, carrier propagation.TextMapCarrier) context.Context
- func (t *Tracer) ExtractTraceContext(ctx context.Context, headers map[string]string) context.Context
- func (t *Tracer) HTTPMiddleware(next http.Handler) http.Handler
- func (t *Tracer) Inject(ctx context.Context, carrier propagation.TextMapCarrier)
- func (t *Tracer) InjectTraceContext(ctx context.Context, headers map[string]string)
- func (t *Tracer) InstrumentedOperation(ctx context.Context, operationName string, fn func(context.Context) error) error
- func (t *Tracer) IsEnabled() bool
- func (t *Tracer) MeasureDuration(ctx context.Context, operation string, fn func() error) error
- func (t *Tracer) RecordError(ctx context.Context, err error, attrs map[string]interface{})
- func (t *Tracer) RecordMetric(ctx context.Context, metricName string, value interface{}, unit string)
- func (t *Tracer) SetAttributes(ctx context.Context, attrs map[string]interface{})
- func (t *Tracer) Shutdown(ctx context.Context) error
- func (t *Tracer) Start(ctx context.Context, spanName string, opts ...trace.SpanStartOption) (context.Context, trace.Span)
- func (t *Tracer) StartWithAttributes(ctx context.Context, spanName string, attrs map[string]interface{}) (context.Context, trace.Span)
- func (t *Tracer) TraceConsumeMessage(ctx context.Context, topic string, partition uint32, offset int64) (context.Context, trace.Span)
- func (t *Tracer) TraceNetworkRequest(ctx context.Context, operation, targetBroker string) (context.Context, trace.Span)
- func (t *Tracer) TraceProduceMessage(ctx context.Context, topic string, partition uint32, key, value []byte) (context.Context, trace.Span)
- func (t *Tracer) TraceRaftOperation(ctx context.Context, operation string, term, index int64) (context.Context, trace.Span)
- func (t *Tracer) TraceStorageOperation(ctx context.Context, operation, component string) (context.Context, trace.Span)
- func (t *Tracer) TraceWithRetry(ctx context.Context, operation string, maxRetries int, ...) error
- type ZipkinConfig
Constants ¶
const ( // Broker attributes AttrBrokerID = attribute.Key("streambus.broker.id") AttrBrokerHost = attribute.Key("streambus.broker.host") AttrBrokerPort = attribute.Key("streambus.broker.port") // Topic attributes AttrTopicName = attribute.Key("streambus.topic.name") AttrTopicPartitions = attribute.Key("streambus.topic.partitions") AttrTopicReplicas = attribute.Key("streambus.topic.replicas") // Partition attributes AttrPartitionID = attribute.Key("streambus.partition.id") AttrPartitionOffset = attribute.Key("streambus.partition.offset") // Message attributes AttrMessageKey = attribute.Key("streambus.message.key") AttrMessageSize = attribute.Key("streambus.message.size") AttrMessageCount = attribute.Key("streambus.message.count") AttrMessageOffset = attribute.Key("streambus.message.offset") AttrMessageBatch = attribute.Key("streambus.message.batch") // Consumer attributes AttrConsumerGroup = attribute.Key("streambus.consumer.group") AttrConsumerID = attribute.Key("streambus.consumer.id") AttrConsumerMember = attribute.Key("streambus.consumer.member") // Transaction attributes AttrTransactionID = attribute.Key("streambus.transaction.id") AttrTransactionStatus = attribute.Key("streambus.transaction.status") // Request attributes AttrRequestID = attribute.Key("streambus.request.id") AttrRequestType = attribute.Key("streambus.request.type") // Schema attributes AttrSchemaID = attribute.Key("streambus.schema.id") AttrSchemaVersion = attribute.Key("streambus.schema.version") AttrSchemaType = attribute.Key("streambus.schema.type") // Error attributes AttrErrorType = attribute.Key("streambus.error.type") AttrErrorMessage = attribute.Key("streambus.error.message") AttrErrorCode = attribute.Key("streambus.error.code") )
Common attribute keys for StreamBus operations
Variables ¶
var ( // ErrTracerNotInitialized is returned when tracer is not initialized ErrTracerNotInitialized = errors.New("tracer not initialized") // ErrInvalidServiceName is returned when service name is invalid ErrInvalidServiceName = errors.New("invalid service name") // ErrInvalidSamplingRate is returned when sampling rate is invalid ErrInvalidSamplingRate = errors.New("invalid sampling rate: must be between 0.0 and 1.0") // ErrInvalidExporterType is returned when exporter type is invalid ErrInvalidExporterType = errors.New("invalid exporter type") // ErrInvalidOTLPEndpoint is returned when OTLP endpoint is invalid ErrInvalidOTLPEndpoint = errors.New("invalid OTLP endpoint") // ErrInvalidJaegerEndpoint is returned when Jaeger endpoint is invalid ErrInvalidJaegerEndpoint = errors.New("invalid Jaeger endpoint: must specify agent or collector endpoint") // ErrInvalidZipkinEndpoint is returned when Zipkin endpoint is invalid ErrInvalidZipkinEndpoint = errors.New("invalid Zipkin endpoint") // ErrExporterShutdownFailed is returned when exporter shutdown fails ErrExporterShutdownFailed = errors.New("exporter shutdown failed") // ErrTracerProviderShutdownFailed is returned when tracer provider shutdown fails ErrTracerProviderShutdownFailed = errors.New("tracer provider shutdown failed") )
Functions ¶
func AddSpanEvent ¶
AddSpanEvent adds an event to a span
func BrokerAttributes ¶
BrokerAttributes creates broker-related attributes
func ConsumerAttributes ¶
ConsumerAttributes creates consumer-related attributes
func ContextWithSpan ¶
ContextWithSpan returns a context with the given span
func ErrorAttributes ¶
ErrorAttributes creates error-related attributes
func HeaderCarrierFromMap ¶
func HeaderCarrierFromMap(m map[string]string) propagation.TextMapCarrier
HeaderCarrierFromMap creates a propagation carrier from a map
func MessageAttributes ¶
MessageAttributes creates message-related attributes
func PartitionAttributes ¶
PartitionAttributes creates partition-related attributes
func RecordError ¶
RecordError records an error on the span
func RequestAttributes ¶
RequestAttributes creates request-related attributes
func SchemaAttributes ¶
SchemaAttributes creates schema-related attributes
func SetSpanAttributes ¶
SetSpanAttributes sets multiple attributes on a span
func SetSpanStatus ¶
SetSpanStatus sets the status of a span
func SpanContextFromContext ¶
func SpanContextFromContext(ctx context.Context) trace.SpanContext
SpanContextFromContext returns the span context from the context
func SpanFromContext ¶
SpanFromContext returns the span from the context
func StartSpan ¶
func StartSpan(ctx context.Context, tracer trace.Tracer, name string, opts ...SpanOption) (context.Context, trace.Span)
StartSpan starts a new span with the given name and options
func TopicAttributes ¶
TopicAttributes creates topic-related attributes
func TransactionAttributes ¶
TransactionAttributes creates transaction-related attributes
Types ¶
type Config ¶
type Config struct {
// Enable tracing
Enabled bool
// Service name for traces
ServiceName string
// Service version
ServiceVersion string
// Environment (dev, staging, prod)
Environment string
// Exporter configuration
Exporter ExporterConfig
// Sampling configuration
Sampling SamplingConfig
// Resource attributes
ResourceAttributes map[string]string
// Propagators (tracecontext, baggage, b3, jaeger, etc.)
Propagators []string
}
Config holds tracing configuration
func DefaultConfig ¶
func DefaultConfig() *Config
DefaultConfig returns default tracing configuration
func (*Config) ToResourceAttributes ¶
ToResourceAttributes converts resource attributes to OpenTelemetry attributes
type ExporterConfig ¶
type ExporterConfig struct {
// Exporter type (otlp, jaeger, zipkin, stdout)
Type ExporterType
// OTLP configuration
OTLP OTLPConfig
// Jaeger configuration
Jaeger JaegerConfig
// Zipkin configuration
Zipkin ZipkinConfig
}
ExporterConfig holds exporter configuration
type ExporterType ¶
type ExporterType string
ExporterType represents the type of trace exporter
const ( // ExporterTypeOTLP exports to OTLP endpoint (OpenTelemetry Collector) ExporterTypeOTLP ExporterType = "otlp" // ExporterTypeJaeger exports to Jaeger ExporterTypeJaeger ExporterType = "jaeger" // ExporterTypeZipkin exports to Zipkin ExporterTypeZipkin ExporterType = "zipkin" // ExporterTypeStdout exports to stdout (for debugging) ExporterTypeStdout ExporterType = "stdout" // ExporterTypeNone disables exporting ExporterTypeNone ExporterType = "none" )
type JaegerConfig ¶
type JaegerConfig struct {
// Agent endpoint (e.g., "localhost:6831")
AgentEndpoint string
// Collector endpoint (e.g., "http://localhost:14268/api/traces")
CollectorEndpoint string
// Username for authentication
Username string
// Password for authentication
Password string
}
JaegerConfig holds Jaeger exporter configuration
type OTLPConfig ¶
type OTLPConfig struct {
// Endpoint (e.g., "localhost:4317")
Endpoint string
// Use insecure connection
Insecure bool
// Headers to send with requests
Headers map[string]string
// Timeout for exporting
Timeout time.Duration
// Compression (gzip, none)
Compression string
}
OTLPConfig holds OTLP exporter configuration
type SamplingConfig ¶
type SamplingConfig struct {
// Sampling rate (0.0 to 1.0)
// 1.0 = sample all traces, 0.1 = sample 10% of traces
SamplingRate float64
// Parent-based sampling
ParentBased bool
}
SamplingConfig holds sampling configuration
type SpanOption ¶
type SpanOption func(*spanConfig)
SpanOption is a functional option for configuring spans
func WithAttributes ¶
func WithAttributes(attrs ...attribute.KeyValue) SpanOption
WithAttributes adds attributes to a span
func WithSpanKind ¶
func WithSpanKind(kind trace.SpanKind) SpanOption
WithSpanKind sets the span kind
type Tracer ¶
type Tracer struct {
// contains filtered or unexported fields
}
Tracer wraps OpenTelemetry tracer
func (*Tracer) Extract ¶
func (t *Tracer) Extract(ctx context.Context, carrier propagation.TextMapCarrier) context.Context
Extract extracts the trace context from a carrier
func (*Tracer) ExtractTraceContext ¶
func (t *Tracer) ExtractTraceContext(ctx context.Context, headers map[string]string) context.Context
ExtractTraceContext extracts trace context from a map (from message headers)
func (*Tracer) HTTPMiddleware ¶
HTTPMiddleware returns an HTTP middleware that traces requests
func (*Tracer) Inject ¶
func (t *Tracer) Inject(ctx context.Context, carrier propagation.TextMapCarrier)
Inject injects the trace context into a carrier
func (*Tracer) InjectTraceContext ¶
InjectTraceContext injects trace context into a map (for message headers)
func (*Tracer) InstrumentedOperation ¶
func (t *Tracer) InstrumentedOperation(ctx context.Context, operationName string, fn func(context.Context) error) error
InstrumentedOperation runs an operation with tracing
func (*Tracer) MeasureDuration ¶
MeasureDuration measures operation duration and records it
func (*Tracer) RecordError ¶
RecordError records an error in the current span
func (*Tracer) RecordMetric ¶
func (t *Tracer) RecordMetric(ctx context.Context, metricName string, value interface{}, unit string)
RecordMetric records a metric as a span event
func (*Tracer) SetAttributes ¶
SetAttributes sets attributes on the current span
func (*Tracer) Start ¶
func (t *Tracer) Start(ctx context.Context, spanName string, opts ...trace.SpanStartOption) (context.Context, trace.Span)
Start starts a new span
func (*Tracer) StartWithAttributes ¶
func (t *Tracer) StartWithAttributes(ctx context.Context, spanName string, attrs map[string]interface{}) (context.Context, trace.Span)
StartWithAttributes starts a new span with attributes
func (*Tracer) TraceConsumeMessage ¶
func (t *Tracer) TraceConsumeMessage(ctx context.Context, topic string, partition uint32, offset int64) (context.Context, trace.Span)
TraceConsumeMessage traces message consumption
func (*Tracer) TraceNetworkRequest ¶
func (t *Tracer) TraceNetworkRequest(ctx context.Context, operation, targetBroker string) (context.Context, trace.Span)
TraceNetworkRequest traces network requests between brokers
func (*Tracer) TraceProduceMessage ¶
func (t *Tracer) TraceProduceMessage(ctx context.Context, topic string, partition uint32, key, value []byte) (context.Context, trace.Span)
TraceProduceMessage traces message production
func (*Tracer) TraceRaftOperation ¶
func (t *Tracer) TraceRaftOperation(ctx context.Context, operation string, term, index int64) (context.Context, trace.Span)
TraceRaftOperation traces Raft consensus operations
type ZipkinConfig ¶
type ZipkinConfig struct {
// Endpoint (e.g., "http://localhost:9411/api/v2/spans")
Endpoint string
// Timeout for exporting
Timeout time.Duration
}
ZipkinConfig holds Zipkin exporter configuration