UNPKG

1.51 kBPlain TextView Raw
1import Span from './span';
2import SpanContext from './span_context';
3
4/**
5 * Reference pairs a reference type constant (e.g., REFERENCE_CHILD_OF or
6 * REFERENCE_FOLLOWS_FROM) with the SpanContext it points to.
7 *
8 * See the exported childOf() and followsFrom() functions at the package level.
9 */
10export default class Reference {
11
12 protected _type: string;
13 protected _referencedContext: SpanContext;
14
15 /**
16 * @return {string} The Reference type (e.g., REFERENCE_CHILD_OF or
17 * REFERENCE_FOLLOWS_FROM).
18 */
19 type(): string {
20 return this._type;
21 }
22
23 /**
24 * @return {SpanContext} The SpanContext being referred to (e.g., the
25 * parent in a REFERENCE_CHILD_OF Reference).
26 */
27 referencedContext(): SpanContext {
28 return this._referencedContext;
29 }
30
31 /**
32 * Initialize a new Reference instance.
33 *
34 * @param {string} type - the Reference type constant (e.g.,
35 * REFERENCE_CHILD_OF or REFERENCE_FOLLOWS_FROM).
36 * @param {SpanContext} referencedContext - the SpanContext being referred
37 * to. As a convenience, a Span instance may be passed in instead
38 * (in which case its .context() is used here).
39 */
40 constructor(type: string, referencedContext: SpanContext | Span) {
41 this._type = type;
42 this._referencedContext = (
43 referencedContext instanceof Span ?
44 referencedContext.context() :
45 referencedContext);
46 }
47}