Skip to content

Commit

Permalink
Backport: Polishing Dynatrace V2 logging changes a little
Browse files Browse the repository at this point in the history
See original commit: cf655e9
  • Loading branch information
jonatan-ivanov committed May 9, 2022
1 parent d060a46 commit de70a01
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
package io.micrometer.dynatrace.v2;

import com.dynatrace.metric.util.*;

import io.micrometer.core.instrument.*;
import io.micrometer.core.instrument.distribution.HistogramSnapshot;
import io.micrometer.core.instrument.distribution.ValueAtPercentile;
Expand Down Expand Up @@ -67,10 +66,9 @@ public final class DynatraceExporterV2 extends AbstractDynatraceExporter {

private static final String LOG_RESPONSE_BODY_TRUNCATION_INDICATOR = " (truncated)";

private final InternalLogger logger = InternalLoggerFactory.getInstance(DynatraceExporterV2.class);
private static final InternalLogger logger = InternalLoggerFactory.getInstance(DynatraceExporterV2.class);

private static final WarnThenDebugLogger warnThenDebugLoggerSendStack = new WarnThenDebugLogger(
DynatraceExporterV2.class);
private static final WarnThenDebugLogger warnThenDebugLogger = new WarnThenDebugLogger(DynatraceExporterV2.class);

private static final Map<String, String> staticDimensions = Collections.singletonMap("dt.metrics.source",
"micrometer");
Expand Down Expand Up @@ -323,8 +321,7 @@ private void send(List<String> metricLines) {
}
catch (Throwable throwable) {
logger.warn("Failed metric ingestion: " + throwable);
warnThenDebugLoggerSendStack.log("Stack trace for previous 'Failed metric ingestion' warning log: ",
throwable);
warnThenDebugLogger.log("Stack trace for previous 'Failed metric ingestion' warning log: ", throwable);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,9 +98,10 @@ public static String truncate(String string, int maxLength, String truncationInd
throw new IllegalArgumentException("maxLength must be greater than length of truncationIndicator");
}
if (string.length() > maxLength) {
final int remainingLength = maxLength - truncationIndicator.length();
int remainingLength = maxLength - truncationIndicator.length();
return string.substring(0, remainingLength) + truncationIndicator;
}

return string;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,12 +58,12 @@ void truncateWithIndicatorWhenLessThanMaxLengthShouldReturnItself() {
}

@Test
void truncateWithIndicatorThrowsOnInvalidLength1() {
void truncateWithIndicatorThrowsOnInvalidLengthWhenOriginalStringIsShort() {
assertThrows(IllegalArgumentException.class, () -> StringUtils.truncate("12345", 7, "[abbreviated]"));
}

@Test
void truncateWithIndicatorThrowsOnInvalidLength2() {
void truncateWithIndicatorThrowsOnInvalidLengthWhenOriginalStringIsLongEnough() {
assertThrows(IllegalArgumentException.class, () -> StringUtils.truncate("1234567890", 7, "[abbreviated]"));
}

Expand Down

0 comments on commit de70a01

Please sign in to comment.