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
beginTrace
Begings recording an operation trace.
@override
TraceTiming beginTrace(String? correlationId, String component, String operation)
- correlationId: String? - (optional) transaction id to trace execution through a call chain.
- component: String - name of the called component
- operation: String - name of the executed operation.
- return: TraceTiming - a trace timing object.
configure
Configures component by passing configuration parameters.
@override
void configure(ConfigParams config)
- config: ConfigParams - configuration parameters to be set.
failure
Records an operation failure with its name, duration and error
@override
void failure(String? correlationId, String component, String operation, Exception error, int duration)
- correlationId: String? - (optional) transaction id to trace execution through call chain.
- component: String - name of the called component
- operation: String - name of the executed operation.
- error: Exception - an error object associated with this trace.
- duration: int - execution duration in milliseconds.
setReferences
Sets references to dependent components.
@override
void setReferences(IReferences references)
- references: IReferences - references to locate the component dependencies.
trace
Records an operation trace with its name and duration.
@override
void trace(String? correlationId, String component, String operation, int duration)
- correlationId: String? - (optional) transaction id to trace execution through a call chain.
- component: String - name of the called component
- operation: String - name of the executed operation.
- duration: int - execution duration in milliseconds.
Examples
var tracer = LogTracer();
tracer.setReferences(References.fromTuples([
Descriptor('pip-services', 'logger', 'console', 'default', '1.0'), ConsoleLogger()
]));
var timing = tracer.beginTrace('123', 'mycomponent', 'mymethod');
try {
timing.endTrace();
} catch(err) {
timing.endFailure(err);
}