UNPKG

5.57 kBTypeScriptView Raw
1import SpanContext from './span_context';
2import Tracer from './tracer';
3/**
4 * Span represents a logical unit of work as part of a broader Trace. Examples
5 * of span might include remote procedure calls or a in-process function calls
6 * to sub-components. A Trace has a single, top-level "root" Span that in turn
7 * may have zero or more child Spans, which in turn may have children.
8 */
9export declare class Span {
10 /**
11 * Returns the SpanContext object associated with this Span.
12 *
13 * @return {SpanContext}
14 */
15 context(): SpanContext;
16 /**
17 * Returns the Tracer object used to create this Span.
18 *
19 * @return {Tracer}
20 */
21 tracer(): Tracer;
22 /**
23 * Sets the string name for the logical operation this span represents.
24 *
25 * @param {string} name
26 */
27 setOperationName(name: string): this;
28 /**
29 * Sets a key:value pair on this Span that also propagates to future
30 * children of the associated Span.
31 *
32 * setBaggageItem() enables powerful functionality given a full-stack
33 * opentracing integration (e.g., arbitrary application data from a web
34 * client can make it, transparently, all the way into the depths of a
35 * storage system), and with it some powerful costs: use this feature with
36 * care.
37 *
38 * IMPORTANT NOTE #1: setBaggageItem() will only propagate baggage items to
39 * *future* causal descendants of the associated Span.
40 *
41 * IMPORTANT NOTE #2: Use this thoughtfully and with care. Every key and
42 * value is copied into every local *and remote* child of the associated
43 * Span, and that can add up to a lot of network and cpu overhead.
44 *
45 * @param {string} key
46 * @param {string} value
47 */
48 setBaggageItem(key: string, value: string): this;
49 /**
50 * Returns the value for a baggage item given its key.
51 *
52 * @param {string} key
53 * The key for the given trace attribute.
54 * @return {string}
55 * String value for the given key, or undefined if the key does not
56 * correspond to a set trace attribute.
57 */
58 getBaggageItem(key: string): string | undefined;
59 /**
60 * Adds a single tag to the span. See `addTags()` for details.
61 *
62 * @param {string} key
63 * @param {any} value
64 */
65 setTag(key: string, value: any): this;
66 /**
67 * Adds the given key value pairs to the set of span tags.
68 *
69 * Multiple calls to addTags() results in the tags being the superset of
70 * all calls.
71 *
72 * The behavior of setting the same key multiple times on the same span
73 * is undefined.
74 *
75 * The supported type of the values is implementation-dependent.
76 * Implementations are expected to safely handle all types of values but
77 * may choose to ignore unrecognized / unhandle-able values (e.g. objects
78 * with cyclic references, function objects).
79 *
80 * @return {[type]} [description]
81 */
82 addTags(keyValueMap: {
83 [key: string]: any;
84 }): this;
85 /**
86 * Add a log record to this Span, optionally at a user-provided timestamp.
87 *
88 * For example:
89 *
90 * span.log({
91 * size: rpc.size(), // numeric value
92 * URI: rpc.URI(), // string value
93 * payload: rpc.payload(), // Object value
94 * "keys can be arbitrary strings": rpc.foo(),
95 * });
96 *
97 * span.log({
98 * "error.description": someError.description(),
99 * }, someError.timestampMillis());
100 *
101 * @param {object} keyValuePairs
102 * An object mapping string keys to arbitrary value types. All
103 * Tracer implementations should support bool, string, and numeric
104 * value types, and some may also support Object values.
105 * @param {number} timestamp
106 * An optional parameter specifying the timestamp in milliseconds
107 * since the Unix epoch. Fractional values are allowed so that
108 * timestamps with sub-millisecond accuracy can be represented. If
109 * not specified, the implementation is expected to use its notion
110 * of the current time of the call.
111 */
112 log(keyValuePairs: {
113 [key: string]: any;
114 }, timestamp?: number): this;
115 /**
116 * DEPRECATED
117 */
118 logEvent(eventName: string, payload: any): void;
119 /**
120 * Sets the end timestamp and finalizes Span state.
121 *
122 * With the exception of calls to Span.context() (which are always allowed),
123 * finish() must be the last call made to any span instance, and to do
124 * otherwise leads to undefined behavior.
125 *
126 * @param {number} finishTime
127 * Optional finish time in milliseconds as a Unix timestamp. Decimal
128 * values are supported for timestamps with sub-millisecond accuracy.
129 * If not specified, the current time (as defined by the
130 * implementation) will be used.
131 */
132 finish(finishTime?: number): void;
133 protected _context(): SpanContext;
134 protected _tracer(): Tracer;
135 protected _setOperationName(name: string): void;
136 protected _setBaggageItem(key: string, value: string): void;
137 protected _getBaggageItem(key: string): string | undefined;
138 protected _addTags(keyValuePairs: {
139 [key: string]: any;
140 }): void;
141 protected _log(keyValuePairs: {
142 [key: string]: any;
143 }, timestamp?: number): void;
144 protected _finish(finishTime?: number): void;
145}
146export default Span;
147//# sourceMappingURL=span.d.ts.map
\No newline at end of file