Skip to content
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,9 @@ public final class Instrumentation {
public static final String INSTRUMENTATION_NAME_KEY = "name";
public static final String INSTRUMENTATION_VERSION_KEY = "version";
public static final String JAVA_LIBRARY_NAME_PREFIX = "java";
// Using release-please annotations to update DEFAULT_INSTRUMENTATION_VERSION with latest version.
// See
// https://github.com/googleapis/release-please/blob/main/docs/customizing.md#updating-arbitrary-files
// {x-version-update-start:google-cloud-logging:current}
public static final String DEFAULT_INSTRUMENTATION_VERSION = "3.13.0";
// {x-version-update-end}
Expand Down Expand Up @@ -233,7 +236,13 @@ public static String getLibraryVersion(Class<?> libraryClass) {
return libraryVersion;
}

private static String truncateValue(String value) {
/**
* Trancates given string to MAX_DIAGNOSTIC_VALUE_LENGTH and adds "*" instead of reduced suffix
*
* @param value {String} Value to be truncated
* @return The truncated string
*/
public static String truncateValue(String value) {
if (Strings.isNullOrEmpty(value) || value.length() < MAX_DIAGNOSTIC_VALUE_LENGTH) {
return value;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,10 @@ public void testInstrumentationGenerated() {
1,
2,
new HashSet<>(Arrays.asList(Instrumentation.JAVA_LIBRARY_NAME_PREFIX)),
new HashSet<>(Arrays.asList(Instrumentation.getLibraryVersion(Instrumentation.class))));
new HashSet<>(
Arrays.asList(
Instrumentation.truncateValue(
Instrumentation.getLibraryVersion(Instrumentation.class)))));
}

@Test
Expand All @@ -78,7 +81,9 @@ public void testInstrumentationUpdated() {
new HashSet<>(Arrays.asList(Instrumentation.JAVA_LIBRARY_NAME_PREFIX, JAVA_OTHER_NAME)),
new HashSet<>(
Arrays.asList(
Instrumentation.getLibraryVersion(Instrumentation.class), JAVA_OTHER_VERSION)));
Instrumentation.truncateValue(
Instrumentation.getLibraryVersion(Instrumentation.class)),
JAVA_OTHER_VERSION)));
}

@Test
Expand All @@ -92,7 +97,10 @@ public void testInvalidInstrumentationRemoved() {
0,
1,
new HashSet<>(Arrays.asList(Instrumentation.JAVA_LIBRARY_NAME_PREFIX)),
new HashSet<>(Arrays.asList(Instrumentation.getLibraryVersion(Instrumentation.class))));
new HashSet<>(
Arrays.asList(
Instrumentation.truncateValue(
Instrumentation.getLibraryVersion(Instrumentation.class)))));
}

public static JsonPayload generateInstrumentationPayload(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,8 @@ public class LoggingHandlerTest {
LogEntry.newBuilder(
InstrumentationTest.generateInstrumentationPayload(
Instrumentation.JAVA_LIBRARY_NAME_PREFIX,
Instrumentation.getLibraryVersion(Instrumentation.class)))
Instrumentation.truncateValue(
Instrumentation.getLibraryVersion(Instrumentation.class))))
.setLogName(Instrumentation.INSTRUMENTATION_LOG_NAME)
.build();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2333,7 +2333,8 @@ private void testDiagnosticInfoGeneration(boolean addPartialSuccessOption) {
LogEntry.newBuilder(
InstrumentationTest.generateInstrumentationPayload(
Instrumentation.JAVA_LIBRARY_NAME_PREFIX,
Instrumentation.getLibraryVersion(Instrumentation.class)))
Instrumentation.truncateValue(
Instrumentation.getLibraryVersion(Instrumentation.class))))
.setLogName(Instrumentation.INSTRUMENTATION_LOG_NAME)
.build();
WriteLogEntriesRequest request =
Expand Down