otzap

package module
v0.0.13 Latest Latest
Warning

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

Go to latest
Published: Mar 3, 2023 License: MIT Imports: 13 Imported by: 0

README

Overview

Documentation

Overview

Package otzap connect opentelemetry and zap

Index

Constants

This section is empty.

Variables

View Source
var BlockedEnvVarSubstrings = []string{
	"access_key",
	"accesstoken",
	"admin_token",
	"auth_pass",
	"authentication",
	"credentials",
	"database_password",
	"jwt",
	"kerberos",
	"keystore",
	"ldap",
	"openssl",
	"passwd",
	"password",
	"password_file",
	"root_password",
	"rsa",
	"secret",
	"sslkey",
	"token",
	"truststore",
}

BlockedEnvVarSubstrings lists Key substrings which must NOT be logged not case sensitive

View Source
var BlockedEnvVars = []string{
	"AUTH_PASS",
	"AWS_ACCESS_KEY",
	"AWS_SECRET_ACCESS_KEY",
	"DB_PASS",
	"DB_PASSWORD",
	"GOOGLE_APPLICATION_CREDENTIALS",
	"JDBC_DATABASE_PASSWORD",
	"KAFKA_PASSWORD",
	"MARIADB_ROOT_PASSWORD",
	"MYSQL_PWD",
	"MYSQL_ROOT_PASSWORD",
	"PGPASSFILE",
	"PGPASSWORD",
	"PGSSLKEY",
	"PIN",
	"POSTGRES_PASSWORD",
	"PS1",
	"PS2",
	"SYSTEM_ACCESSTOKEN",
	"VISUAL",
}

BlockedEnvVars lists keys which must NOT be logged not case sensitive

Functions

func AddDebugEvent

func AddDebugEvent(span trace.Span, msg string, err ...error)

AddDebugEvent simplifies span.debug(msg) AddDebugEvent adds an event to the span Any related attributes should be added to the span

func AddDebugEventToSpan

func AddDebugEventToSpan(ctx context.Context, msg string, err ...error)

AddDebugEventToSpan retrieves span from context and adds error to span when present

AddDebugEventToSpan sets level to debug

func AddErrorEvent

func AddErrorEvent(span trace.Span, msg string, err ...error)

AddErrorEvent simplifies span.error(msg) AddErrorEvent adds an event to the span Any related attributes should be added to the span

func AddErrorEventToSpan

func AddErrorEventToSpan(ctx context.Context, msg string, err ...error)

AddErrorEventToSpan retrieves span from context and adds error to span when present

AddErrorEventToSpan sets level to error

func AddFatalEvent

func AddFatalEvent(span trace.Span, msg string, err ...error)

AddFatalEvent simplifies span.fatal(msg) AddFatalEvent adds an event to the span Any related attributes should be added to the span

func AddFatalEventToSpan

func AddFatalEventToSpan(ctx context.Context, msg string, err ...error)

AddFatalEventToSpan retrieves span from context and adds error to span when present

AddFatalEventToSpan sets level to fatal

func AddInfoEvent

func AddInfoEvent(span trace.Span, msg string, err ...error)

AddInfoEvent simplifies span.info(msg) AddInfoEvent adds an event to the span Any related attributes should be added to the span

func AddInfoEventToSpan

func AddInfoEventToSpan(ctx context.Context, msg string, err ...error)

AddInfoEventToSpan retrieves span from context and adds error to span when present

AddInfoEventToSpan sets level to info

func AddWarnEvent

func AddWarnEvent(span trace.Span, msg string, err ...error)

AddWarnEvent simplifies span.warn(msg) AddWarnEvent adds an event to the span Any related attributes should be added to the span

func AddWarnEventToSpan

func AddWarnEventToSpan(ctx context.Context, msg string, err ...error)

AddWarnEventToSpan retrieves span from context and adds error to span when present

AddWarnEventToSpan sets level to warn

func BuildNormalZapCores added in v0.0.12

func BuildNormalZapCores(minLevel zapcore.Level) ([]zapcore.Core, error)

BuildNormalZapCores returns a slice of zapcore.Core suitable for both local and GCloud based logging This is just an example, tweak to meet your needs

func CollectResourceAttributes

func CollectResourceAttributes() []attribute.KeyValue

CollectResourceAttributes reads Environment Variables and returns corresponding OpenTelemetry Attributes

func ColorConsoleLevelEncoder

func ColorConsoleLevelEncoder(
	l zapcore.Level,
	enc zapcore.PrimitiveArrayEncoder,
)

ColorConsoleLevelEncoder adds color and uses exactly 3-chars for level

func GoogleCloudLevelEncoder

func GoogleCloudLevelEncoder(
	lvl zapcore.Level,
	enc zapcore.PrimitiveArrayEncoder,
)

GoogleCloudLevelEncoder encodes a zapcore.Level to a Google Cloud Logging severity

See https://pkg.go.dev/go.uber.org/zap/zapcore#LevelEncoder See https://cloud.google.com/logging/docs/reference/v2/rest/v2/LogEntry#LogSeverity

func IsInAWSCloud added in v0.0.9

func IsInAWSCloud() bool

IsInAWSCloud returns true iff the application is running in Amazon Web Services

func IsInGoogleCloud

func IsInGoogleCloud() bool

IsInGoogleCloud returns true iff the application is running in Google Cloud

func MustNotLogEnvVar

func MustNotLogEnvVar(varName string) bool

MustNotLogEnvVar is a predicate MustNotLogEnvVar returns true for sensitive env vars MustNotLogEnvVar relies on 2 global vars: - BlockedEnvVars - BlockedEnvVarSubstrings

func NewGoogleCloudCore

func NewGoogleCloudCore(minLevel zapcore.Level) zapcore.Core

NewGoogleCloudCore builds a zapcore.Core that writes to stdout in Google Cloud Logging format

See https://pkg.go.dev/go.uber.org/zap/zapcore#Core See https://cloud.google.com/logging

func NewPrettyConsoleCore

func NewPrettyConsoleCore(minLevel zapcore.Level) zapcore.Core

NewPrettyConsoleCore builds a Core which prints to stdout in a pretty format Inspired by zerolog's console writer

func NewRollingFileCore added in v0.0.12

func NewRollingFileCore(
	minLevel zapcore.Level,
) zapcore.Core

NewRollingFileCore shows how to configure a rolling file logger This is just an example, tweak to meet your needs

func PrintEnvVars

func PrintEnvVars()

PrintEnvVars prints local environment variables using zap API

func RecordErrors

func RecordErrors(span trace.Span, err ...error)

RecordErrors is a low-level method, prefer the methods above RecordErrors simplifies recording errors correctly for Jaeger, Google Cloud Trace, AWS XRay, etc

Types

type OTelZapCore

type OTelZapCore struct {

	// Matches zap.Field.Key
	// default: "ctx"
	// Context may contain a Span
	//
	// See https://pkg.go.dev/go.uber.org/zap#Any
	// See https://pkg.go.dev/go.opentelemetry.io/otel/trace#SpanFromContext
	ContextAttrKey string

	// Matches zap.Field.Key
	// default: "span"
	// See https://pkg.go.dev/go.uber.org/zap#Any
	SpanAttrKey string

	// default: "logEventSource"
	EventSourceKey string

	// default: "zap"
	EventSourceValue string

	// default: "level"
	LevelKey string
	// contains filtered or unexported fields
}

OtelZapCore attaches zap log entries to current span Span can be attached directly to zap Log Entry or nested in an attached context.Context OTelZapCore ignores Log Entries which lack a Span

OtelZapCore implements zapcore.Core See https://pkg.go.dev/go.uber.org/zap/zapcore#Core if log event contains a span, OTelZapCore forwards log events to span

func (OTelZapCore) AddEventToSpan

func (oc OTelZapCore) AddEventToSpan(
	span trace.Span,
	entry zapcore.Entry,
	fields []zapcore.Field,
) error

TODO: add tests for error handling TODO: add tests for mapping each type TODO: add tests for my span processor source TODO: add tests for self source

func (OTelZapCore) AddEventToSpanInContext

func (oc OTelZapCore) AddEventToSpanInContext(
	ctx context.Context,
	entry zapcore.Entry,
	fields []zapcore.Field,
) error

AddEventToSpanInContext retrieves span from contex and adds the zap Entry

func (OTelZapCore) Check

func (OTelZapCore) Enabled

func (oc OTelZapCore) Enabled(zapcore.Level) bool

func (OTelZapCore) GetContextAttrKey

func (oc OTelZapCore) GetContextAttrKey() string

func (OTelZapCore) GetEventSourceKey

func (oc OTelZapCore) GetEventSourceKey() string

func (OTelZapCore) GetEventSourceValue

func (oc OTelZapCore) GetEventSourceValue() string

func (OTelZapCore) GetLevelKey

func (oc OTelZapCore) GetLevelKey() string

func (OTelZapCore) GetSpanAttrKey

func (oc OTelZapCore) GetSpanAttrKey() string

func (OTelZapCore) Sync

func (oc OTelZapCore) Sync() error

func (OTelZapCore) Validate

func (oc OTelZapCore) Validate() error

func (OTelZapCore) With

func (oc OTelZapCore) With(fields []zapcore.Field) zapcore.Core

TODO: add test that this doesn't affect original

func (OTelZapCore) Write

func (oc OTelZapCore) Write(
	entry zapcore.Entry,
	fields []zapcore.Field,
) error

type ZapSpanProcessor

type ZapSpanProcessor struct {
	// debug | info | warn | error | fatal
	DefaultLevel string
	Logger       *zap.Logger

	EventSourceKey string

	// Useful for preventing infinite loops
	EventSourceValue string

	LevelKey     string
	SpanIdKey    string
	TimestampKey string

	// See https://cloud.google.com/resource-manager/docs/creating-managing-projects#before_you_begin
	GoogleCloudProjectId string
}

ZapSpanProcessor forwards OpenTelemetry::Span events to a Zap logger See https://pkg.go.dev/go.opentelemetry.io/otel/sdk/trace#SpanProcessor

func (ZapSpanProcessor) ForceFlush

func (zp ZapSpanProcessor) ForceFlush(context.Context) error

func (ZapSpanProcessor) GetEventSourceKey

func (zp ZapSpanProcessor) GetEventSourceKey() string

func (ZapSpanProcessor) GetEventSourceValue

func (zp ZapSpanProcessor) GetEventSourceValue() string

func (ZapSpanProcessor) GetLogger

func (zp ZapSpanProcessor) GetLogger() *zap.Logger

func (ZapSpanProcessor) GetSpanIdKey

func (zp ZapSpanProcessor) GetSpanIdKey() string

func (ZapSpanProcessor) GetTimestampKey

func (zp ZapSpanProcessor) GetTimestampKey() string

func (ZapSpanProcessor) GetZapLevel

func (zp ZapSpanProcessor) GetZapLevel(raw string) zapcore.Level

func (ZapSpanProcessor) GetZapLevelKey

func (zp ZapSpanProcessor) GetZapLevelKey() string

func (ZapSpanProcessor) LogEvent

func (zp ZapSpanProcessor) LogEvent(
	currentEvt tracesdk.Event,
	spanAttributes []attribute.KeyValue,
	spanCtx trace.SpanContext)

LogEvent delegates to configured Writers

func (ZapSpanProcessor) OnEnd

func (zp ZapSpanProcessor) OnEnd(span tracesdk.ReadOnlySpan)

func (ZapSpanProcessor) OnStart

func (ZapSpanProcessor) Shutdown

func (zp ZapSpanProcessor) Shutdown(context.Context) error

func (ZapSpanProcessor) Validate

func (zp ZapSpanProcessor) Validate() error

Jump to

Keyboard shortcuts

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