Tracer that dumps recorded traces to a logger.
Implements: IReconfigurable, IReferenceable, ITracer
Description
The LogTracer class allows you to create a tracer that dumps recorded traces to a 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
Instance methods
begin_trace
Begings recording an operation trace.
begin_trace(context: Optional[IContext], component: str, operation: str): TraceTiming
- context: IContext - (optional) a context to trace execution through a call chain.
- component: str - name of the called component
- operation: str - name of the executed operation.
- return: TraceTiming - a trace timing object.
configure
Configures component by passing configuration parameters.
configure(config: ConfigParams)
- config: ConfigParams - configuration parameters to be set.
failure
Records an operation failure with its name, duration and error
failure(context: Optional[IContext], component: str, operation: str, error: Exception, duration: float)
- context: IContext - (optional) a context to trace execution through a call chain.
- component: str - name of the called component
- operation: str - name of the executed operation.
- error: Exception - an error object associated with this trace.
- duration: float - execution duration in milliseconds.
set_references
Sets references to dependent components.
set_references(references: IReferences)
- references: IReferences - references to locate the component dependencies.
trace
Records an operation trace with its name and duration.
trace(context: Optional[IContext], component: str, operation: str, duration: float)
- context: IContext - (optional) a context to trace execution through a call chain.
- component: str - name of the called component
- operation: str - name of the executed operation.
- duration: float - execution duration in milliseconds.
Examples
tracer = LogTracer()
tracer.set_references(References.from_tuples(
Descriptor("pip-services", "logger", "console", "default", "1.0"), ConsoleLogger()
))
timing = tracer.begin_trace("123", "mycomponent", "mymethod")
try:
...
timing.end_trace()
except Exception as err:
timing.end_failure(err)