Skip to content

Commit

Permalink
address review comment
Browse files Browse the repository at this point in the history
  • Loading branch information
laurit committed Apr 3, 2023
1 parent 26fd806 commit b2ce969
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import io.opentelemetry.sdk.common.InstrumentationScopeInfo;
import io.opentelemetry.sdk.logs.data.LogRecordData;
import io.opentelemetry.semconv.trace.attributes.SemanticAttributes;
import java.util.Arrays;
import java.util.stream.Stream;
import org.assertj.core.api.AbstractLongAssert;
import org.junit.jupiter.api.Test;
Expand Down Expand Up @@ -215,7 +216,7 @@ public void testMarker() {
.hasAttributesSatisfyingExactly(
equalTo(SemanticAttributes.THREAD_NAME, Thread.currentThread().getName()),
equalTo(SemanticAttributes.THREAD_ID, Thread.currentThread().getId()),
equalTo(AttributeKey.stringKey("logback.marker"), markerName),
equalTo(AttributeKey.stringArrayKey("logback.marker"), Arrays.asList(markerName)),
equalTo(SemanticAttributes.CODE_NAMESPACE, LogbackTest.class.getName()),
equalTo(SemanticAttributes.CODE_FUNCTION, "testMarker"),
satisfies(SemanticAttributes.CODE_LINENO, AbstractLongAssert::isPositive),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import io.opentelemetry.semconv.trace.attributes.SemanticAttributes;
import java.io.PrintWriter;
import java.io.StringWriter;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.concurrent.TimeUnit;
Expand All @@ -36,7 +37,8 @@ public final class LoggingEventMapper {
private static final boolean supportsMultipleMarkers = supportsMultipleMarkers();
private static final Cache<String, AttributeKey<String>> mdcAttributeKeys = Cache.bounded(100);

private static final AttributeKey<String> LOG_MARKER = AttributeKey.stringKey("logback.marker");
private static final AttributeKey<List<String>> LOG_MARKER =
AttributeKey.stringArrayKey("logback.marker");

private final boolean captureExperimentalAttributes;
private final List<String> captureMdcAttributes;
Expand Down Expand Up @@ -245,19 +247,18 @@ private static void captureSingleMarkerAttribute(
AttributesBuilder attributes, ILoggingEvent loggingEvent) {
Marker marker = loggingEvent.getMarker();
if (marker != null) {
String markerName = marker.getName();
attributes.put(LOG_MARKER, markerName);
attributes.put(LOG_MARKER, marker.getName());
}
}

@NoMuzzle
private static void captureMultipleMarkerAttributes(
AttributesBuilder attributes, ILoggingEvent loggingEvent) {
int i = 1;
List<String> markerNames = new ArrayList<>(loggingEvent.getMarkerList().size());
for (Marker marker : loggingEvent.getMarkerList()) {
String markerName = marker.getName();
attributes.put(AttributeKey.stringKey("logback.marker." + i++), markerName);
markerNames.add(marker.getName());
}
attributes.put(LOG_MARKER, markerNames.toArray(new String[0]));
}

@NoMuzzle
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import io.opentelemetry.sdk.logs.export.InMemoryLogRecordExporter;
import io.opentelemetry.sdk.logs.export.SimpleLogRecordProcessor;
import io.opentelemetry.sdk.resources.Resource;
import java.util.Arrays;
import java.util.List;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.BeforeEach;
Expand Down Expand Up @@ -84,14 +85,10 @@ void multipleMarkers() {
assertThat(logData.getResource()).isEqualTo(resource);
assertThat(logData.getInstrumentationScopeInfo()).isEqualTo(instrumentationScopeInfo);
assertThat(logData.getBody().asString()).isEqualTo("log message 1");
assertThat(logData.getAttributes().size()).isEqualTo(6); // 4 code attributes + 2 markers
assertThat(logData.getAttributes().size()).isEqualTo(5); // 4 code attributes + 1 marker
assertThat(logData.getAttributes())
.hasEntrySatisfying(
AttributeKey.stringKey("logback.marker.1"),
value -> assertThat(value).isEqualTo(markerName1));
assertThat(logData.getAttributes())
.hasEntrySatisfying(
AttributeKey.stringKey("logback.marker.2"),
value -> assertThat(value).isEqualTo(markerName2));
AttributeKey.stringArrayKey("logback.marker"),
value -> assertThat(value).isEqualTo(Arrays.asList(markerName1, markerName2)));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import io.opentelemetry.sdk.trace.SdkTracerProvider;
import io.opentelemetry.semconv.trace.attributes.SemanticAttributes;
import java.time.Instant;
import java.util.Arrays;
import java.util.List;
import java.util.concurrent.TimeUnit;
import org.junit.jupiter.api.BeforeAll;
Expand Down Expand Up @@ -141,8 +142,9 @@ void logWithExtras() {
Long lineNumber = logData.getAttributes().get(SemanticAttributes.CODE_LINENO);
assertThat(lineNumber).isGreaterThan(1);

String logMarker = logData.getAttributes().get(AttributeKey.stringKey("logback.marker"));
assertThat(logMarker).isEqualTo(markerName);
List<String> logMarker =
logData.getAttributes().get(AttributeKey.stringArrayKey("logback.marker"));
assertThat(logMarker).isEqualTo(Arrays.asList(markerName));
}

@Test
Expand Down

0 comments on commit b2ce969

Please sign in to comment.