This repository was archived by the owner on Oct 3, 2023. It is now read-only.
File tree Expand file tree Collapse file tree
packages/opencensus-core/src/trace Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -37,6 +37,8 @@ export class TracerImpl implements Tracer {
3737 //TODO: temp solution
3838 private endedTraces : RootSpan [ ] = [ ] ;
3939
40+ samplingRate : number ;
41+
4042 constructor ( ) {
4143 this . activeLocal = false ;
4244 this . contextManager = cls . createNamespace ( ) ;
@@ -75,12 +77,12 @@ export class TracerImpl implements Tracer {
7577 if ( ! options ) {
7678 options = { } as TraceOptions ;
7779 }
78- if ( ! options . sampler ) {
79- options . sampler = new SamplerImpl ( newRoot . traceId ) ;
80- // options.sampler.probability(0.5 );
81- options . sampler . always ( ) ;
82- }
83- newRoot . sampler = options . sampler ;
80+ // if (!options.sampler) {
81+ // options.sampler = new SamplerImpl(newRoot.traceId);
82+ // options.sampler.always( );
83+ // }
84+ // newRoot.sampler = options.sampler;
85+ newRoot . sampler = new SamplerImpl ( ) . probability ( this . samplingRate ) ;
8486 if ( newRoot . sampler . shouldSample ( newRoot . traceId ) ) {
8587 newRoot . start ( ) ;
8688 return fn ( newRoot ) ;
Original file line number Diff line number Diff line change @@ -148,6 +148,9 @@ export interface RootSpan extends Span, OnEndSpanEventListener {
148148export interface Tracer {
149149 /** Get and set the currentRootSpan to tracer instance */
150150 currentRootSpan : RootSpan ;
151+
152+ samplingRate : number ;
153+
151154 /** Get the eventListeners from tracer instance */
152155 readonly eventListeners : OnEndSpanEventListener [ ] ;
153156 /** Get the active status from tracer instance */
Original file line number Diff line number Diff line change @@ -64,14 +64,14 @@ export class SamplerImpl {
6464 * @param probability probability between 0 and 1
6565 * @returns a Sampler object
6666 */
67- probability ( probability : number ) : Sampler {
68- if ( probability < MIN_NUMBER ) {
69- return this . never ( ) ;
70-
71- } else if ( probability > MAX_NUMBER ) {
67+ probability ( probability ?: number ) : Sampler {
68+ if ( ! probability || probability > MAX_NUMBER ) {
7269 return this . always ( ) ;
7370 }
71+ else if ( probability < MIN_NUMBER ) {
72+ return this . never ( ) ;
7473
74+ }
7575 this . idUpperBound = probability * MAX_NUMBER ;
7676 return this ;
7777 }
@@ -93,4 +93,18 @@ export class SamplerImpl {
9393 return false ;
9494 }
9595 }
96+
97+ // setRate(samplerRate?:number){
98+ // if(samplerRate){
99+ // if(samplerRate <= MIN_NUMBER){
100+ // this.never();
101+ // }else if(samplerRate >= MAX_NUMBER){
102+ // this.always();
103+ // }else{
104+ // this.probability(samplerRate);
105+ // }
106+ // }else{
107+ // this.always();
108+ // }
109+ // }
96110}
Original file line number Diff line number Diff line change @@ -19,10 +19,13 @@ import {Sampler} from './config/types';
1919import { Exporter } from '../exporters/types' ;
2020
2121
22- export interface Tracing {
22+ export interface Tracing {
2323 readonly tracer : Tracer ;
24- readonly sampler : Sampler ;
24+ // readonly sampler: Sampler;
2525 readonly exporter : Exporter ;
26- start ( ) : Tracing ;
26+ start ( opstion ?: OptionsTracing ) : Tracing ;
2727 stop ( ) : void ;
2828}
29+ export interface OptionsTracing {
30+ samplingRate ?: number ;
31+ }
You can’t perform that action at this time.
0 commit comments