Skip to content
Open
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
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import static com.datadog.debugger.util.ExceptionHelper.getInnerMostThrowable;

import datadog.trace.bootstrap.debugger.DebuggerContext.ClassNameFilter;
import java.nio.charset.StandardCharsets;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import org.slf4j.Logger;
Expand Down Expand Up @@ -30,22 +31,22 @@ public static String fingerprint(Throwable t, ClassNameFilter classNameFiltering
return null;
}
String typeName = clazz.getTypeName();
digest.update(typeName.getBytes());
digest.update(typeName.getBytes(StandardCharsets.UTF_8));
StackTraceElement[] stackTrace = t.getStackTrace();
for (StackTraceElement stackTraceElement : stackTrace) {
String className = stackTraceElement.getClassName();
if (classNameFiltering.isExcluded(className)) {
continue;
}
digest.update(stackTraceElement.toString().getBytes());
digest.update(stackTraceElement.toString().getBytes(StandardCharsets.UTF_8));
}
return bytesToHex(digest.digest());
}

public static String fingerprint(StackTraceElement element) {
try {
MessageDigest digest = MessageDigest.getInstance("SHA-256");
digest.update(element.toString().getBytes());
digest.update(element.toString().getBytes(StandardCharsets.UTF_8));
return bytesToHex(digest.digest());
} catch (NoSuchAlgorithmException e) {
LOGGER.debug("Unable to find digest algorithm SHA-256", e);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.nio.charset.StandardCharsets;
import okio.BufferedSource;
import okio.Okio;

Expand Down Expand Up @@ -60,7 +61,7 @@ public interface Visitor {
*/
public static boolean tryToParse(String raw, Visitor visitor, PathCursor pathCursor) {
if (raw.startsWith("{") && raw.endsWith("}") || raw.startsWith("[") && raw.endsWith("]")) {
try (InputStream is = new ByteArrayInputStream(raw.getBytes())) {
try (InputStream is = new ByteArrayInputStream(raw.getBytes(StandardCharsets.UTF_8))) {
return tryToParse(is, visitor, pathCursor.copy());
} catch (Exception e) {
visitor.expandValueFailed(pathCursor, e);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -300,7 +300,7 @@ public void accept(Metadata metadata) {
writable.writeString(spanKind, null);

for (Map.Entry<String, String> error : errorInfo.entrySet()) {
writable.writeUTF8(error.getKey().getBytes());
writable.writeUTF8(error.getKey().getBytes(StandardCharsets.UTF_8));
writable.writeString(error.getValue(), null);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
import datadog.trace.bootstrap.instrumentation.api.AgentSpan;
import datadog.trace.bootstrap.instrumentation.api.AgentTracer;
import datadog.trace.bootstrap.instrumentation.api.Tags;
import java.nio.charset.StandardCharsets;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import java.util.HashMap;
Expand Down Expand Up @@ -374,12 +375,13 @@ protected static String anonymize(final UserIdCollectionMode mode, final String
}
MessageDigest digest;
try {
// TODO avoid lookup a new instance every time
// A new instance is needed each time for thread safety.
// Per micro-benchmarks, the overhead of getInstance() is negligible.
digest = MessageDigest.getInstance("SHA-256");
} catch (NoSuchAlgorithmException e) {
return null;
}
digest.update(userId.getBytes());
digest.update(userId.getBytes(StandardCharsets.UTF_8));
byte[] hash = digest.digest();
if (hash.length > HASH_SIZE_BYTES) {
byte[] temp = new byte[HASH_SIZE_BYTES];
Expand Down