Documentation
¶
Index ¶
- 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 SetSpanAttributeForParam(c *fiber.Ctx, param, value, entityName string)
- 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 AttrBagSpanProcessor
- type DefaultObfuscator
- type FieldObfuscator
- type Telemetry
- type TelemetryConfig
Constants ¶
This section is empty.
Variables ¶
This section is empty.
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.3.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.3.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 SetSpanAttributeForParam ¶ added in v2.3.0
func SetSpanAttributeForParam(c *fiber.Ctx, param, value, entityName string)
SetSpanAttributeForParam sets a span attribute for a Fiber request parameter with consistent naming entityName is a snake_case string used to identify id name, for example the "organization" entity name will result in "app.request.organization_id" otherwise the path parameter "id" in a Fiber request for example "/v1/organizations/:id" will be parsed as "app.request.id"
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 AttrBagSpanProcessor ¶ added in v2.3.0
type AttrBagSpanProcessor struct{}
AttrBagSpanProcessor copies request-scoped attributes from context into every span at start.
func (AttrBagSpanProcessor) ForceFlush ¶ added in v2.3.0
func (AttrBagSpanProcessor) ForceFlush(ctx context.Context) error
func (AttrBagSpanProcessor) OnEnd ¶ added in v2.3.0
func (AttrBagSpanProcessor) OnEnd(s sdktrace.ReadOnlySpan)
func (AttrBagSpanProcessor) OnStart ¶ added in v2.3.0
func (AttrBagSpanProcessor) OnStart(ctx context.Context, s sdktrace.ReadWriteSpan)
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 Telemetry ¶
type Telemetry struct {
TelemetryConfig
TracerProvider *sdktrace.TracerProvider
MetricProvider *sdkmetric.MeterProvider
LoggerProvider *sdklog.LoggerProvider
MetricsFactory *metrics.MetricsFactory
// contains filtered or unexported fields
}
func InitializeTelemetry ¶ added in v2.3.0
func InitializeTelemetry(cfg *TelemetryConfig) *Telemetry
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) EndTracingSpans ¶
func (*Telemetry) ShutdownTelemetry ¶
func (tl *Telemetry) ShutdownTelemetry()
ShutdownTelemetry shuts down the telemetry providers and exporters.