Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix null ref check in telemetry correlation Utils #541

Merged
merged 3 commits into from
Feb 1, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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