swo

package
v1.2.0 Latest Latest
Warning

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

Go to latest
Published: Aug 22, 2024 License: Apache-2.0 Imports: 29 Imported by: 3

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GetLogLevel

func GetLogLevel() string

GetLogLevel returns the current logging level of the library

func SetLogLevel

func SetLogLevel(level string) error

SetLogLevel changes the logging level of the library Valid logging levels: DEBUG, INFO, WARN, ERROR

func SetLogOutput

func SetLogOutput(w io.Writer)

SetLogOutput sets the output destination for the internal logger.

func SetTransactionName

func SetTransactionName(ctx context.Context, name string) error

SetTransactionName sets the transaction name of the current entry span. If set multiple times, the last is used. Returns nil on success; Error if the provided name is blank, or we are unable to set the transaction name.

func Start

func Start(resourceAttrs ...attribute.KeyValue) (func(), error)

Start bootstraps otel requirements and starts the agent. The given `resourceAttrs` are added to the otel `resource.Resource` that is supplied to the otel `TracerProvider`

Types

type Flusher added in v1.1.0

type Flusher interface {
	Flush(ctx context.Context) error
}

func StartLambda added in v1.1.0

func StartLambda(lambdaLogStreamName string) (Flusher, error)

type LogHandler added in v1.2.0

type LogHandler struct {
	// contains filtered or unexported fields
}

LogHandler is a custom slog handler that adds a trace ID from the trace context to each log entry

func NewLogHandler added in v1.2.0

func NewLogHandler(wrapped slog.Handler) *LogHandler

NewLogHandler creates a new LogHandler

func (*LogHandler) Enabled added in v1.2.0

func (h *LogHandler) Enabled(ctx context.Context, level slog.Level) bool

Enabled calls slog Enabled

func (*LogHandler) Handle added in v1.2.0

func (h *LogHandler) Handle(ctx context.Context, record slog.Record) error

Handle adds trace context to the record, in the format that allows SWO to associate log lines with traces

func (*LogHandler) WithAttrs added in v1.2.0

func (h *LogHandler) WithAttrs(attrs []slog.Attr) slog.Handler

WithAttrs calls slog WithAttrs

func (*LogHandler) WithGroup added in v1.2.0

func (h *LogHandler) WithGroup(name string) slog.Handler

WithGroup calls slog WithGroup

type LoggableTraceContext

type LoggableTraceContext struct {
	TraceID     trace.TraceID    `json:"trace_id,omitempty"`
	SpanID      trace.SpanID     `json:"span_id,omitempty"`
	TraceFlags  trace.TraceFlags `json:"trace_flags,omitempty"`
	ServiceName string           `json:"service_name,omitempty"`
}

func LoggableTrace

func LoggableTrace(ctx context.Context) LoggableTraceContext

LoggableTrace returns a LoggableTraceContext from a given context.Context and the configured service name

func LoggableTraceFromSpanContext

func LoggableTraceFromSpanContext(ctx trace.SpanContext) LoggableTraceContext

LoggableTraceFromSpanContext returns a LoggableTraceContext from a given SpanContext and the configured service name

func (LoggableTraceContext) IsValid

func (l LoggableTraceContext) IsValid() bool

IsValid returns true if both TraceID and SpanID are valid

func (LoggableTraceContext) String

func (l LoggableTraceContext) String() string

String returns a string representation that is usable in a log Example: trace_id=d4261c67357f99f39958b14f99da7e6c span_id=1280450002ba77b3 trace_flags=01 resource.service.name=my-service

Jump to

Keyboard shortcuts

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