obs

package
v0.1.8 Latest Latest
Warning

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

Go to latest
Published: Jul 11, 2026 License: Apache-2.0 Imports: 10 Imported by: 0

Documentation

Overview

Package obs provides tenant observability fields, redaction helpers, slog helpers, and OpenTelemetry API helpers.

Index

Constants

View Source
const (
	// TenantIDField is the standard observability field for tenant ID.
	TenantIDField = "tenant_id"

	// TenantSideField is the standard observability field for tenant side.
	TenantSideField = "tenant_side"
)
View Source
const (
	// InstrumentationName is the OpenTelemetry instrumentation scope name for GoTenancy.
	InstrumentationName = "github.com/DarkInno/gotenancy"
)

Variables

This section is empty.

Functions

func AddSpanAttributes added in v0.1.6

func AddSpanAttributes(ctx context.Context)

AddSpanAttributes adds tenant attributes to the current span in ctx.

func Fields

func Fields(ctx context.Context) map[string]string

Fields returns tenant observability fields for ctx.

func LogAttrs added in v0.1.6

func LogAttrs(ctx context.Context, logger *slog.Logger, level slog.Level, msg string, attrs ...slog.Attr)

LogAttrs logs attrs with tenant fields from ctx and redacts sensitive attrs.

func LoggerWithTenant added in v0.1.6

func LoggerWithTenant(ctx context.Context, logger *slog.Logger) *slog.Logger

LoggerWithTenant returns logger enriched with tenant fields from ctx.

func NewTracer added in v0.1.6

func NewTracer(provider trace.TracerProvider) trace.Tracer

NewTracer returns an OpenTelemetry tracer for GoTenancy.

Libraries should not initialize an SDK or exporter. When provider is nil, the process-global OpenTelemetry provider is used, which is no-op until the host application configures it.

func RecordSpanError added in v0.1.6

func RecordSpanError(ctx context.Context, err error, description string)

RecordSpanError records a sanitized error event on the current span and marks it as failed.

func Redact

func Redact(fields map[string]string) map[string]string

Redact removes sensitive values from a string map.

func RedactSlogAttrs added in v0.1.6

func RedactSlogAttrs(attrs ...slog.Attr) []slog.Attr

RedactSlogAttrs returns a redacted copy of attrs.

func SlogAttrs added in v0.1.6

func SlogAttrs(ctx context.Context) []slog.Attr

SlogAttrs returns tenant observability attributes for slog.

func SpanAttributes added in v0.1.6

func SpanAttributes(ctx context.Context) []attribute.KeyValue

SpanAttributes returns tenant OpenTelemetry span attributes for ctx.

func StartSpan added in v0.1.6

func StartSpan(ctx context.Context, tracer trace.Tracer, name string, opts ...trace.SpanStartOption) (context.Context, trace.Span)

StartSpan starts a span with tenant attributes from ctx.

The caller is responsible for ending the returned span.

Types

This section is empty.

Jump to

Keyboard shortcuts

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