Skip to content

Commit 694aaec

Browse files
authored
Merge pull request #1016 from microsoft/minor_tweaks
Minor reworkings
2 parents 1b72094 + 3b4b6cf commit 694aaec

File tree

5 files changed

+22
-31
lines changed

5 files changed

+22
-31
lines changed

ApplicationInsightsInternalLogger/src/main/java/com/microsoft/applicationinsights/internal/logger/InternalLogger.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -307,8 +307,7 @@ private static String createMessage(String prefix, String message, Object... arg
307307
}
308308
String formattedMessage = String.format(message, args);
309309
final Thread thisThread = Thread.currentThread();
310-
String theMessage = String.format("%s %s, %d(%s): %s", prefix, currentDateAsString, thisThread.getId(), thisThread.getName(), formattedMessage);
311-
return theMessage;
310+
return String.format("%s %s, %d(%s): %s", prefix, currentDateAsString, thisThread.getId(), thisThread.getName(), formattedMessage);
312311
}
313312

314313
/**

core/src/main/java/com/microsoft/applicationinsights/internal/channel/samplingV2/FixedRateSamplingTelemetryProcessor.java

Lines changed: 17 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -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
}

core/src/main/java/com/microsoft/applicationinsights/internal/heartbeat/HeartbeatDefaultPayload.java

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,7 @@ public class HeartbeatDefaultPayload {
1414
/**
1515
* List of default payloads which would be added
1616
*/
17-
private static final List<HeartBeatPayloadProviderInterface> defaultPayloadProviders =
18-
new ArrayList<>();
17+
private static final List<HeartBeatPayloadProviderInterface> defaultPayloadProviders = new ArrayList<>();
1918

2019
static {
2120
defaultPayloadProviders.add(new DefaultHeartBeatPropertyProvider());
@@ -59,10 +58,9 @@ public static boolean addDefaultPayLoadProvider(HeartBeatPayloadProviderInterfac
5958
public static Callable<Boolean> populateDefaultPayload(final List<String> disabledFields, final List<String>
6059
disabledProviders, final HeartBeatProviderInterface provider) {
6160
return new Callable<Boolean>() {
62-
63-
volatile boolean populatedFields = false;
6461
@Override
6562
public Boolean call() throws Exception {
63+
boolean populatedFields = false;
6664
for (HeartBeatPayloadProviderInterface payloadProvider : defaultPayloadProviders) {
6765
if (disabledProviders != null && disabledProviders.contains(payloadProvider.getName())) {
6866

core/src/main/java/com/microsoft/applicationinsights/internal/heartbeat/MiscUtils.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
* @author Dhaval Doshi
1212
*/
1313
public class MiscUtils {
14+
private MiscUtils(){}
1415

1516
/**
1617
* Returns a set which contains result of List - Set

core/src/main/java/com/microsoft/applicationinsights/telemetry/BaseTelemetry.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -147,8 +147,7 @@ public void sanitize() {
147147
@Override
148148
public void serialize(JsonTelemetryDataSerializer writer) throws IOException {
149149

150-
String telemetryName = this.getTelemetryName(
151-
this.normalizeInstrumentationKey(context.getInstrumentationKey()), this.getEnvelopName());
150+
String telemetryName = getTelemetryName(normalizeInstrumentationKey(context.getInstrumentationKey()), this.getEnvelopName());
152151

153152
Envelope envelope = new Envelope();
154153
envelope.setName(telemetryName);

0 commit comments

Comments
 (0)