UNPKG

1.19 kBPlain TextView Raw
1import * as Constants from './constants';
2import Reference from './reference';
3import Span from './span';
4import SpanContext from './span_context';
5
6/**
7 * Return a new REFERENCE_CHILD_OF reference.
8 *
9 * @param {SpanContext} spanContext - the parent SpanContext instance to
10 * reference.
11 * @return a REFERENCE_CHILD_OF reference pointing to `spanContext`
12 */
13export function childOf(spanContext: SpanContext | Span): Reference {
14 // Allow the user to pass a Span instead of a SpanContext
15 if (spanContext instanceof Span) {
16 spanContext = spanContext.context();
17 }
18 return new Reference(Constants.REFERENCE_CHILD_OF, spanContext);
19}
20
21/**
22 * Return a new REFERENCE_FOLLOWS_FROM reference.
23 *
24 * @param {SpanContext} spanContext - the parent SpanContext instance to
25 * reference.
26 * @return a REFERENCE_FOLLOWS_FROM reference pointing to `spanContext`
27 */
28export function followsFrom(spanContext: SpanContext | Span): Reference {
29 // Allow the user to pass a Span instead of a SpanContext
30 if (spanContext instanceof Span) {
31 spanContext = spanContext.context();
32 }
33 return new Reference(Constants.REFERENCE_FOLLOWS_FROM, spanContext);
34}