Documentation ¶
Index ¶
- type CachedTracer
- func (c *CachedTracer) BeginTrace(ctx context.Context, correlationId string, component string, operation string) *TraceTiming
- func (c *CachedTracer) Clear()
- func (c *CachedTracer) Configure(ctx context.Context, config *cconf.ConfigParams)
- func (c *CachedTracer) Dump(ctx context.Context)
- func (c *CachedTracer) Failure(ctx context.Context, correlationId string, component string, operation string, ...)
- func (c *CachedTracer) SetReferences(ctx context.Context, references cref.IReferences)
- func (c *CachedTracer) Trace(ctx context.Context, correlationId string, component string, operation string, ...)
- func (c *CachedTracer) Update(ctx context.Context)
- func (c *CachedTracer) Write(ctx context.Context, correlationId string, component string, operation string, ...)
- type CompositeTracer
- func (c *CompositeTracer) BeginTrace(ctx context.Context, correlationId string, component string, operation string) *TraceTiming
- func (c *CompositeTracer) Failure(ctx context.Context, correlationId string, component string, operation string, ...)
- func (c *CompositeTracer) SetReferences(ctx context.Context, references cref.IReferences)
- func (c *CompositeTracer) Trace(ctx context.Context, correlationId string, component string, operation string, ...)
- type DefaultTracerFactory
- type ICachedTraceSaver
- type ITracer
- type LogTracer
- func (c *LogTracer) BeginTrace(ctx context.Context, correlationId string, component string, operation string) *TraceTiming
- func (c *LogTracer) Configure(ctx context.Context, config *cconf.ConfigParams)
- func (c *LogTracer) Failure(ctx context.Context, correlationId string, component string, operation string, ...)
- func (c *LogTracer) SetReferences(ctx context.Context, references cref.IReferences)
- func (c *LogTracer) Trace(ctx context.Context, correlationId string, component string, operation string, ...)
- type NullTracer
- func (c *NullTracer) BeginTrace(ctx context.Context, correlationId string, component string, operation string) *TraceTiming
- func (c *NullTracer) Failure(ctx context.Context, correlationId string, component string, operation string, ...)
- func (c *NullTracer) Trace(ctx context.Context, correlationId string, component string, operation string, ...)
- type OperationTrace
- type TraceTiming
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type CachedTracer ¶
type CachedTracer struct { Cache []OperationTrace // contains filtered or unexported fields }
func InheritCachedTracer ¶
func InheritCachedTracer(saver ICachedTraceSaver) *CachedTracer
InheritCachedTracer creates a new instance of the logger.
func (*CachedTracer) BeginTrace ¶
func (c *CachedTracer) BeginTrace(ctx context.Context, correlationId string, component string, operation string) *TraceTiming
BeginTrace begins recording an operation trace
Parameters: - ctx context.Context - correlationId (optional) transaction id to trace execution through call chain. - component a name of called component - operation a name of the executed operation. Returns: a trace timing object.
func (*CachedTracer) Clear ¶
func (c *CachedTracer) Clear()
Clear (removes) all cached log messages.
func (*CachedTracer) Configure ¶
func (c *CachedTracer) Configure(ctx context.Context, config *cconf.ConfigParams)
Configure component by passing configuration parameters.
Parameters: - ctx context.Context - config configuration parameters to be set.
func (*CachedTracer) Dump ¶
func (c *CachedTracer) Dump(ctx context.Context)
Dump (writes) the currently cached log messages.
See [[Write]]
func (*CachedTracer) Failure ¶
func (c *CachedTracer) Failure(ctx context.Context, correlationId string, component string, operation string, err error, duration int64)
Failure records an operation failure with its name, duration and error
Parameters: - ctx context.Context - correlationId (optional) transaction id to trace execution through call chain. - component a name of called component - operation a name of the executed operation. - error an error object associated with this trace. - duration execution duration in milliseconds.
func (*CachedTracer) SetReferences ¶
func (c *CachedTracer) SetReferences(ctx context.Context, references cref.IReferences)
SetReferences references to dependent components.
Parameters: - ctx context.Context - references references to locate the component dependencies.
func (*CachedTracer) Trace ¶
func (c *CachedTracer) Trace(ctx context.Context, correlationId string, component string, operation string, duration int64)
Trace records an operation trace with its name and duration
Parameters: - ctx context.Context - correlationId (optional) transaction id to trace execution through call chain. - component a name of called component - operation a name of the executed operation. - duration execution duration in milliseconds.
func (*CachedTracer) Update ¶
func (c *CachedTracer) Update(ctx context.Context)
Update makes trace cache as updated and dumps it when timeout expires.
See [[Dump]]
func (*CachedTracer) Write ¶
func (c *CachedTracer) Write(ctx context.Context, correlationId string, component string, operation string, err error, duration int64)
Writes a log message to the logger destination.
Parameters: - ctx context.Context - correlationId (optional) transaction id to trace execution through call chain. - component a name of called component - operation a name of the executed operation. - error an error object associated with this trace. - duration execution duration in milliseconds.
type CompositeTracer ¶
type CompositeTracer struct {
Tracers []ITracer
}
CompositeTracer aggregates all tracers from component references under a single component. It allows to record traces and conveniently send them to multiple destinations.
References: - *:tracer:*:*:1.0 (optional) [[ITracer]] components to pass operation traces See [[ITracer]] Example: type MyComponent struct { tracer CompositeTracer } func NewMyComponent() *MyComponent{ return &MyComponent{ tracer: NewCompositeTracer(nil); } } func (c* MyComponent) SetReferences(ctx context.Context, references IReferences) { c.tracer.SetReferences(references) ... } public MyMethod(ctx context.Context, correlatonId string) { timing := c.tracer.BeginTrace(ctx, correlationId, "mycomponent", "mymethod"); ... timing.EndTrace(ctx); if err != nil { timing.EndFailure(ctx, err); } }
func NewCompositeTracer ¶
func NewCompositeTracer(ctx context.Context, references cref.IReferences) *CompositeTracer
NewCompositeTracer creates a new instance of the tracer.
Parameters: - references to locate the component dependencies.
func (*CompositeTracer) BeginTrace ¶
func (c *CompositeTracer) BeginTrace(ctx context.Context, correlationId string, component string, operation string) *TraceTiming
BeginTrace begins recording an operation trace
Parameters: - ctx context.Context - correlationId (optional) transaction id to trace execution through call chain. - component a name of called component - operation a name of the executed operation. Returns: a trace timing object.
func (*CompositeTracer) Failure ¶
func (c *CompositeTracer) Failure(ctx context.Context, correlationId string, component string, operation string, err error, duration int64)
Failure records an operation failure with its name, duration and error
Parameters: - ctx context.Context - correlationId (optional) transaction id to trace execution through call chain. - component a name of called component - operation a name of the executed operation. - error an error object associated with this trace. - duration execution duration in milliseconds.
func (*CompositeTracer) SetReferences ¶
func (c *CompositeTracer) SetReferences(ctx context.Context, references cref.IReferences)
SetReferences sets references to dependent components.
Parameters: - ctx context.Context - references to locate the component dependencies.
func (*CompositeTracer) Trace ¶
func (c *CompositeTracer) Trace(ctx context.Context, correlationId string, component string, operation string, duration int64)
Trace records an operation trace with its name and duration
Parameters: - ctx context.Context - correlationId (optional) transaction id to trace execution through call chain. - component a name of called component - operation a name of the executed operation. - duration execution duration in milliseconds.
type DefaultTracerFactory ¶
type DefaultTracerFactory struct { cbuild.Factory NullTracerDescriptor *cref.Descriptor LogTracerDescriptor *cref.Descriptor CompositeTracerDescriptor *cref.Descriptor }
DefaultTracerFactory creates [ITracer] components by their descriptors.
See [[Factory]] See [[NullTracer]] See [[ConsoleTracer]] See [[CompositeTracer]]
func NewDefaultTracerFactory ¶
func NewDefaultTracerFactory() *DefaultTracerFactory
NewDefaultTracerFactory create a new instance of the factory.
type ICachedTraceSaver ¶
type ICachedTraceSaver interface {
Save(ctx context.Context, operations []OperationTrace) error
}
ICachedTraceSaver Abstract tracer that caches recorded traces in memory and periodically dumps them. Child classes implement saving cached traces to their specified destinations.
Configuration parameters: - source: source (context) name - options: - interval: interval in milliseconds to save log messages (default: 10 seconds) - maxcache_size: maximum number of messages stored in this cache (default: 100) References: - *:context-info:*:*:1.0 (optional) [[ContextInfo]] to detect the context id and specify counters source See [[ITracer]] See [[OperationTrace]]
type ITracer ¶
type ITracer interface { // Trace records an operation trace with its name and duration // Parameters: // - ctx context.Context // - correlationId (optional) transaction id to trace execution through call chain. // - component a name of called component // - operation a name of the executed operation. // - duration execution duration in milliseconds. Trace(ctx context.Context, correlationId string, component string, operation string, duration int64) // Failure records an operation failure with its name, duration and error // Parameters: // - ctx context.Context // - correlationId (optional) transaction id to trace execution through call chain. // - component a name of called component // - operation a name of the executed operation. // - error an error object associated with this trace. // - duration execution duration in milliseconds. Failure(ctx context.Context, correlationId string, component string, operation string, err error, duration int64) //BeginTrace recording an operation trace // Parameters: // - ctx context.Context // - correlationId (optional) transaction id to trace execution through call chain. // - component a name of called component // - operation a name of the executed operation. // Returns: a trace timing object. BeginTrace(ctx context.Context, correlationId string, component string, operation string) *TraceTiming }
ITracer interface for tracer components that capture operation traces.
type LogTracer ¶
type LogTracer struct {
// contains filtered or unexported fields
}
LogTracer tracer that dumps recorded traces to logger.
Configuration parameters: - options: - log_level: log level to record traces (default: debug) References: - *:logger:*:*:1.0 [[ILogger]] components to dump the captured counters - *:context-info:*:*:1.0 (optional) [[ContextInfo]] to detect the context id and specify counters source See [[Tracer]] See [[CachedCounters]] See [[CompositeLogger]] Example: tracer = NewLogTracer(); tracer.SetReferences( context.Background(), NewReferencesFromTuples( NewDescriptor("pip-services", "logger", "console", "default", "1.0"), NewConsoleLogger() ) ); timing := trcer.BeginTrace(context.Background(), "123", "mycomponent", "mymethod"); ... timing.EndTrace(context.Background()); if err != nil { timing.EndFailure(context.Background(), err); }
func NewLogTracer ¶
func NewLogTracer() *LogTracer
NewLogTracer creates a new instance of the tracer.
func (*LogTracer) BeginTrace ¶
func (c *LogTracer) BeginTrace(ctx context.Context, correlationId string, component string, operation string) *TraceTiming
BeginTrace begins recording an operation trace
Parameters: - ctx context.Context - correlationId (optional) transaction id to trace execution through call chain. - component a name of called component - operation a name of the executed operation. Returns: a trace timing object.
func (*LogTracer) Configure ¶
func (c *LogTracer) Configure(ctx context.Context, config *cconf.ConfigParams)
Configure component by passing configuration parameters.
Parameters: - ctx context.Context - config configuration parameters to be set.
func (*LogTracer) Failure ¶
func (c *LogTracer) Failure(ctx context.Context, correlationId string, component string, operation string, err error, duration int64)
Failure records an operation failure with its name, duration and error
Parameters: - ctx context.Context - correlationId (optional) transaction id to trace execution through call chain. - component a name of called component - operation a name of the executed operation. - error an error object associated with this trace. - duration execution duration in milliseconds.
func (*LogTracer) SetReferences ¶
func (c *LogTracer) SetReferences(ctx context.Context, references cref.IReferences)
SetReferences sets references to dependent components.
Parameters: - ctx context.Context - references references to locate the component dependencies.
func (*LogTracer) Trace ¶
func (c *LogTracer) Trace(ctx context.Context, correlationId string, component string, operation string, duration int64)
Trace records an operation trace with its name and duration
Parameters: - ctx context.Context - correlationId (optional) transaction id to trace execution through call chain. - component a name of called component - operation a name of the executed operation. - duration execution duration in milliseconds.
type NullTracer ¶
type NullTracer struct { }
NullTracer dummy implementation of tracer that doesn't do anything. It can be used in testing or in situations when tracing is required but shall be disabled.
See ITracer
func NewNullTracer ¶
func NewNullTracer() *NullTracer
NewNullTracer creates a new instance of the tracer.
func (*NullTracer) BeginTrace ¶
func (c *NullTracer) BeginTrace(ctx context.Context, correlationId string, component string, operation string) *TraceTiming
BeginTrace begins recording an operation trace
Parameters: - ctx context.Context - correlationId (optional) transaction id to trace execution through call chain. - component a name of called component - operation a name of the executed operation. Returns: a trace timing object.
func (*NullTracer) Failure ¶
func (c *NullTracer) Failure(ctx context.Context, correlationId string, component string, operation string, err error, duration int64)
Failure records an operation failure with its name, duration and error
Parameters: - ctx context.Context - correlationId (optional) transaction id to trace execution through call chain. - component a name of called component - operation a name of the executed operation. - error an error object associated with this trace. - duration execution duration in milliseconds.
func (*NullTracer) Trace ¶
func (c *NullTracer) Trace(ctx context.Context, correlationId string, component string, operation string, duration int64)
Trace records an operation trace with its name and duration
Parameters: - ctx context.Context - correlationId (optional) transaction id to trace execution through call chain. - component a name of called component - operation a name of the executed operation. - duration execution duration in milliseconds.
type OperationTrace ¶
type OperationTrace struct { // The time when operation was executed Time time.Time // The source (context name) Source string `json:"source"` // The name of component Component string `json:"component"` // The name of the executed operation Operation string `json:"operation"` // The transaction id to trace execution through call chain. CorrelationId string `json:"correlation_id"` // The duration of the operation in milliseconds Duration int64 `json:"duration"` //The description of the captured error //ErrorDescription //ApplicationException Error cerr.ErrorDescription `json:"error"` }
OperationTrace data object to store captured operation traces. This object is used by CachedTracer.
type TraceTiming ¶
type TraceTiming struct {
// contains filtered or unexported fields
}
TraceTiming timing object returned by {ITracer.BeginTrace} to end timing of execution block and record the associated trace.
Example: timing := tracer.BeginTrace("mymethod.exec_time"); ... timing.EndTrace(); if err != nil { timing.EndFailure(err); }
func NewTraceTiming ¶
func NewTraceTiming(correlationId string, component string, operation string, tracer ITracer) *TraceTiming
NewTraceTiming creates a new instance of the timing callback object.
Parameters: - correlationId (optional) transaction id to trace execution through call chain. - component an associated component name - operation an associated operation name - callback a callback that shall be called when endTiming is called.
func (*TraceTiming) EndFailure ¶
func (c *TraceTiming) EndFailure(ctx context.Context, err error)
EndFailure ends timing of a failed block, calculates elapsed time and records the associated trace.
Parameters: - ctx context.Context
func (*TraceTiming) EndTrace ¶
func (c *TraceTiming) EndTrace(ctx context.Context)
EndTrace ends timing of an execution block, calculates elapsed time and records the associated trace.
Parameters: - ctx context.Context