@@ -105,17 +105,12 @@ public Set<Class> getIncludedTypes() {
105105 }
106106
107107
108- private void setIncludedOrExcludedTypes (String value , Set <Class > typeSet ) {
109-
110- if (!StringUtils .isEmpty (value )) {
111- value = value .trim ();
112- if (!StringUtils .isEmpty (value ) && allowedTypes .containsKey (value )) {
113- typeSet .add (allowedTypes .get (value ));
114- } else {
115- InternalLogger .INSTANCE .error ("Item %s is either not allowed to sample or is empty" , value );
116- }
108+ private void setIncludedOrExcludedTypes (String value , Set <Class > typeSet , String verb ) {
109+ Class type = allowedTypes .get (StringUtils .trimToEmpty (value ));
110+ if (type != null ) {
111+ typeSet .add (type );
117112 } else {
118- InternalLogger .INSTANCE .error ("Telemetry type %s is empty " , value );
113+ InternalLogger .INSTANCE .error ("Error configuring %s: %s is not a valid telemetry type to %s. " , FixedRateSamplingTelemetryProcessor . class . getSimpleName (), value , verb );
119114 }
120115 }
121116
@@ -133,13 +128,14 @@ private void setIncludedOrExcludedTypes(String value, Set<Class> typeSet) {
133128 */
134129 public void setSamplingPercentage (String samplingPercentage ) {
135130 try {
136- this .samplingPercentage = Double .valueOf (samplingPercentage );
131+ this .samplingPercentage = Double .parseDouble (samplingPercentage );
137132 InternalLogger .INSTANCE .info ("Sampling rate set to %s" , samplingPercentage );
138133 }
139134 catch (NumberFormatException ex ) {
140135 this .samplingPercentage = 100.0 ;
141- InternalLogger .INSTANCE .error ("Sampling rate specified in improper format, sampling rate is now set to 100.0 (default)" );
142- InternalLogger .INSTANCE .trace ("stack trace is %s" , ExceptionUtils .getStackTrace (ex ));
136+ if (InternalLogger .INSTANCE .isErrorEnabled ()) {
137+ InternalLogger .INSTANCE .error ("Sampling rate specified in improper format. Using default sampling rate, 100.0: %s" , ExceptionUtils .getStackTrace (ex ));
138+ }
143139 }
144140 }
145141
@@ -152,7 +148,7 @@ public void setSamplingPercentage(String samplingPercentage) {
152148 @ Override
153149 public boolean process (Telemetry telemetry ) {
154150
155- double samplingPercentage = this .samplingPercentage ;
151+ double sp = this .samplingPercentage ;
156152
157153 if (telemetry instanceof SupportSampling ) {
158154
@@ -162,24 +158,24 @@ public boolean process(Telemetry telemetry) {
162158
163159 if (samplingSupportingTelemetry .getSamplingPercentage () == null ) {
164160
165- samplingSupportingTelemetry .setSamplingPercentage (samplingPercentage );
161+ samplingSupportingTelemetry .setSamplingPercentage (sp );
166162
167163
168164 } else {
169165 InternalLogger .INSTANCE .info ("Item has sampling percentage already set to :"
170166 + samplingSupportingTelemetry .getSamplingPercentage ());
171167
172- samplingPercentage = samplingSupportingTelemetry .getSamplingPercentage ();
168+ sp = samplingSupportingTelemetry .getSamplingPercentage ();
173169 }
174170
175- if (SamplingScoreGeneratorV2 .getSamplingScore (telemetry ) >= samplingPercentage ) {
171+ if (SamplingScoreGeneratorV2 .getSamplingScore (telemetry ) >= sp ) {
176172
177- InternalLogger .INSTANCE .info ("Item %s sampled out" , telemetry .getClass ());
173+ InternalLogger .INSTANCE .info ("Item %s sampled out" , telemetry .getClass (). getSimpleName () );
178174 return false ;
179175 }
180176
181177 } else {
182- InternalLogger .INSTANCE .trace ("Skip sampling since %s type is not sampling applicable" , telemetry .getClass ());
178+ InternalLogger .INSTANCE .trace ("Skip sampling since %s type is not sampling applicable" , telemetry .getClass (). getSimpleName () );
183179 }
184180 }
185181
@@ -212,8 +208,7 @@ private boolean isSamplingApplicable(Class item) {
212208 */
213209 public void addToExcludedType (String value ) {
214210
215- setIncludedOrExcludedTypes (value , excludedTypes );
216- InternalLogger .INSTANCE .trace ("%s added as excluded to sampling" , value );
211+ setIncludedOrExcludedTypes (value , excludedTypes , "exclude" );
217212
218213 }
219214
@@ -224,8 +219,7 @@ public void addToExcludedType(String value) {
224219 */
225220 public void addToIncludedType (String value ) {
226221
227- setIncludedOrExcludedTypes (value , includedTypes );
228- InternalLogger .INSTANCE .trace ("%s added as included to sampling" , value );
222+ setIncludedOrExcludedTypes (value , includedTypes , "include" );
229223
230224 }
231225}
0 commit comments