-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #224 from solarwinds-cloud/cc/NH-77733
NH-77733: Fix trace context in queries lambda edition
- Loading branch information
Showing
15 changed files
with
152 additions
and
256 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
22 changes: 22 additions & 0 deletions
22
...ation/jdbc/src/main/java/com/solarwinds/opentelemetry/instrumentation/BackTraceCache.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
package com.solarwinds.opentelemetry.instrumentation; | ||
|
||
import com.github.benmanes.caffeine.cache.Cache; | ||
import com.github.benmanes.caffeine.cache.Caffeine; | ||
import java.time.Duration; | ||
import java.util.List; | ||
|
||
public class BackTraceCache { | ||
private static final Cache<List<StackTraceElement>, String> backTraceCache = | ||
Caffeine.newBuilder() | ||
.maximumSize(20) | ||
.expireAfterAccess(Duration.ofHours(1L)) | ||
.build(); // 1 hour cache; | ||
|
||
static String getBackTraceString(List<StackTraceElement> stackTrace) { | ||
return backTraceCache.getIfPresent(stackTrace); | ||
} | ||
|
||
static void putBackTraceString(List<StackTraceElement> stackTrace, String stackTraceString) { | ||
backTraceCache.put(stackTrace, stackTraceString); | ||
} | ||
} |
87 changes: 87 additions & 0 deletions
87
...tation/jdbc/src/main/java/com/solarwinds/opentelemetry/instrumentation/BackTraceUtil.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
package com.solarwinds.opentelemetry.instrumentation; | ||
|
||
import com.solarwinds.joboe.logging.Logger; | ||
import com.solarwinds.joboe.logging.LoggerFactory; | ||
import java.util.Arrays; | ||
import java.util.List; | ||
|
||
public class BackTraceUtil { | ||
private static final int MAX_BACK_TRACE_TOP_LINE_COUNT = 100; | ||
|
||
private static final int MAX_BACK_TRACE_BOTTOM_LINE_COUNT = 20; | ||
|
||
private static final int MAX_BACK_TRACE_LINE_COUNT = | ||
MAX_BACK_TRACE_TOP_LINE_COUNT + MAX_BACK_TRACE_BOTTOM_LINE_COUNT; | ||
|
||
private static final Logger logger = LoggerFactory.getLogger(); | ||
|
||
public static StackTraceElement[] getBackTrace(int skipElements) { | ||
StackTraceElement[] stackTrace = Thread.currentThread().getStackTrace(); | ||
|
||
int startPosition = | ||
2 + skipElements; // Starts with 2: To exclude the getStackTrace() and addBackTrace calls | ||
// themselves. Also adds the number of skipElements provided in the | ||
// argument to skip elements | ||
|
||
if (startPosition >= stackTrace.length) { | ||
logger.debug( | ||
"Attempt to skip [" | ||
+ skipElements | ||
+ "] elements in addBackTrace is invalid, no stack trace element is left!"); | ||
return new StackTraceElement[0]; | ||
} | ||
|
||
int targetStackTraceLength = stackTrace.length - startPosition; | ||
StackTraceElement[] targetStackTrace = new StackTraceElement[targetStackTraceLength]; | ||
System.arraycopy(stackTrace, startPosition, targetStackTrace, 0, targetStackTraceLength); | ||
|
||
return targetStackTrace; | ||
} | ||
|
||
public static String backTraceToString(StackTraceElement[] stackTrace) { | ||
List<StackTraceElement> wrappedStackTrace = | ||
Arrays.asList(stackTrace); // wrap it so hashCode and equals work | ||
|
||
String cachedValue = BackTraceCache.getBackTraceString(wrappedStackTrace); | ||
if (cachedValue != null) { | ||
return cachedValue; | ||
} | ||
|
||
StringBuffer stringBuffer = new StringBuffer(); | ||
if (stackTrace.length > MAX_BACK_TRACE_LINE_COUNT) { // then we will have to skip some lines | ||
appendStackTrace( | ||
stackTrace, 0, MAX_BACK_TRACE_TOP_LINE_COUNT, stringBuffer); // add the top lines | ||
|
||
stringBuffer | ||
.append("...Skipped ") | ||
.append(stackTrace.length - MAX_BACK_TRACE_LINE_COUNT) | ||
.append(" line(s)\n"); | ||
|
||
appendStackTrace( | ||
stackTrace, | ||
stackTrace.length - MAX_BACK_TRACE_BOTTOM_LINE_COUNT, | ||
MAX_BACK_TRACE_BOTTOM_LINE_COUNT, | ||
stringBuffer); // add the bottom lines | ||
|
||
} else { | ||
appendStackTrace(stackTrace, 0, stackTrace.length, stringBuffer); // add everything | ||
} | ||
|
||
String value = stringBuffer.toString(); | ||
BackTraceCache.putBackTraceString(wrappedStackTrace, value); | ||
return value; | ||
} | ||
|
||
/** | ||
* Build the stackTrace output and append the result to the buffer provided | ||
* | ||
* @param stackTrace The source of the stack trace array | ||
* @param buffer The buffer that stores the result | ||
*/ | ||
private static void appendStackTrace( | ||
StackTraceElement[] stackTrace, int startPosition, int lineCount, StringBuffer buffer) { | ||
for (int i = startPosition; i < startPosition + lineCount && i < stackTrace.length; i++) { | ||
buffer.append(stackTrace[i].toString()).append("\n"); | ||
} | ||
} | ||
} |
158 changes: 0 additions & 158 deletions
158
...c/src/main/java/com/solarwinds/opentelemetry/instrumentation/JdbcEventValueConverter.java
This file was deleted.
Oops, something went wrong.
47 changes: 0 additions & 47 deletions
47
...n/jdbc/src/main/java/com/solarwinds/opentelemetry/instrumentation/QueryArgsCollector.java
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.