Skip to content

Commit

Permalink
Fix null ref check in telemetry correlation Utils (#541)
Browse files Browse the repository at this point in the history
* Fix null ref check in TelemetryCorrelationUtils

* Modifying log level to warning

* Updating Changelog
  • Loading branch information
dhaval24 authored Feb 1, 2018
1 parent f4c3059 commit ecf723a
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 0 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# CHANGELOG

## Version 2.0.0

- Fix #506 Null Reference Check causing Null Pointer Exception in `TelemetryCorrelationUtils.java`

## Version 2.0.0-BETA
- Updating various dependencies to latest version
- Introducing public class CustomClassWriter in Agent to enable finding common super classes used for Agent instrumentation without loading it
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,15 @@ public static void resolveCorrelation(HttpServletRequest request, HttpServletRes
public static String generateChildDependencyId() {

try {

RequestTelemetryContext context = ThreadContext.getRequestTelemetryContext();

//check if context is null - no correlation will happen
if (context == null) {
InternalLogger.INSTANCE.warn("No Correlation will happen, Thread context is null while generating child dependency");
return "";
}

RequestTelemetry requestTelemetry = context.getHttpRequestTelemetry();

String parentId = requestTelemetry.getContext().getOperation().getParentId();
Expand All @@ -137,6 +145,13 @@ public static String generateChildDependencyId() {
* @return The correlation context as a string.
*/
public static String retrieveCorrelationContext() {

//check if context is null - no correlation will happen
if (ThreadContext.getRequestTelemetryContext() == null) {
InternalLogger.INSTANCE.warn("No correlation wil happen, Thread context is null");
return "";
}

CorrelationContext context = ThreadContext.getRequestTelemetryContext().getCorrelationContext();
return context.toString();
}
Expand Down Expand Up @@ -256,6 +271,13 @@ private static void resolveCorrelationContext(HttpServletRequest request, Reques
return;
}

//check if context is null - no correlation will happen
if (ThreadContext.getRequestTelemetryContext() == null) {
InternalLogger.INSTANCE.warn("No correlation will happen " +
"Thread context is null while resolving Correlation Context");
return;
}

CorrelationContext currentCorrelationContext =
ThreadContext.getRequestTelemetryContext().getCorrelationContext();

Expand Down

0 comments on commit ecf723a

Please sign in to comment.