obs

package
v0.2.1 Latest Latest
Warning

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

Go to latest
Published: Jul 17, 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.

包 obs 提供租户可观测性字段、脱敏辅助函数、slog 辅助函数和 OpenTelemetry API 辅助函数。

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 SaaS.
	InstrumentationName = "github.com/DarkInno/saas"
)

Variables

This section is empty.

Functions

func AddSpanAttributes

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

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

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

LoggerWithTenant returns logger enriched with tenant fields from ctx.

func NewTracer

func NewTracer(provider trace.TracerProvider) trace.Tracer

NewTracer returns an OpenTelemetry tracer for SaaS.

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

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

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

RedactSlogAttrs returns a redacted copy of attrs.

func SlogAttrs

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

SlogAttrs returns tenant observability attributes for slog.

func SpanAttributes

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

SpanAttributes returns tenant OpenTelemetry span attributes for ctx.

func StartSpan

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