Skip to content

Commit ecf723a

Browse files
authored
Fix null ref check in telemetry correlation Utils (#541)
* Fix null ref check in TelemetryCorrelationUtils * Modifying log level to warning * Updating Changelog
1 parent f4c3059 commit ecf723a

File tree

2 files changed

+26
-0
lines changed

2 files changed

+26
-0
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
# CHANGELOG
22

3+
## Version 2.0.0
4+
5+
- Fix #506 Null Reference Check causing Null Pointer Exception in `TelemetryCorrelationUtils.java`
6+
37
## Version 2.0.0-BETA
48
- Updating various dependencies to latest version
59
- Introducing public class CustomClassWriter in Agent to enable finding common super classes used for Agent instrumentation without loading it

web/src/main/java/com/microsoft/applicationinsights/web/internal/correlation/TelemetryCorrelationUtils.java

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,15 @@ public static void resolveCorrelation(HttpServletRequest request, HttpServletRes
111111
public static String generateChildDependencyId() {
112112

113113
try {
114+
114115
RequestTelemetryContext context = ThreadContext.getRequestTelemetryContext();
116+
117+
//check if context is null - no correlation will happen
118+
if (context == null) {
119+
InternalLogger.INSTANCE.warn("No Correlation will happen, Thread context is null while generating child dependency");
120+
return "";
121+
}
122+
115123
RequestTelemetry requestTelemetry = context.getHttpRequestTelemetry();
116124

117125
String parentId = requestTelemetry.getContext().getOperation().getParentId();
@@ -137,6 +145,13 @@ public static String generateChildDependencyId() {
137145
* @return The correlation context as a string.
138146
*/
139147
public static String retrieveCorrelationContext() {
148+
149+
//check if context is null - no correlation will happen
150+
if (ThreadContext.getRequestTelemetryContext() == null) {
151+
InternalLogger.INSTANCE.warn("No correlation wil happen, Thread context is null");
152+
return "";
153+
}
154+
140155
CorrelationContext context = ThreadContext.getRequestTelemetryContext().getCorrelationContext();
141156
return context.toString();
142157
}
@@ -256,6 +271,13 @@ private static void resolveCorrelationContext(HttpServletRequest request, Reques
256271
return;
257272
}
258273

274+
//check if context is null - no correlation will happen
275+
if (ThreadContext.getRequestTelemetryContext() == null) {
276+
InternalLogger.INSTANCE.warn("No correlation will happen " +
277+
"Thread context is null while resolving Correlation Context");
278+
return;
279+
}
280+
259281
CorrelationContext currentCorrelationContext =
260282
ThreadContext.getRequestTelemetryContext().getCorrelationContext();
261283

0 commit comments

Comments
 (0)