Documentation
¶
Index ¶
- Variables
- func CtxWithBelt(ctx context.Context, belt *Belt) context.Context
- func Flush(ctx context.Context)
- func GetFields(ctx context.Context) field.AbstractFields
- func WithArtifact(ctx context.Context, artifactID ArtifactID, artifact Artifact) context.Context
- func WithField(ctx context.Context, key string, value interface{}, props ...field.Property) context.Context
- func WithFields(ctx context.Context, fields field.AbstractFields) context.Context
- func WithMap(ctx context.Context, m map[string]interface{}, props ...field.Property) context.Context
- func WithTool(ctx context.Context, toolID ToolID, tool Tool) context.Context
- func WithTraceID(ctx context.Context, traceIDs ...TraceID) context.Context
- type Artifact
- type ArtifactID
- type Artifacts
- type Belt
- func (belt *Belt) Artifacts() Artifacts
- func (belt *Belt) Fields() field.AbstractFields
- func (belt *Belt) Flush(ctx context.Context)
- func (belt *Belt) Tools() Tools
- func (belt *Belt) TraceIDs() TraceIDs
- func (belt *Belt) WithArtifact(artifactID ArtifactID, artifact Artifact) *Belt
- func (belt *Belt) WithField(key string, value field.Value, props ...field.Property) *Belt
- func (belt *Belt) WithFields(fields field.AbstractFields) *Belt
- func (belt *Belt) WithMap(m map[string]interface{}, props ...field.Property) *Belt
- func (belt *Belt) WithTool(toolID ToolID, tool Tool) *Belt
- func (belt *Belt) WithTraceID(traceIDs ...TraceID) *Belt
- type Tool
- type ToolID
- type Tools
- type TraceID
- type TraceIDs
Constants ¶
This section is empty.
Variables ¶
var Default = func() *Belt { return New() }
Default returns an Belt with the default configuration and state.
This function is overridable. Please override it only and only from a `main` package.
Functions ¶
func CtxWithBelt ¶
CtxWithBelt returns a context derivative which includes the Belt as a value.
func GetFields ¶
func GetFields(ctx context.Context) field.AbstractFields
GetFields returns returns the set of fields set in the scope of this Belt.
Do not modify the output of this function! It is for reading only.
func WithArtifact ¶
WithArtifact returns a derivative of the context, but with the Artifact set.
func WithField ¶
func WithField(ctx context.Context, key string, value interface{}, props ...field.Property) context.Context
WithField returns a context with a clone/derivative of the Belt which includes the passed value.
The value is used by observability tooling. For example a Logger derived from the resulting Belt may add this value to the structured fields of each log entry.
func WithFields ¶
WithFields is the same as WithField, but adds multiple Fields at the same time.
It is more performance efficient than adding fields by one.
func WithMap ¶
func WithMap(ctx context.Context, m map[string]interface{}, props ...field.Property) context.Context
WithMap is just a sugar method, which provides logrus like way of adding fields. Effectively the same as WithFields, just the argument are in another format.
Types ¶
type Artifact ¶
type Artifact any
Artifact is a specific object attached to current context by any of the observability tools.
type ArtifactID ¶
type ArtifactID any
ArtifactID is an unique ID of an Artifact.
An example of such objects is a Span left by a Tracer.
type Artifacts ¶
type Artifacts map[ArtifactID]Artifact
Artifacts is a set of Artifact-s.
func GetArtifacts ¶
GetArtifacts returns the collection of Artifacts in the scope of the Belt.
Do not modify the output of this function! It is for reading only.
func (Artifacts) GetByID ¶
func (artifacts Artifacts) GetByID(artifactID ArtifactID) Artifact
GetByID returns an Artifact given its ID.
Returns an untyped nil if an Artifact is not set.
type Belt ¶
type Belt struct {
// contains filtered or unexported fields
}
Belt (tool belt for observability) is the handler which orchestrates all the observability tooling.
Things like Logger, Tracer, Metrics, ErrorMonitoring are handled together, and are available at any moment, given an Belt.
For example one may call `logger.FromBelt(belt)` to get a `Logger`, if `belt` is an `Belt`. It is different from just storing this tooling as values within a context, for example it is: * More performance efficient. * Safer (e.g. you won't get an untyped nil because a context was accidentally changed to a new one) * More convenient: no need to manage each tool separately. And all the possible sugar is already in place. * Reusable. It is a generic standardized way to handle observability tooling. * Quality. Here we try to accumulate best practices, instead of having a quick solution for a single project.
func CtxBelt ¶
CtxBelt returns the Belt from context values. Returns the default observer if one is not set in the context.
func (*Belt) Artifacts ¶
Artifacts returns the collection of Artifacts in the scope of the Belt.
Do not modify the output of this function! It is for reading only.
func (*Belt) Fields ¶
func (belt *Belt) Fields() field.AbstractFields
Fields returns returns the set of fields set in the scope of this Belt.
Do not modify the output of this function! It is for reading only.
func (*Belt) Tools ¶
Tools returns the current collection of Tools.
Do not modify the output of this function! It is for reading only.
func (*Belt) TraceIDs ¶
TraceIDs returns the current set of TraceID-s.
Do not modify the output of this function! It is for reading only.
func (*Belt) WithArtifact ¶
func (belt *Belt) WithArtifact(artifactID ArtifactID, artifact Artifact) *Belt
WithArtifact returns a clone of the Belt, but with the Artifact set.
func (*Belt) WithField ¶
WithField returns a clone/derivative of the Belt which includes the passed value.
The value is used by observability tooling. For example a Logger derived from the resulting Belt may add this value to the structured fields of each log entry.
func (*Belt) WithFields ¶
func (belt *Belt) WithFields(fields field.AbstractFields) *Belt
WithFields is the same as WithField, but adds multiple Fields at the same time.
It is more performance efficient than adding fields by one.
func (*Belt) WithMap ¶
WithMap is just a sugar method, which provides logrus like way of adding fields. Effectively the same as WithFields, just the argument are in another format.
func (*Belt) WithTool ¶
WithTool returns an Belt clone/derivative, but the provided tool added to the collection of tools.
Special case: to remove a specific tool, just passed an untyped nil as `tool`.
func (*Belt) WithTraceID ¶
WithTraceID returns an Belt clone/derivative with the passed traceIDs added to the set of TraceIDs.
type Tool ¶
type Tool interface { // Flush forces to flush all buffers. Flush(ctx context.Context) // WithContextFields sets new context-defined fields. Supposed to be called // only by an Belt. // // allFields contains all fields as a chain of additions in a reverse-chronological order, // while newFieldsCount tells about how much of the fields are new (since last // call of WithContextFields). Thus if one will call // field.Slice(allFields, 0, newFieldsCount) they will get only the new fields. // At the same time some Tool-s may prefer just to re-set all the fields instead of adding // only new fields (due to performance reasons) and they may just use `allFields`. WithContextFields(allFields *field.FieldsChain, newFieldsCount int) Tool // WithTraceIDs sets new context-defined TraceIDs. Supposed to be called // only by an Belt. // // traceIDs and newTraceIDsCount has similar properties as allFields and newFieldsCount // in the WithContextFields method. WithTraceIDs(traceIDs TraceIDs, newTraceIDsCount int) Tool }
Tool is an abstract observability tool. It could be a Logger, metrics, tracing or anything else.
type ToolID ¶
type ToolID interface{}
ToolID is an unique identifier of a Tool. A ToolID should be always defined using a private-type, so that no other package can define the same ToolID.
type Tools ¶
Tools is a collection of observability Tool-s.
Directories
¶
Path | Synopsis |
---|---|
examples
|
|
pkg
|
|
test
|
|
dependencies/zap
Module
|
|
tool
|
|
logger/types
Package types of logger unifies different types of loggers into interfaces Logger.
|
Package types of logger unifies different types of loggers into interfaces Logger. |