UNPKG

3.18 kBTypeScriptView Raw
1/** @module trace */
2import { IReferenceable } from 'pip-services3-commons-node';
3import { IReferences } from 'pip-services3-commons-node';
4import { ITracer } from './ITracer';
5import { TraceTiming } from './TraceTiming';
6/**
7 * Aggregates all tracers from component references under a single component.
8 *
9 * It allows to record traces and conveniently send them to multiple destinations.
10 *
11 * ### References ###
12 *
13 * - <code>\*:tracer:\*:\*:1.0</code> (optional) [[ITracer]] components to pass operation traces
14 *
15 * @see [[ITracer]]
16 *
17 * ### Example ###
18 *
19 * class MyComponent implements IReferenceable {
20 * private _tracer: CompositeTracer = new CompositeTracer();
21 *
22 * public setReferences(references: IReferences): void {
23 * this._tracer.setReferences(references);
24 * ...
25 * }
26 *
27 * public myMethod(correlatonId: string): void {
28 * var timing = this._tracer.beginTrace(correlationId, "mycomponent", "mymethod");
29 * try {
30 * ...
31 * timing.endTrace();
32 * } catch (err) {
33 * timing.endFailure(err);
34 * }
35 * }
36 * }
37 *
38 */
39export declare class CompositeTracer implements ITracer, IReferenceable {
40 protected readonly _tracers: ITracer[];
41 /**
42 * Creates a new instance of the tracer.
43 *
44 * @param references references to locate the component dependencies.
45 */
46 constructor(references?: IReferences);
47 /**
48 * Sets references to dependent components.
49 *
50 * @param references references to locate the component dependencies.
51 */
52 setReferences(references: IReferences): void;
53 /**
54 * Records an operation trace with its name and duration
55 *
56 * @param correlationId (optional) transaction id to trace execution through call chain.
57 * @param component a name of called component
58 * @param operation a name of the executed operation.
59 * @param duration execution duration in milliseconds.
60 */
61 trace(correlationId: string, component: string, operation: string, duration: number): void;
62 /**
63 * Records an operation failure with its name, duration and error
64 *
65 * @param correlationId (optional) transaction id to trace execution through call chain.
66 * @param component a name of called component
67 * @param operation a name of the executed operation.
68 * @param error an error object associated with this trace.
69 * @param duration execution duration in milliseconds.
70 */
71 failure(correlationId: string, component: string, operation: string, error: Error, duration: number): void;
72 /**
73 * Begings recording an operation trace
74 *
75 * @param correlationId (optional) transaction id to trace execution through call chain.
76 * @param component a name of called component
77 * @param operation a name of the executed operation.
78 * @returns a trace timing object.
79 */
80 beginTrace(correlationId: string, component: string, operation: string): TraceTiming;
81}