Skip to content
This repository was archived by the owner on Oct 3, 2023. It is now read-only.

Commit 50b920d

Browse files
added basic struct
1 parent 7491376 commit 50b920d

1 file changed

Lines changed: 21 additions & 25 deletions

File tree

  • packages/opencensus-core/src/trace/model

packages/opencensus-core/src/trace/model/trace.ts

Lines changed: 21 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -14,59 +14,55 @@
1414
* limitations under the License.
1515
*/
1616

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'
2322

2423
export class Trace extends TraceBaseModel {
2524

26-
private spans: Span[] = [];
25+
private _spans: Span[];
2726
private _traceId: string;
2827

2928
constructor() {
3029
super()
31-
this._traceId = (uuid.v4().split('-').join(''));
30+
this.setId((uuid.v4().split('-').join('')));
31+
this._spans = [];
3232
}
3333

34-
public get traceSpans() : Span[] {
35-
return this.spans;
34+
public get spans() {
35+
return this._spans;
3636
}
37-
38-
public get traceId() : string {
37+
38+
public get traceId() {
3939
return this._traceId;
4040
}
41-
41+
4242
public start() {
43-
super.start()
44-
debug('starting trace %o', {traceId: this.traceId})
43+
super.start()
44+
debug('starting trace %o', { id: this.id })
4545
}
46-
46+
4747
public end() {
4848
super.end()
4949

5050
//TODO - Define logic for list of spans
51-
this.spans.forEach(function (span) {
51+
this._spans.forEach(function (span) {
5252
if (span.ended || !span.started) return
5353
span.truncate()
5454
})
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 })
6258
}
6359

6460
public startSpan(name: string, type: string) {
6561
let newSpan = new Span(this);
6662
newSpan.name = name
6763
newSpan.type = type
6864
newSpan.start();
69-
this.spans.push(newSpan);
65+
this._spans.push(newSpan);
7066
return newSpan;
7167
}
7268

0 commit comments

Comments
 (0)