|
14 | 14 | * limitations under the License. |
15 | 15 | */ |
16 | 16 |
|
17 | | -import * as uuid from 'uuid' |
18 | | - |
19 | | -import {Span} from './span' |
20 | | -import {Clock} from '../../internal/clock' |
21 | | -import {debug} from '../../internal/util' |
22 | | -import {TraceBaseModel} from '../types/tracetypes' |
| 17 | +import { Span } from './span' |
| 18 | +import { Clock } from '../../internal/clock' |
| 19 | +import * as uuid from 'uuid'; |
| 20 | +import { debug } from '../../internal/util' |
| 21 | +import { TraceBaseModel } from '../types/tracetypes' |
23 | 22 |
|
24 | 23 | export class Trace extends TraceBaseModel { |
25 | 24 |
|
26 | | - private spans: Span[] = []; |
| 25 | + private _spans: Span[]; |
27 | 26 | private _traceId: string; |
28 | 27 |
|
29 | 28 | constructor() { |
30 | 29 | super() |
31 | | - this._traceId = (uuid.v4().split('-').join('')); |
| 30 | + this.setId((uuid.v4().split('-').join(''))); |
| 31 | + this._spans = []; |
32 | 32 | } |
33 | 33 |
|
34 | | - public get traceSpans() : Span[] { |
35 | | - return this.spans; |
| 34 | + public get spans() { |
| 35 | + return this._spans; |
36 | 36 | } |
37 | | - |
38 | | - public get traceId() : string { |
| 37 | + |
| 38 | + public get traceId() { |
39 | 39 | return this._traceId; |
40 | 40 | } |
41 | | - |
| 41 | + |
42 | 42 | public start() { |
43 | | - super.start() |
44 | | - debug('starting trace %o', {traceId: this.traceId}) |
| 43 | + super.start() |
| 44 | + debug('starting trace %o', { id: this.id }) |
45 | 45 | } |
46 | | - |
| 46 | + |
47 | 47 | public end() { |
48 | 48 | super.end() |
49 | 49 |
|
50 | 50 | //TODO - Define logic for list of spans |
51 | | - this.spans.forEach(function (span) { |
| 51 | + this._spans.forEach(function (span) { |
52 | 52 | if (span.ended || !span.started) return |
53 | 53 | span.truncate() |
54 | 54 | }) |
55 | | - |
56 | | - debug('ending trace %o', |
57 | | - {id: this.id, |
58 | | - name: this.name, |
59 | | - startTime: this.startTime, |
60 | | - endTime: this.endTime, |
61 | | - duration: this.duration}) |
| 55 | + |
| 56 | + debug('ending trace %o', |
| 57 | + { id: this.id, name: this.name, startTime: this.startTime, endTime: this.endTime, duration: this.duration }) |
62 | 58 | } |
63 | 59 |
|
64 | 60 | public startSpan(name: string, type: string) { |
65 | 61 | let newSpan = new Span(this); |
66 | 62 | newSpan.name = name |
67 | 63 | newSpan.type = type |
68 | 64 | newSpan.start(); |
69 | | - this.spans.push(newSpan); |
| 65 | + this._spans.push(newSpan); |
70 | 66 | return newSpan; |
71 | 67 | } |
72 | 68 |
|
|
0 commit comments