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

Commit 5e4ef9b

Browse files
committed
Enable propagation to work with non sampled spans
1 parent e409d69 commit 5e4ef9b

3 files changed

Lines changed: 29 additions & 31 deletions

File tree

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ export class Tracer implements OnEndSpanEventListener {
8181
}
8282
if (!options.sampler) {
8383
options.sampler = new Sampler(newRoot.traceId);
84-
// options.sampler.probability(0.6);
84+
//options.sampler.probability(0.5);
8585
options.sampler.always();
8686
}
8787
newRoot.sampler = options.sampler;

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

Lines changed: 28 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -23,38 +23,38 @@ const maxNumber = 0xffffffffffffffff;
2323
/**
2424
* Class Sampler
2525
*/
26-
export class Sampler{
27-
traceId: string;
28-
private idUpperBound: number;
26+
export class Sampler {
27+
traceId: string;
28+
private idUpperBound: number;
2929

30-
/**
31-
* @param traceId Used for probability calculation
32-
* @param spanId todo: integration with propagation class
33-
* @param isRemote todo: integration with propagation class
34-
*/
35-
constructor(traceId?:string, spanId?:string, isRemote?:boolean){
36-
if(traceId){
37-
this.traceId = traceId;
38-
}
39-
}
30+
/**
31+
* @param traceId Used for probability calculation
32+
* @param spanId todo: integration with propagation class
33+
* @param isRemote todo: integration with propagation class
34+
*/
35+
constructor(traceId?: string, spanId?: string, isRemote?: boolean) {
36+
if (traceId) {
37+
this.traceId = traceId;
38+
}
39+
}
4040

4141
/**
4242
* @description Set idUpperBound with maxNumber
4343
* @returns a Sampler object
4444
*/
45-
public always(): Sampler{
46-
this.idUpperBound = maxNumber;
47-
return this;
48-
}
45+
public always(): Sampler {
46+
this.idUpperBound = maxNumber;
47+
return this;
48+
}
4949

5050
/**
5151
* @description Set idUpperBound with minNumber
5252
* @returns a Sampler object
5353
*/
54-
public never(): Sampler{
55-
this.idUpperBound = minNumber;
56-
return this;
57-
}
54+
public never(): Sampler {
55+
this.idUpperBound = minNumber;
56+
return this;
57+
}
5858

5959
/**
6060
* @description Set idUpperBound with the probability. If probability
@@ -63,8 +63,8 @@ export class Sampler{
6363
* @param probability probability between 0 and 1
6464
* @returns a Sampler object
6565
*/
66-
public probability(probability:number): Sampler{
67-
if(probability < minNumber){
66+
public probability(probability: number): Sampler {
67+
if (probability < minNumber) {
6868
return this.never();
6969

7070
} else if (probability > maxNumber) {
@@ -74,20 +74,20 @@ export class Sampler{
7474

7575
this.idUpperBound = probability * maxNumber;
7676
return this;
77-
}
78-
77+
}
78+
7979
/**
8080
* @description
8181
* @param traceId
8282
* @returns a boolean
8383
*/
84-
public shouldSample (traceId:string):boolean{
84+
public shouldSample(traceId: string): boolean {
8585
const lower_bytes = traceId.substring(16)
8686
const lower_long = parseInt(lower_bytes, 16);
8787

88-
if(lower_long <= this.idUpperBound){
88+
if (lower_long <= this.idUpperBound) {
8989
return true
90-
}else{
90+
} else {
9191
return false;
9292
}
9393
}

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

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -178,12 +178,10 @@ export abstract class SpanBaseModel {
178178
}
179179

180180
public get sampler() {
181-
debug('tracetypes get sampler()')
182181
return this._sampler;
183182
}
184183

185184
public set sampler(sampler: Sampler) {
186-
debug('tracetypes set sempler(sampler)')
187185
this._sampler = sampler;
188186
}
189187

0 commit comments

Comments
 (0)