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

Commit a2d3345

Browse files
committed
chord: merge commit
2 parents 2b12413 + 32360cb commit a2d3345

6 files changed

Lines changed: 53 additions & 54 deletions

File tree

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

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,18 @@ export class RootSpan extends SpanBaseModel implements OnEndSpanEventListener {
7575
}
7676

7777
public startSpan(name: string, type: string) {
78+
if (!this.started) {
79+
debug('calling %s.startSpan() on un-started %s %o',
80+
this._className, this._className,
81+
{ id: this.id, name: this.name, type: this.type })
82+
return
83+
}
84+
if (this.ended) {
85+
debug('calling %s.startSpan() on ended %s %o',
86+
this._className, this._className,
87+
{ id: this.id, name: this.name, type: this.type })
88+
return
89+
}
7890
let newSpan = new Span(this);
7991
newSpan.name = name
8092
newSpan.type = type

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ export class Sampler{
7171
if(probability < minNumber){
7272
return this.never();
7373

74-
} else if (probability > maxNumber){
74+
} else if (probability > maxNumber) {
7575
return this.always();
7676

7777
}
@@ -93,6 +93,6 @@ export class Sampler{
9393
}else{
9494
return false;
9595
}
96-
}
96+
}
9797

98-
}
98+
}

packages/opencensus-core/src/trace/types/tracetypes.ts

Lines changed: 19 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -23,27 +23,27 @@ export interface MapLabels { [propName: string]: string; }
2323
export interface MapObjects { [propName: string]: any; }
2424

2525
export interface TraceContext {
26-
traceId: string,
27-
spanId: string,
28-
options?: number
26+
traceId: string,
27+
spanId: string,
28+
options?: number
2929
}
3030

3131
export interface TraceOptions {
32-
name:string;
33-
traceContext?:TraceContext;
34-
sampler?:Sampler;
32+
name: string;
33+
traceContext?: TraceContext;
34+
sampler?: Sampler;
3535
}
3636

3737
export interface OnEndSpanEventListener {
38-
onEndSpan(span: SpanBaseModel): void;
38+
onEndSpan(span: SpanBaseModel): void;
3939
}
4040

4141
export interface SpanData {
42-
labels: {[key: string]: string};
42+
labels: { [key: string]: string };
4343
name: string;
4444
spanId: string;
4545
parentSpanId?: string;
46-
}
46+
}
4747

4848

4949
export abstract class SpanBaseModel {
@@ -129,20 +129,20 @@ export abstract class SpanBaseModel {
129129
}
130130

131131
public get startTime(): Date {
132-
if(this.clock){
132+
if (this.clock) {
133133
return this.clock.startTime;
134134
}
135-
135+
136136
}
137137

138138
public get endTime(): Date {
139-
if(this.clock){
139+
if (this.clock) {
140140
return this.clock.endTime;
141141
}
142142
}
143143

144144
public get duration(): number {
145-
if(this.clock){
145+
if (this.clock) {
146146
return this.clock.duration;
147147
}
148148
}
@@ -165,12 +165,12 @@ export abstract class SpanBaseModel {
165165
this.annotations[key] = value;
166166
}
167167

168-
public get sampler(){
168+
public get sampler() {
169169
debug('tracetypes get sampler()')
170170
return this._sampler;
171171
}
172172

173-
public set sampler(sampler:Sampler){
173+
public set sampler(sampler: Sampler) {
174174
debug('tracetypes set sempler(sampler)')
175175
this._sampler = sampler;
176176
}
@@ -192,10 +192,11 @@ export abstract class SpanBaseModel {
192192
this._className, this._className,
193193
{ id: this.id, name: this.name, type: this.type })
194194
return
195-
} else if (this.ended) {
195+
}
196+
if (this.ended) {
196197
debug('calling %s.end() on already ended %s %o',
197-
this._className, this._className,
198-
{ id: this.id, name: this.name, type: this.type })
198+
this._className, this._className,
199+
{ id: this.id, name: this.name, type: this.type })
199200
return
200201
}
201202
this._started = false;

packages/opencensus-core/test/test-root-span.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/**
2-
* Copyright 2017 Google Inc. All Rights Reserved.
2+
* Copyright 2018 Google Inc. All Rights Reserved.
33
*
44
* Licensed under the Apache License, Version 2.0 (the 'License');
55
* you may not use this file except in compliance with the License.

packages/opencensus-core/test/test-span.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/**
2-
* Copyright 2017 Google Inc. All Rights Reserved.
2+
* Copyright 2018 Google Inc. All Rights Reserved.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.

packages/opencensus-core/test/test-tracer.ts

Lines changed: 17 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/**
2-
* Copyright 2017 Google Inc. All Rights Reserved.
2+
* Copyright 2018 Google Inc. All Rights Reserved.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -23,10 +23,7 @@ let assert = require('assert');
2323

2424
describe('Tracer', function () {
2525
const options = { name: "test" };
26-
const callback = (root) => {
27-
28-
return root;
29-
}
26+
const callback = (root) => { return root; }
3027

3128
describe('new Tracer()', function () {
3229
it('should create a Tracer instance', function () {
@@ -52,35 +49,27 @@ describe('Tracer', function () {
5249
describe('startRootSpan()', function () {
5350

5451
it('should start the rootSpan', function () {
55-
const tracer = new Tracer();
56-
tracer.start();
57-
const root = tracer.startRootSpan(options, callback);
58-
59-
assert.ok(root.started);
60-
});
61-
62-
it('should set the new span root as currentRootSpan', function () {
63-
const tracer = new Tracer();
52+
let tracer = new Tracer();
6453
tracer.start();
65-
const root = tracer.startRootSpan(options, callback);
54+
let rootSpan = tracer.startRootSpan(options, callback);
6655

67-
assert.equal(tracer.currentRootSpan.id, root.id);
56+
assert.ok(rootSpan.started);
6857
});
6958
});
7059

7160
describe('end()', function () {
7261
it('should end current trace', function () {
73-
const tracer = new Tracer();
74-
const trace = tracer.startRootSpan(options, callback);
75-
trace.end();
76-
assert.ok(trace.ended);
62+
let tracer = new Tracer();
63+
let rootSpan = tracer.startRootSpan(options, callback);
64+
rootSpan.end();
65+
assert.ok(rootSpan.ended);
7766
});
7867
});
7968

8069
describe('clearCurrentRootSpan()', function () {
8170
it('should set the current root span to null', function () {
82-
const tracer = new Tracer();
83-
const trace = tracer.startRootSpan(options, callback);
71+
let tracer = new Tracer();
72+
let rootSpan = tracer.startRootSpan(options, callback);
8473
tracer.clearCurrentTrace();
8574

8675
assert.ok(tracer.currentRootSpan == null);
@@ -89,19 +78,16 @@ describe('Tracer', function () {
8978

9079
describe('startSpan()', function () {
9180
it('should return a Span instance', function () {
92-
const tracer = new Tracer();
93-
const trace = tracer.startRootSpan(options, callback);
94-
trace.start();
95-
const span = tracer.startSpan("spanName", "spanType");
96-
console.log(span);
81+
let tracer = new Tracer();
82+
let rootSpan = tracer.startRootSpan(options, callback);
83+
let span = tracer.startSpan("spanName", "spanType");
9784
assert.ok(span instanceof Span);
9885
});
9986

10087
it('should start a span', function () {
101-
const tracer = new Tracer();
102-
const trace = tracer.startRootSpan(options, callback);
103-
trace.start();
104-
const span = tracer.startSpan("spanName", "spanType");
88+
let tracer = new Tracer();
89+
let rootSpan = tracer.startRootSpan(options, callback);
90+
let span = tracer.startSpan("spanName", "spanType");
10591
assert.ok(span.started);
10692
});
10793
});

0 commit comments

Comments
 (0)