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

Commit 088abb0

Browse files
committed
chord: merge commit
1 parent cd6cf28 commit 088abb0

3 files changed

Lines changed: 28 additions & 16 deletions

File tree

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

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -73,21 +73,19 @@ export class Tracer implements OnEndSpanEventListener {
7373
}
7474

7575
public startRootSpan<T>(options: TraceOptions, fn: (root: RootSpan) => T): T {
76-
debug('starting root span: %o', options)
7776
return this.contextManager.runAndReturn((root) => {
7877
let newRoot = new RootSpan(this, options);
7978
this.setCurrentRootSpan(newRoot);
80-
debug('ELDREY -> START ROOT SPAN OPTIONS: ',options);
8179
if(options.sampler == null){
8280
options.sampler = new Sampler(newRoot.traceId);
83-
options.sampler.always();
81+
options.sampler.probability(0.6);
8482
}
8583
newRoot.sampler = options.sampler;
8684
if(newRoot.sampler.continue(newRoot.traceId)){
87-
debug('ELDREY -> START ROOT SPAN .START()');
8885
newRoot.start();
86+
return fn(newRoot);
8987
}
90-
return fn(newRoot);
88+
return fn(null);
9189
});
9290
}
9391

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

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -70,17 +70,20 @@ export class Sampler{
7070
public continue (traceId:string):boolean{
7171
debug('Samplre continue')
7272
let lower_bytes = traceId.substring(16)
73-
let j;
7473
let lower_long: number
75-
debug('ELDREY -> SAMPLER CONTINUE lower_bytes :',lower_bytes)
74+
debug('SAMPLER CONTINUE lower_bytes :',lower_bytes)
7675

7776
lower_long = parseInt(lower_bytes, 16);
7877

79-
debug('ELDREY -> SAMPLER CONTINUE lower_long :',lower_long)
80-
debug('ELDREY -> SAMPLER CONTINUE this.idUpperBound :',this.idUpperBound)
78+
debug('SAMPLER CONTINUE lower_long :',lower_long)
79+
debug('SAMPLER CONTINUE this.idUpperBound :',this.idUpperBound)
80+
debug('SAMPLER CONTINUE diff :',lower_long - this.idUpperBound)
81+
8182
if(lower_long <= this.idUpperBound){
83+
debug('trace sampler TRUE')
8284
return true
8385
}else{
86+
debug('trace sampler FALSE')
8487
return false;
8588
}
8689
}

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

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ export abstract class SpanBaseModel {
6969
this.setId(randomSpanId());
7070
}
7171

72+
7273
public get id(): string {
7374
return this._id;
7475
}
@@ -120,15 +121,22 @@ export abstract class SpanBaseModel {
120121
}
121122

122123
public get startTime(): Date {
123-
return this.clock.startTime;
124+
if(this.clock){
125+
return this.clock.startTime;
126+
}
127+
124128
}
125129

126130
public get endTime(): Date {
127-
return this.clock.endTime;
131+
if(this.clock){
132+
return this.clock.endTime;
133+
}
128134
}
129135

130136
public get duration(): number {
131-
return this.clock.duration;
137+
if(this.clock){
138+
return this.clock.duration;
139+
}
132140
}
133141

134142
public get traceContext(): TraceContext {
@@ -173,13 +181,16 @@ export abstract class SpanBaseModel {
173181
public end(): void {
174182
if (!this.started) {
175183
debug('calling %s.end() on un-started %s %o',
176-
this._className, this._className,
177-
{ id: this.id, name: this.name, type: this.type })
184+
this._className, this._className,
185+
{ id: this.id, name: this.name, type: this.type })
186+
this._started = false;
187+
this._ended = true;
188+
// this.clock.end();
178189
return
179190
} else if (this.ended) {
180191
debug('calling %s.end() on already ended %s %o',
181-
this._className, this._className,
182-
{ id: this.id, name: this.name, type: this.type })
192+
this._className, this._className,
193+
{ id: this.id, name: this.name, type: this.type })
183194
return
184195
}
185196
this._started = false;

0 commit comments

Comments
 (0)