Documentation ¶
Overview ¶
Package otzap connect opentelemetry and zap
Index ¶
- Variables
- func AddDebugEvent(span trace.Span, msg string, err ...error)
- func AddDebugEventToSpan(ctx context.Context, msg string, err ...error)
- func AddErrorEvent(span trace.Span, msg string, err ...error)
- func AddErrorEventToSpan(ctx context.Context, msg string, err ...error)
- func AddFatalEvent(span trace.Span, msg string, err ...error)
- func AddFatalEventToSpan(ctx context.Context, msg string, err ...error)
- func AddInfoEvent(span trace.Span, msg string, err ...error)
- func AddInfoEventToSpan(ctx context.Context, msg string, err ...error)
- func AddWarnEvent(span trace.Span, msg string, err ...error)
- func AddWarnEventToSpan(ctx context.Context, msg string, err ...error)
- func BuildNormalZapCores(minLevel zapcore.Level) ([]zapcore.Core, error)
- func CollectResourceAttributes() []attribute.KeyValue
- func ColorConsoleLevelEncoder(l zapcore.Level, enc zapcore.PrimitiveArrayEncoder)
- func GoogleCloudLevelEncoder(lvl zapcore.Level, enc zapcore.PrimitiveArrayEncoder)
- func IsInAWSCloud() bool
- func IsInGoogleCloud() bool
- func MustNotLogEnvVar(varName string) bool
- func NewGoogleCloudCore(minLevel zapcore.Level) zapcore.Core
- func NewPrettyConsoleCore(minLevel zapcore.Level) zapcore.Core
- func NewRollingFileCore(minLevel zapcore.Level) zapcore.Core
- func PrintEnvVars()
- func RecordErrors(span trace.Span, err ...error)
- type OTelZapCore
- func (oc OTelZapCore) AddEventToSpan(span trace.Span, entry zapcore.Entry, fields []zapcore.Field) error
- func (oc OTelZapCore) AddEventToSpanInContext(ctx context.Context, entry zapcore.Entry, fields []zapcore.Field) error
- func (oc OTelZapCore) Check(ent zapcore.Entry, ce *zapcore.CheckedEntry) *zapcore.CheckedEntry
- func (oc OTelZapCore) Enabled(zapcore.Level) bool
- func (oc OTelZapCore) GetContextAttrKey() string
- func (oc OTelZapCore) GetEventSourceKey() string
- func (oc OTelZapCore) GetEventSourceValue() string
- func (oc OTelZapCore) GetLevelKey() string
- func (oc OTelZapCore) GetSpanAttrKey() string
- func (oc OTelZapCore) Sync() error
- func (oc OTelZapCore) Validate() error
- func (oc OTelZapCore) With(fields []zapcore.Field) zapcore.Core
- func (oc OTelZapCore) Write(entry zapcore.Entry, fields []zapcore.Field) error
- type ZapSpanProcessor
- func (zp ZapSpanProcessor) ForceFlush(context.Context) error
- func (zp ZapSpanProcessor) GetEventSourceKey() string
- func (zp ZapSpanProcessor) GetEventSourceValue() string
- func (zp ZapSpanProcessor) GetLogger() *zap.Logger
- func (zp ZapSpanProcessor) GetSpanIdKey() string
- func (zp ZapSpanProcessor) GetTimestampKey() string
- func (zp ZapSpanProcessor) GetZapLevel(raw string) zapcore.Level
- func (zp ZapSpanProcessor) GetZapLevelKey() string
- func (zp ZapSpanProcessor) LogEvent(currentEvt tracesdk.Event, spanAttributes []attribute.KeyValue, ...)
- func (zp ZapSpanProcessor) OnEnd(span tracesdk.ReadOnlySpan)
- func (zp ZapSpanProcessor) OnStart(context.Context, tracesdk.ReadWriteSpan)
- func (zp ZapSpanProcessor) Shutdown(context.Context) error
- func (zp ZapSpanProcessor) Validate() error
Constants ¶
This section is empty.
Variables ¶
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
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 ¶
AddDebugEvent simplifies span.debug(msg) AddDebugEvent adds an event to the span Any related attributes should be added to the span
func AddDebugEventToSpan ¶
AddDebugEventToSpan retrieves span from context and adds error to span when present
AddDebugEventToSpan sets level to debug
func AddErrorEvent ¶
AddErrorEvent simplifies span.error(msg) AddErrorEvent adds an event to the span Any related attributes should be added to the span
func AddErrorEventToSpan ¶
AddErrorEventToSpan retrieves span from context and adds error to span when present
AddErrorEventToSpan sets level to error
func AddFatalEvent ¶
AddFatalEvent simplifies span.fatal(msg) AddFatalEvent adds an event to the span Any related attributes should be added to the span
func AddFatalEventToSpan ¶
AddFatalEventToSpan retrieves span from context and adds error to span when present
AddFatalEventToSpan sets level to fatal
func AddInfoEvent ¶
AddInfoEvent simplifies span.info(msg) AddInfoEvent adds an event to the span Any related attributes should be added to the span
func AddInfoEventToSpan ¶
AddInfoEventToSpan retrieves span from context and adds error to span when present
AddInfoEventToSpan sets level to info
func AddWarnEvent ¶
AddWarnEvent simplifies span.warn(msg) AddWarnEvent adds an event to the span Any related attributes should be added to the span
func AddWarnEventToSpan ¶
AddWarnEventToSpan retrieves span from context and adds error to span when present
AddWarnEventToSpan sets level to warn
func BuildNormalZapCores ¶ added in v0.0.12
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 ¶
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 ¶
MustNotLogEnvVar is a predicate MustNotLogEnvVar returns true for sensitive env vars MustNotLogEnvVar relies on 2 global vars: - BlockedEnvVars - BlockedEnvVarSubstrings
func NewGoogleCloudCore ¶
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 ¶
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
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 ¶
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 (oc OTelZapCore) Check( ent zapcore.Entry, ce *zapcore.CheckedEntry, ) *zapcore.CheckedEntry
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
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 (zp ZapSpanProcessor) OnStart(context.Context, tracesdk.ReadWriteSpan)
func (ZapSpanProcessor) Validate ¶
func (zp ZapSpanProcessor) Validate() error