Documentation
¶
Overview ¶
Package otelutils contain reusable utilities for OpenTelemetry attributes.
Index ¶
- Constants
- Variables
- func ExtractTelemetryHeaders(httpHeaders http.Header, sensitivePatterns []string, allowedHeaders ...string) [][]string
- func GetLogger(ctx context.Context) *slog.Logger
- func GetLoggerFromContext(ctx context.Context) (*slog.Logger, bool)
- func IsContentTypeDebuggable(contentType string) bool
- func IsSensitiveHeader(name string, patterns ...string) bool
- func NewContextWithLogger(parentContext context.Context, logger *slog.Logger) context.Context
- func NewHeaderLogGroupAttrs(key string, headers http.Header) slog.Attr
- func NewHeaderMatrixLogGroupAttrs(key string, headers [][]string) slog.Attr
- func NewJSONLogger(logLevel string) (*slog.Logger, slog.Level, error)
- func NormalizeStrings(values []string) []string
- func SetSpanHeaderAttributes(span trace.Span, prefix string, headers map[string][]string, ...)
- func SetSpanHeaderMatrixAttributes(span trace.Span, prefix string, headers [][]string, allowedHeaders ...string)
- func SplitHostPort(hostport string, urlScheme string) (string, int, error)
Constants ¶
const MaskString = "[REDACTED]"
MaskString is the constant string for masking sensitive data.
Variables ¶
var LoggerContextKey = &contextKey{"LogEntry"}
LoggerContextKey is the global context key constant.
var UserVisibilityAttribute = attribute.String("internal.visibility", "user")
UserVisibilityAttribute is the attribute to display on the Trace view.
Functions ¶
func ExtractTelemetryHeaders ¶ added in v0.7.1
func ExtractTelemetryHeaders( httpHeaders http.Header, sensitivePatterns []string, allowedHeaders ...string, ) [][]string
ExtractTelemetryHeaders creates matrix with sensitive values masked.
func GetLogger ¶ added in v0.6.3
GetLogger gets the logger instance from context. If not exists, return the default logger.
func GetLoggerFromContext ¶ added in v0.6.3
GetLoggerFromContext gets the logger instance from context.
func IsContentTypeDebuggable ¶ added in v0.4.0
IsContentTypeDebuggable checks if the content type can be debugged.
func IsSensitiveHeader ¶
IsSensitiveHeader checks if the header name is sensitive.
func NewContextWithLogger ¶ added in v0.4.0
NewContextWithLogger creates a new context with a logger set.
func NewHeaderLogGroupAttrs ¶ added in v0.4.0
NewHeaderLogGroupAttrs converts HTTP header to slog attributes.
func NewHeaderMatrixLogGroupAttrs ¶ added in v0.7.1
NewHeaderMatrixLogGroupAttrs converts a header matrix to slog attributes.
func NewJSONLogger ¶ added in v0.4.0
NewJSONLogger creates a JSON logger from a log level string.
func NormalizeStrings ¶ added in v0.8.0
NormalizeStrings normalize input strings to the standard format for telemetry evaluation.
func SetSpanHeaderAttributes ¶
func SetSpanHeaderAttributes( span trace.Span, prefix string, headers map[string][]string, allowedHeaders ...string, )
SetSpanHeaderAttributes sets header attributes to the otel span.
func SetSpanHeaderMatrixAttributes ¶ added in v0.7.1
func SetSpanHeaderMatrixAttributes( span trace.Span, prefix string, headers [][]string, allowedHeaders ...string, )
SetSpanHeaderMatrixAttributes sets header attributes from a matrix to the otel span.
func SplitHostPort ¶
SplitHostPort splits a network address hostport of the form "host", "host%zone", "[host]", "[host%zone]", "host:port", "host%zone:port", "[host]:port", "[host%zone]:port", or ":port" into host or host%zone and port.
An empty host is returned if it is not provided or unparsable. A negative port is returned if it is not provided or unparsable.
Types ¶
This section is empty.