|
14 | 14 | * limitations under the License. |
15 | 15 | */ |
16 | 16 |
|
17 | | -import { Clock } from '../../internal/clock' |
18 | | -import { RootSpan } from './rootspan' |
19 | | -import { debug, randomSpanId } from '../../internal/util' |
20 | | -import { SpanBaseModel, TraceContext } from '../types/tracetypes' |
21 | | - |
| 17 | +import {Clock} from '../../internal/clock'; |
| 18 | +import {debug, randomSpanId} from '../../internal/util'; |
| 19 | +import {SpanBaseModel, TraceContext} from '../types/tracetypes'; |
| 20 | +import {RootSpan} from './rootspan'; |
22 | 21 |
|
| 22 | +/** |
| 23 | + * This class represent a span. |
| 24 | + */ |
23 | 25 | export class Span extends SpanBaseModel { |
| 26 | + private root: RootSpan; |
24 | 27 |
|
25 | | - private root: RootSpan; |
26 | | - // private _parentSpanId: string; |
27 | | - |
28 | | - constructor(root: RootSpan) { |
29 | | - super() |
30 | | - this.root = root; |
31 | | - } |
32 | | - |
33 | | - public get traceId(): string { |
34 | | - return this.root.traceId; |
35 | | - } |
36 | | - |
37 | | - public get parentSpanId(): string { |
38 | | - return this.root.id; |
39 | | - } |
| 28 | + /** |
| 29 | + * Constructs a new Span instance. |
| 30 | + * @param root |
| 31 | + */ |
| 32 | + constructor(root: RootSpan) { |
| 33 | + super(); |
| 34 | + this.root = root; |
| 35 | + } |
40 | 36 |
|
41 | | - public get traceContext(): TraceContext { |
42 | | - return { |
43 | | - traceId: this.traceId.toString(), |
44 | | - spanId: this.id.toString(), |
45 | | - options: 1 // always traced |
46 | | - }; |
47 | | - } |
| 37 | + /** Gets trace id of rootspan. */ |
| 38 | + get traceId(): string { |
| 39 | + return this.root.traceId; |
| 40 | + } |
48 | 41 |
|
49 | | - public start() { |
50 | | - super.start(); |
51 | | - debug('starting span %o', |
52 | | - { |
53 | | - traceId: this.traceId, |
54 | | - spanId: this.id, |
55 | | - name: this.name |
56 | | - }) |
57 | | - } |
| 42 | + /** Gets trace id of rootspan. */ |
| 43 | + get parentSpanId(): string { |
| 44 | + return this.root.id; |
| 45 | + } |
58 | 46 |
|
59 | | - private notifyEnd () { |
60 | | - this.root.onEndSpan(this); |
61 | | - } |
| 47 | + /** Gets trace context of rootspan. */ |
| 48 | + get traceContext(): TraceContext { |
| 49 | + return { |
| 50 | + traceId: this.traceId.toString(), |
| 51 | + spanId: this.id.toString(), |
| 52 | + options: 1 // always traced |
| 53 | + }; |
| 54 | + } |
62 | 55 |
|
63 | | - public end(): void { |
64 | | - // if(this.sampler.continue(this.traceId)) { |
65 | | - |
66 | | - super.end(); |
67 | | - this.notifyEnd(); |
68 | | - debug('ending span %o', |
69 | | - { |
70 | | - spanId: this.id, |
71 | | - traceId: this.traceId, |
72 | | - name: this.name, |
73 | | - startTime: this.startTime, |
74 | | - endTime: this.endTime, |
75 | | - duration: this.duration |
76 | | - }); |
77 | | - // } |
78 | | - } |
| 56 | + /** Starts the span instance. */ |
| 57 | + start() { |
| 58 | + super.start(); |
| 59 | + debug( |
| 60 | + 'starting span %o', |
| 61 | + {traceId: this.traceId, spanId: this.id, name: this.name}); |
| 62 | + } |
79 | 63 |
|
| 64 | + /** Notifies an end operation on span instance. */ |
| 65 | + private notifyEnd() { |
| 66 | + this.root.onEndSpan(this); |
| 67 | + } |
80 | 68 |
|
| 69 | + /** Ends the span. */ |
| 70 | + end(): void { |
| 71 | + super.end(); |
| 72 | + this.notifyEnd(); |
| 73 | + debug('ending span %o', { |
| 74 | + spanId: this.id, |
| 75 | + traceId: this.traceId, |
| 76 | + name: this.name, |
| 77 | + startTime: this.startTime, |
| 78 | + endTime: this.endTime, |
| 79 | + duration: this.duration |
| 80 | + }); |
| 81 | + } |
81 | 82 | } |
0 commit comments