otelutils

package
v0.8.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 30, 2026 License: Apache-2.0 Imports: 11 Imported by: 13

Documentation

Overview

Package otelutils contain reusable utilities for OpenTelemetry attributes.

Index

Constants

View Source
const MaskString = "[REDACTED]"

MaskString is the constant string for masking sensitive data.

Variables

View Source
var LoggerContextKey = &contextKey{"LogEntry"}

LoggerContextKey is the global context key constant.

View Source
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

func GetLogger(ctx context.Context) *slog.Logger

GetLogger gets the logger instance from context. If not exists, return the default logger.

func GetLoggerFromContext added in v0.6.3

func GetLoggerFromContext(ctx context.Context) (*slog.Logger, bool)

GetLoggerFromContext gets the logger instance from context.

func IsContentTypeDebuggable added in v0.4.0

func IsContentTypeDebuggable(contentType string) bool

IsContentTypeDebuggable checks if the content type can be debugged.

func IsSensitiveHeader

func IsSensitiveHeader(name string, patterns ...string) bool

IsSensitiveHeader checks if the header name is sensitive.

func NewContextWithLogger added in v0.4.0

func NewContextWithLogger(parentContext context.Context, logger *slog.Logger) context.Context

NewContextWithLogger creates a new context with a logger set.

func NewHeaderLogGroupAttrs added in v0.4.0

func NewHeaderLogGroupAttrs(key string, headers http.Header) slog.Attr

NewHeaderLogGroupAttrs converts HTTP header to slog attributes.

func NewHeaderMatrixLogGroupAttrs added in v0.7.1

func NewHeaderMatrixLogGroupAttrs(key string, headers [][]string) slog.Attr

NewHeaderMatrixLogGroupAttrs converts a header matrix to slog attributes.

func NewJSONLogger added in v0.4.0

func NewJSONLogger(logLevel string) (*slog.Logger, slog.Level, error)

NewJSONLogger creates a JSON logger from a log level string.

func NormalizeStrings added in v0.8.0

func NormalizeStrings(values []string) []string

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

func SplitHostPort(hostport string, urlScheme string) (string, int, error)

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.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL