Documentation
¶
Index ¶
- func ExtractGRPCContext(ctx context.Context) context.Context
- func ExtractHTTPContext(c *fiber.Ctx) context.Context
- func HandleSpanError(span *trace.Span, message string, err error)
- func InjectGRPCContext(ctx context.Context) context.Context
- func InjectHTTPContext(headers *http.Header, ctx context.Context)
- func ObfuscateStruct(valueStruct any, obfuscator FieldObfuscator) (any, error)
- func SetSpanAttributesFromStruct(span *trace.Span, key string, valueStruct any) error
- func SetSpanAttributesFromStructWithObfuscation(span *trace.Span, key string, valueStruct any, obfuscator FieldObfuscator) error
- type DefaultObfuscator
- type FieldObfuscator
- type Telemetry
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ExtractGRPCContext ¶ added in v1.17.0
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 ¶ added in v1.17.0
ExtractHTTPContext extracts OpenTelemetry trace context from incoming HTTP headers and injects it into the context. It works with Fiber's HTTP context.
func HandleSpanError ¶
HandleSpanError sets the status of the span to error and records the error.
func InjectGRPCContext ¶ added in v1.17.0
InjectGRPCContext injects OpenTelemetry trace context into outgoing gRPC metadata. It normalizes W3C trace headers to lowercase for gRPC compatibility.
func InjectHTTPContext ¶ added in v1.17.0
InjectHTTPContext modifies HTTP headers for trace propagation in outgoing client requests
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 SetSpanAttributesFromStruct ¶
SetSpanAttributesFromStruct converts a struct to a JSON string and sets it as an attribute on the span. This is the basic version without obfuscation for backward compatibility.
func SetSpanAttributesFromStructWithObfuscation ¶
func SetSpanAttributesFromStructWithObfuscation(span *trace.Span, key string, valueStruct any, obfuscator FieldObfuscator) error
SetSpanAttributesFromStructWithObfuscation converts a struct to a JSON string, obfuscates sensitive fields using the provided obfuscator, and sets it as an attribute on the span. If obfuscator is nil, no obfuscation is performed.
Types ¶
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 {
LibraryName string
ServiceName string
ServiceVersion string
DeploymentEnv string
CollectorExporterEndpoint string
TracerProvider *sdktrace.TracerProvider
MetricProvider *sdkmetric.MeterProvider
LoggerProvider *sdklog.LoggerProvider
EnableTelemetry bool
// contains filtered or unexported fields
}
func (*Telemetry) EndTracingSpans ¶ added in v1.17.0
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.