Documentation
¶
Index ¶
- Variables
- func ExtractGRPCContext(ctx context.Context) context.Context
- func ExtractHTTPContext(c *fiber.Ctx) context.Context
- func ExtractQueueTraceContext(ctx context.Context, headers map[string]string) context.Context
- func ExtractTraceContextFromQueueHeaders(baseCtx context.Context, amqpHeaders map[string]any) context.Context
- func GetTraceIDFromContext(ctx context.Context) string
- func GetTraceStateFromContext(ctx context.Context) string
- func HandleSpanBusinessErrorEvent(span *trace.Span, eventName string, err error)
- func HandleSpanError(span *trace.Span, message string, err error)
- func HandleSpanEvent(span *trace.Span, eventName string, attributes ...attribute.KeyValue)
- func InjectGRPCContext(ctx context.Context) context.Context
- func InjectHTTPContext(headers *http.Header, ctx context.Context)
- func InjectQueueTraceContext(ctx context.Context) map[string]string
- func InjectTraceHeadersIntoQueue(ctx context.Context, headers *map[string]any)
- func ObfuscateStruct(valueStruct any, obfuscator FieldObfuscator) (any, error)
- func PrepareQueueHeaders(ctx context.Context, baseHeaders map[string]any) map[string]any
- func SetSpanAttributesFromStruct(span *trace.Span, key string, valueStruct any) error
- func SetSpanAttributesFromStructWithCustomObfuscation(span *trace.Span, key string, valueStruct any, obfuscator FieldObfuscator) errordeprecated
- func SetSpanAttributesFromStructWithObfuscation(span *trace.Span, key string, valueStruct any) errordeprecated
- type CounterBuilder
- type DefaultObfuscator
- type FieldObfuscator
- type GaugeBuilder
- type HistogramBuilder
- type MetricOption
- type MetricsFactory
- type Telemetry
Constants ¶
This section is empty.
Variables ¶
var ( // DefaultLatencyBuckets for latency measurements (in seconds) DefaultLatencyBuckets = []float64{0.001, 0.005, 0.01, 0.025, 0.05, 0.1, 0.25, 0.5, 1, 2.5, 5, 10} // DefaultAccountBuckets for account creation counts DefaultAccountBuckets = []float64{1, 5, 10, 25, 50, 100, 250, 500, 1000, 2500, 5000} // DefaultTransactionBuckets for transaction count per time period DefaultTransactionBuckets = []float64{1, 10, 50, 100, 500, 1000, 2500, 5000, 8000, 10000} )
Default histogram bucket configurations for different metric types
Functions ¶
func ExtractGRPCContext ¶
ExtractGRPCContext extracts OpenTelemetry trace context from incoming gRPC metadata and injects it into the context. It handles case normalization for W3C trace headers.
func ExtractHTTPContext ¶
ExtractHTTPContext extracts OpenTelemetry trace context from incoming HTTP headers and injects it into the context. It works with Fiber's HTTP context.
func ExtractQueueTraceContext ¶
ExtractQueueTraceContext extracts OpenTelemetry trace context from RabbitMQ headers and returns a new context with the extracted trace information. This enables distributed tracing continuity across queue message boundaries.
func ExtractTraceContextFromQueueHeaders ¶
func ExtractTraceContextFromQueueHeaders(baseCtx context.Context, amqpHeaders map[string]any) context.Context
ExtractTraceContextFromQueueHeaders extracts OpenTelemetry trace context from RabbitMQ amqp.Table headers and returns a new context with the extracted trace information. Handles type conversion automatically.
func GetTraceIDFromContext ¶
GetTraceIDFromContext extracts the trace ID from the current span context Returns empty string if no active span or trace ID is found
func GetTraceStateFromContext ¶
GetTraceStateFromContext extracts the trace state from the current span context Returns empty string if no active span or trace state is found
func HandleSpanBusinessErrorEvent ¶ added in v2.2.0
HandleSpanBusinessErrorEvent adds a business error event to the span.
func HandleSpanError ¶
HandleSpanError sets the status of the span to error and records the error.
func HandleSpanEvent ¶ added in v2.2.0
HandleSpanEvent adds an event to the span.
func InjectGRPCContext ¶
InjectGRPCContext injects OpenTelemetry trace context into outgoing gRPC metadata. It normalizes W3C trace headers to lowercase for gRPC compatibility.
func InjectHTTPContext ¶
InjectHTTPContext modifies HTTP headers for trace propagation in outgoing client requests
func InjectQueueTraceContext ¶
InjectQueueTraceContext injects OpenTelemetry trace context into RabbitMQ headers for distributed tracing across queue messages. Returns a map of headers to be added to the RabbitMQ message headers.
func InjectTraceHeadersIntoQueue ¶
InjectTraceHeadersIntoQueue adds OpenTelemetry trace headers to existing RabbitMQ headers following W3C trace context standards. Modifies the headers map in place.
func ObfuscateStruct ¶
func ObfuscateStruct(valueStruct any, obfuscator FieldObfuscator) (any, error)
ObfuscateStruct applies obfuscation to a struct and returns the obfuscated data. This is a utility function that can be used independently of OpenTelemetry spans.
func PrepareQueueHeaders ¶
PrepareQueueHeaders prepares RabbitMQ headers with trace context injection following W3C trace context standards. Returns a map suitable for amqp.Table.
func SetSpanAttributesFromStruct ¶ added in v2.1.0
SetSpanAttributesFromStruct converts a struct to a JSON string and sets it as an attribute on the span.
func SetSpanAttributesFromStructWithCustomObfuscation
deprecated
func SetSpanAttributesFromStructWithCustomObfuscation(span *trace.Span, key string, valueStruct any, obfuscator FieldObfuscator) error
Deprecated: Use SetSpanAttributesFromStruct instead.
SetSpanAttributesFromStructWithCustomObfuscation converts a struct to a JSON string, obfuscates sensitive fields using the custom obfuscator provided, and sets it as an attribute on the span.
func SetSpanAttributesFromStructWithObfuscation
deprecated
func SetSpanAttributesFromStructWithObfuscation(span *trace.Span, key string, valueStruct any) error
Deprecated: Use SetSpanAttributesFromStruct instead.
SetSpanAttributesFromStructWithObfuscation converts a struct to a JSON string, obfuscates sensitive fields using the default obfuscator, and sets it as an attribute on the span.
Types ¶
type CounterBuilder ¶
type CounterBuilder struct {
// contains filtered or unexported fields
}
CounterBuilder provides a fluent API for recording counter metrics with optional labels
func (*CounterBuilder) Add ¶
func (c *CounterBuilder) Add(ctx context.Context, value int64)
Add records a counter increment
func (*CounterBuilder) WithAttributes ¶
func (c *CounterBuilder) WithAttributes(attrs ...attribute.KeyValue) *CounterBuilder
WithAttributes adds OpenTelemetry attributes to the counter metric
func (*CounterBuilder) WithLabels ¶
func (c *CounterBuilder) WithLabels(labels map[string]string) *CounterBuilder
WithLabels adds labels/attributes to the counter metric
type DefaultObfuscator ¶
type DefaultObfuscator struct {
// contains filtered or unexported fields
}
DefaultObfuscator provides a simple implementation that obfuscates common sensitive field names using a predefined list.
func NewCustomObfuscator ¶
func NewCustomObfuscator(sensitiveFields []string) *DefaultObfuscator
NewCustomObfuscator creates a new DefaultObfuscator with custom sensitive field names.
func NewDefaultObfuscator ¶
func NewDefaultObfuscator() *DefaultObfuscator
NewDefaultObfuscator creates a new DefaultObfuscator with common sensitive field names. Uses the shared sensitive fields list from the security package to ensure consistency across HTTP logging, OpenTelemetry spans, and other components.
func (*DefaultObfuscator) GetObfuscatedValue ¶
func (o *DefaultObfuscator) GetObfuscatedValue() string
GetObfuscatedValue returns the obfuscated value.
func (*DefaultObfuscator) ShouldObfuscate ¶
func (o *DefaultObfuscator) ShouldObfuscate(fieldName string) bool
ShouldObfuscate returns true if the field name is in the sensitive fields list.
type FieldObfuscator ¶
type FieldObfuscator interface {
// ShouldObfuscate returns true if the given field name should be obfuscated
ShouldObfuscate(fieldName string) bool
// GetObfuscatedValue returns the value to use for obfuscated fields
GetObfuscatedValue() string
}
FieldObfuscator defines the interface for obfuscating sensitive fields in structs. Implementations can provide custom logic for determining which fields to obfuscate and how to obfuscate them.
type GaugeBuilder ¶
type GaugeBuilder struct {
// contains filtered or unexported fields
}
GaugeBuilder provides a fluent API for recording gauge metrics with optional labels
func (*GaugeBuilder) Record ¶
func (g *GaugeBuilder) Record(ctx context.Context, value int64)
Record sets the gauge value
func (*GaugeBuilder) Set ¶
func (g *GaugeBuilder) Set(ctx context.Context, value int64)
Set is an alias for Record for gauge metrics (more intuitive naming)
func (*GaugeBuilder) WithAttributes ¶
func (g *GaugeBuilder) WithAttributes(attrs ...attribute.KeyValue) *GaugeBuilder
WithAttributes adds OpenTelemetry attributes to the gauge metric
func (*GaugeBuilder) WithLabels ¶
func (g *GaugeBuilder) WithLabels(labels map[string]string) *GaugeBuilder
WithLabels adds labels/attributes to the gauge metric
type HistogramBuilder ¶
type HistogramBuilder struct {
// contains filtered or unexported fields
}
HistogramBuilder provides a fluent API for recording histogram metrics with optional labels
func (*HistogramBuilder) Record ¶
func (h *HistogramBuilder) Record(ctx context.Context, value int64)
Record records a histogram value
func (*HistogramBuilder) WithAttributes ¶
func (h *HistogramBuilder) WithAttributes(attrs ...attribute.KeyValue) *HistogramBuilder
WithAttributes adds OpenTelemetry attributes to the histogram metric
func (*HistogramBuilder) WithLabels ¶
func (h *HistogramBuilder) WithLabels(labels map[string]string) *HistogramBuilder
WithLabels adds labels/attributes to the histogram metric
type MetricOption ¶
type MetricOption struct {
Description string
Unit string
// For histograms: bucket boundaries
Buckets []float64
}
MetricOption configures metric creation options
type MetricsFactory ¶
type MetricsFactory struct {
// contains filtered or unexported fields
}
MetricsFactory provides a thread-safe factory for creating and managing OpenTelemetry metrics with lazy initialization using sync.Map for high-performance concurrent access.
func NewMetricsFactory ¶
func NewMetricsFactory(meter metric.Meter, logger log.Logger) *MetricsFactory
NewMetricsFactory creates a new MetricsFactory instance
func (*MetricsFactory) Counter ¶
func (f *MetricsFactory) Counter(name string, opts ...MetricOption) *CounterBuilder
Counter creates or retrieves a counter metric and returns a builder for fluent API usage
func (*MetricsFactory) Gauge ¶
func (f *MetricsFactory) Gauge(name string, opts ...MetricOption) *GaugeBuilder
Gauge creates or retrieves a gauge metric and returns a builder for fluent API usage
func (*MetricsFactory) Histogram ¶
func (f *MetricsFactory) Histogram(name string, opts ...MetricOption) *HistogramBuilder
Histogram creates or retrieves a histogram metric and returns a builder for fluent API usage
type Telemetry ¶
type Telemetry struct {
LibraryName string
ServiceName string
ServiceVersion string
DeploymentEnv string
CollectorExporterEndpoint string
TracerProvider *sdktrace.TracerProvider
MetricProvider *sdkmetric.MeterProvider
LoggerProvider *sdklog.LoggerProvider
MetricsFactory *MetricsFactory
EnableTelemetry bool
// contains filtered or unexported fields
}
func (*Telemetry) EndTracingSpans ¶
func (*Telemetry) InitializeTelemetry ¶
InitializeTelemetry initializes the telemetry providers and sets them globally. (Logger is being passed as a parameter because it not exists in the global context at this point to be injected)
func (*Telemetry) ShutdownTelemetry ¶
func (tl *Telemetry) ShutdownTelemetry()
ShutdownTelemetry shuts down the telemetry providers and exporters.