Skip to content
Merged
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 @@ -64,6 +64,9 @@ private static void addExtrasToProtoBuilder(LogRecordData source, LogRecord.Buil
target.trace_id(ByteStringMapper.getInstance().stringToProto(spanContext.getTraceId()));
target.dropped_attributes_count(
source.getTotalAttributeCount() - source.getAttributes().size());
if (source.getEventName() != null) {
target.event_name(source.getEventName());
}
}

public LogRecordData mapToSdk(
Expand Down Expand Up @@ -99,6 +102,7 @@ private static void addExtrasToSdkItemBuilder(
target.setTotalAttributeCount(source.dropped_attributes_count + attributes.size());
target.setResource(resource);
target.setInstrumentationScopeInfo(scopeInfo);
target.setEventName(source.event_name);
}

private static AnyValue bodyToAnyValue(Value<?> body) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,10 @@ public ExtendedAttributes getExtendedAttributes() {
@Nullable
public abstract Value<?> getBodyValue();

@Override
@Nullable
public abstract String getEventName();

@AutoValue.Builder
public abstract static class Builder {
public abstract Builder setResource(Resource value);
Expand All @@ -68,6 +72,8 @@ public abstract static class Builder {

public abstract Builder setTotalAttributeCount(Integer value);

public abstract Builder setEventName(String value);

public abstract LogRecordDataImpl build();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ class LogRecordDataMapperTest {
.setTimestampEpochNanos(100L)
.setObservedTimestampEpochNanos(200L)
.setTotalAttributeCount(3)
.setEventName("my.event.name")
.build();

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ class ProtoLogsDataMapperTest {
.setTimestampEpochNanos(100L)
.setObservedTimestampEpochNanos(200L)
.setTotalAttributeCount(3)
.setEventName("")
.build();

private static final LogRecordData OTHER_LOG_RECORD =
Expand All @@ -51,6 +52,7 @@ class ProtoLogsDataMapperTest {
.setTimestampEpochNanos(100L)
.setObservedTimestampEpochNanos(200L)
.setTotalAttributeCount(3)
.setEventName("")
.build();

private static final LogRecordData LOG_RECORD_WITH_DIFFERENT_SCOPE_SAME_RESOURCE =
Expand All @@ -65,6 +67,7 @@ class ProtoLogsDataMapperTest {
.setTimestampEpochNanos(100L)
.setObservedTimestampEpochNanos(200L)
.setTotalAttributeCount(3)
.setEventName("")
.build();

private static final LogRecordData LOG_RECORD_WITH_DIFFERENT_RESOURCE =
Expand All @@ -79,6 +82,22 @@ class ProtoLogsDataMapperTest {
.setTimestampEpochNanos(100L)
.setObservedTimestampEpochNanos(200L)
.setTotalAttributeCount(3)
.setEventName("")
.build();

private static final LogRecordData LOG_RECORD_WITH_EVENT_NAME =
LogRecordDataImpl.builder()
.setResource(TestData.RESOURCE_FULL)
.setSpanContext(TestData.SPAN_CONTEXT)
.setInstrumentationScopeInfo(TestData.INSTRUMENTATION_SCOPE_INFO_FULL)
.setAttributes(TestData.ATTRIBUTES)
.setBodyValue(Value.of("Log body"))
.setSeverity(Severity.DEBUG)
.setSeverityText("Log severity text")
.setTimestampEpochNanos(100L)
.setObservedTimestampEpochNanos(200L)
.setTotalAttributeCount(3)
.setEventName("test.event.name")
.build();

@Test
Expand Down Expand Up @@ -160,6 +179,19 @@ void verifyMultipleLogsWithDifferentResource() {
assertThat(mapFromProto(proto)).containsExactlyInAnyOrderElementsOf(signals);
}

@Test
void verifyLogWithEventName() {
List<LogRecordData> signals = Collections.singletonList(LOG_RECORD_WITH_EVENT_NAME);

LogsData result = mapToProto(signals);

List<ResourceLogs> resourceLogsList = result.resource_logs;
LogRecord firstLog = resourceLogsList.get(0).scope_logs.get(0).log_records.get(0);

assertEquals("test.event.name", firstLog.event_name);
assertThat(mapFromProto(result)).containsExactlyInAnyOrderElementsOf(signals);
}

private static LogsData mapToProto(Collection<LogRecordData> signals) {
return ProtoLogsDataMapper.getInstance().toProto(signals);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,10 @@ class LogRecordDataSerializerTest extends BaseSignalSerializerTest<LogRecordData
.setTimestampEpochNanos(100L)
.setObservedTimestampEpochNanos(200L)
.setTotalAttributeCount(3)
.setEventName("event")
.build();

private static final LogRecordData LOG_RECORD_WITHOUT_SEVERITY_TEXT =
private static final LogRecordData LOG_RECORD_WITHOUT_SEVERITY_OR_EVENT_NAME_TEXT =
LogRecordDataImpl.builder()
.setResource(TestData.RESOURCE_FULL)
.setSpanContext(TestData.SPAN_CONTEXT)
Expand All @@ -42,11 +43,12 @@ class LogRecordDataSerializerTest extends BaseSignalSerializerTest<LogRecordData
.setTimestampEpochNanos(100L)
.setObservedTimestampEpochNanos(200L)
.setTotalAttributeCount(3)
.setEventName("")
.build();

@Test
void verifySerialization() {
assertSerialization(LOG_RECORD, LOG_RECORD_WITHOUT_SEVERITY_TEXT);
assertSerialization(LOG_RECORD, LOG_RECORD_WITHOUT_SEVERITY_OR_EVENT_NAME_TEXT);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ class ReadableFileTest {
.setTimestampEpochNanos(100L)
.setObservedTimestampEpochNanos(200L)
.setTotalAttributeCount(3)
.setEventName("")
.build();

private static final LogRecordData SECOND_LOG_RECORD =
Expand All @@ -71,6 +72,7 @@ class ReadableFileTest {
.setTimestampEpochNanos(100L)
.setObservedTimestampEpochNanos(200L)
.setTotalAttributeCount(3)
.setEventName("event")
.build();

private static final LogRecordData THIRD_LOG_RECORD =
Expand All @@ -85,6 +87,7 @@ class ReadableFileTest {
.setTimestampEpochNanos(100L)
.setObservedTimestampEpochNanos(200L)
.setTotalAttributeCount(3)
.setEventName("")
.build();

@BeforeEach
Expand Down
Loading