Skip to content

Commit

Permalink
Rename LogData to LogRecordData (#4774)
Browse files Browse the repository at this point in the history
* Rename LogData to LogRecordData

* spotless
  • Loading branch information
jack-berg authored Sep 26, 2022
1 parent 9b17be3 commit 647ed91
Show file tree
Hide file tree
Showing 49 changed files with 272 additions and 262 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,16 @@
import com.fasterxml.jackson.core.io.SegmentedStringWriter;
import io.opentelemetry.exporter.internal.otlp.logs.ResourceLogsMarshaler;
import io.opentelemetry.sdk.common.CompletableResultCode;
import io.opentelemetry.sdk.logs.data.LogData;
import io.opentelemetry.sdk.logs.data.LogRecordData;
import io.opentelemetry.sdk.logs.export.LogRecordExporter;
import java.io.IOException;
import java.util.Collection;
import java.util.logging.Level;
import java.util.logging.Logger;

/**
* A {@link LogRecordExporter} which writes {@linkplain LogData logs} to a {@link Logger} in OTLP
* JSON format. Each log line will include a single {@code ResourceLogs}.
* A {@link LogRecordExporter} which writes {@linkplain LogRecordData logs} to a {@link Logger} in
* OTLP JSON format. Each log line will include a single {@code ResourceLogs}.
*/
public final class OtlpJsonLoggingLogRecordExporter implements LogRecordExporter {

Expand All @@ -35,7 +35,7 @@ public static LogRecordExporter create() {
private OtlpJsonLoggingLogRecordExporter() {}

@Override
public CompletableResultCode export(Collection<LogData> logs) {
public CompletableResultCode export(Collection<LogRecordData> logs) {
ResourceLogsMarshaler[] allResourceLogs = ResourceLogsMarshaler.create(logs);
for (ResourceLogsMarshaler resourceLogs : allResourceLogs) {
SegmentedStringWriter sw = new SegmentedStringWriter(JSON_FACTORY._getBufferRecycler());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,10 @@
import io.opentelemetry.api.trace.TraceState;
import io.opentelemetry.internal.testing.slf4j.SuppressLogger;
import io.opentelemetry.sdk.common.InstrumentationScopeInfo;
import io.opentelemetry.sdk.logs.data.LogData;
import io.opentelemetry.sdk.logs.data.LogRecordData;
import io.opentelemetry.sdk.logs.export.LogRecordExporter;
import io.opentelemetry.sdk.resources.Resource;
import io.opentelemetry.sdk.testing.logs.TestLogData;
import io.opentelemetry.sdk.testing.logs.TestLogRecordData;
import java.util.Arrays;
import java.util.concurrent.TimeUnit;
import org.junit.jupiter.api.BeforeEach;
Expand All @@ -36,8 +36,8 @@ class OtlpJsonLoggingLogRecordExporterTest {
private static final Resource RESOURCE =
Resource.create(Attributes.builder().put("key", "value").build());

private static final LogData LOG1 =
TestLogData.builder()
private static final LogRecordData LOG1 =
TestLogRecordData.builder()
.setResource(RESOURCE)
.setInstrumentationScopeInfo(
InstrumentationScopeInfo.builder("instrumentation")
Expand All @@ -57,8 +57,8 @@ class OtlpJsonLoggingLogRecordExporterTest {
TraceState.getDefault()))
.build();

private static final LogData LOG2 =
TestLogData.builder()
private static final LogRecordData LOG2 =
TestLogRecordData.builder()
.setResource(RESOURCE)
.setInstrumentationScopeInfo(
InstrumentationScopeInfo.builder("instrumentation2").setVersion("2").build())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

import io.opentelemetry.sdk.common.CompletableResultCode;
import io.opentelemetry.sdk.common.InstrumentationScopeInfo;
import io.opentelemetry.sdk.logs.data.LogData;
import io.opentelemetry.sdk.logs.data.LogRecordData;
import io.opentelemetry.sdk.logs.export.LogRecordExporter;
import java.time.Instant;
import java.time.ZoneOffset;
Expand All @@ -35,10 +35,10 @@ public static SystemOutLogRecordExporter create() {
private SystemOutLogRecordExporter() {}

@Override
public CompletableResultCode export(Collection<LogData> logs) {
public CompletableResultCode export(Collection<LogRecordData> logs) {
StringBuilder stringBuilder = new StringBuilder(60);

for (LogData log : logs) {
for (LogRecordData log : logs) {
stringBuilder.setLength(0);
formatLog(stringBuilder, log);
System.out.println(stringBuilder);
Expand All @@ -52,7 +52,7 @@ public CompletableResultCode flush() {
}

// VisibleForTesting
static void formatLog(StringBuilder stringBuilder, LogData log) {
static void formatLog(StringBuilder stringBuilder, LogRecordData log) {
InstrumentationScopeInfo instrumentationScopeInfo = log.getInstrumentationScopeInfo();
stringBuilder
.append(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@
import io.opentelemetry.api.trace.TraceState;
import io.opentelemetry.sdk.common.CompletableResultCode;
import io.opentelemetry.sdk.common.InstrumentationScopeInfo;
import io.opentelemetry.sdk.logs.data.LogData;
import io.opentelemetry.sdk.logs.data.LogRecordData;
import io.opentelemetry.sdk.resources.Resource;
import io.opentelemetry.sdk.testing.logs.TestLogData;
import io.opentelemetry.sdk.testing.logs.TestLogRecordData;
import java.time.LocalDateTime;
import java.time.Month;
import java.time.ZoneOffset;
Expand All @@ -41,7 +41,7 @@ void returnCodes() {
void format() {
long timestamp =
LocalDateTime.of(1970, Month.AUGUST, 7, 10, 0).toInstant(ZoneOffset.UTC).toEpochMilli();
LogData log = sampleLog(timestamp);
LogRecordData log = sampleLog(timestamp);
StringBuilder output = new StringBuilder();
SystemOutLogRecordExporter.formatLog(output, log);
assertThat(output.toString())
Expand All @@ -50,8 +50,8 @@ void format() {
+ "[scopeInfo: logTest:1.0] {amount=1, cheese=\"cheddar\"}");
}

private static LogData sampleLog(long timestamp) {
return TestLogData.builder()
private static LogRecordData sampleLog(long timestamp) {
return TestLogRecordData.builder()
.setResource(Resource.empty())
.setInstrumentationScopeInfo(
InstrumentationScopeInfo.builder("logTest").setVersion("1.0").build())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import io.opentelemetry.exporter.internal.otlp.StringAnyValueMarshaler;
import io.opentelemetry.proto.logs.v1.internal.LogRecord;
import io.opentelemetry.proto.logs.v1.internal.SeverityNumber;
import io.opentelemetry.sdk.logs.data.LogRecordData;
import java.io.IOException;
import javax.annotation.Nullable;

Expand All @@ -35,22 +36,22 @@ final class LogMarshaler extends MarshalerWithSize {
@Nullable private final String traceId;
@Nullable private final String spanId;

static LogMarshaler create(io.opentelemetry.sdk.logs.data.LogData logData) {
static LogMarshaler create(LogRecordData logRecordData) {
KeyValueMarshaler[] attributeMarshalers =
KeyValueMarshaler.createRepeated(logData.getAttributes());
KeyValueMarshaler.createRepeated(logRecordData.getAttributes());

// For now, map all the bodies to String AnyValue.
StringAnyValueMarshaler anyValueMarshaler =
new StringAnyValueMarshaler(MarshalerUtil.toBytes(logData.getBody().asString()));
new StringAnyValueMarshaler(MarshalerUtil.toBytes(logRecordData.getBody().asString()));

SpanContext spanContext = logData.getSpanContext();
SpanContext spanContext = logRecordData.getSpanContext();
return new LogMarshaler(
logData.getEpochNanos(),
toProtoSeverityNumber(logData.getSeverity()),
MarshalerUtil.toBytes(logData.getSeverityText()),
logRecordData.getEpochNanos(),
toProtoSeverityNumber(logRecordData.getSeverity()),
MarshalerUtil.toBytes(logRecordData.getSeverityText()),
anyValueMarshaler,
attributeMarshalers,
logData.getTotalAttributeCount() - logData.getAttributes().size(),
logRecordData.getTotalAttributeCount() - logRecordData.getAttributes().size(),
spanContext.getTraceFlags(),
spanContext.getTraceId().equals(INVALID_TRACE_ID) ? null : spanContext.getTraceId(),
spanContext.getSpanId().equals(INVALID_SPAN_ID) ? null : spanContext.getSpanId());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,13 @@
import io.opentelemetry.exporter.internal.marshal.MarshalerWithSize;
import io.opentelemetry.exporter.internal.marshal.Serializer;
import io.opentelemetry.proto.collector.logs.v1.internal.ExportLogsServiceRequest;
import io.opentelemetry.sdk.logs.data.LogData;
import io.opentelemetry.sdk.logs.data.LogRecordData;
import io.opentelemetry.sdk.trace.data.SpanData;
import java.io.IOException;
import java.util.Collection;

/**
* {@link Marshaler} to convert SDK {@link LogData} to OTLP ExportLogsServiceRequest.
* {@link Marshaler} to convert SDK {@link LogRecordData} to OTLP ExportLogsServiceRequest.
*
* <p>This class is internal and is hence not for public use. Its APIs are unstable and can change
* at any time.
Expand All @@ -29,7 +29,7 @@ public final class LogsRequestMarshaler extends MarshalerWithSize {
* Returns a {@link LogsRequestMarshaler} that can be used to convert the provided {@link
* SpanData} into a serialized OTLP ExportLogsServiceRequest.
*/
public static LogsRequestMarshaler create(Collection<LogData> logs) {
public static LogsRequestMarshaler create(Collection<LogRecordData> logs) {
return new LogsRequestMarshaler(ResourceLogsMarshaler.create(logs));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
import io.opentelemetry.exporter.internal.otlp.ResourceMarshaler;
import io.opentelemetry.proto.logs.v1.internal.ResourceLogs;
import io.opentelemetry.sdk.common.InstrumentationScopeInfo;
import io.opentelemetry.sdk.logs.data.LogData;
import io.opentelemetry.sdk.logs.data.LogRecordData;
import io.opentelemetry.sdk.resources.Resource;
import java.io.IOException;
import java.util.Collection;
Expand All @@ -32,7 +32,7 @@ public final class ResourceLogsMarshaler extends MarshalerWithSize {
private final InstrumentationScopeLogsMarshaler[] instrumentationScopeLogsMarshalers;

/** Returns Marshalers of ResourceLogs created by grouping the provided logRecords. */
public static ResourceLogsMarshaler[] create(Collection<LogData> logs) {
public static ResourceLogsMarshaler[] create(Collection<LogRecordData> logs) {
Map<Resource, Map<InstrumentationScopeInfo, List<Marshaler>>> resourceAndScopeMap =
groupByResourceAndScope(logs);

Expand Down Expand Up @@ -93,13 +93,13 @@ private static int calculateSize(
}

private static Map<Resource, Map<InstrumentationScopeInfo, List<Marshaler>>>
groupByResourceAndScope(Collection<LogData> logs) {
groupByResourceAndScope(Collection<LogRecordData> logs) {
return MarshalerUtil.groupByResourceAndScope(
logs,
// TODO(anuraaga): Replace with an internal SdkData type of interface that exposes these
// two.
LogData::getResource,
LogData::getInstrumentationScopeInfo,
LogRecordData::getResource,
LogRecordData::getInstrumentationScopeInfo,
LogMarshaler::create);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
import io.opentelemetry.proto.logs.v1.ScopeLogs;
import io.opentelemetry.sdk.common.InstrumentationScopeInfo;
import io.opentelemetry.sdk.resources.Resource;
import io.opentelemetry.sdk.testing.logs.TestLogData;
import io.opentelemetry.sdk.testing.logs.TestLogRecordData;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.UncheckedIOException;
Expand All @@ -53,7 +53,7 @@ void toProtoResourceLogs() {
ResourceLogsMarshaler[] resourceLogsMarshalers =
ResourceLogsMarshaler.create(
Collections.singleton(
TestLogData.builder()
TestLogRecordData.builder()
.setResource(
Resource.builder().put("one", 1).setSchemaUrl("http://url").build())
.setInstrumentationScopeInfo(
Expand Down Expand Up @@ -100,7 +100,7 @@ void toProtoLogRecord() {
parse(
LogRecord.getDefaultInstance(),
LogMarshaler.create(
TestLogData.builder()
TestLogRecordData.builder()
.setResource(
Resource.create(Attributes.builder().put("testKey", "testValue").build()))
.setInstrumentationScopeInfo(
Expand Down Expand Up @@ -136,7 +136,7 @@ void toProtoLogRecord_MinimalFields() {
parse(
LogRecord.getDefaultInstance(),
LogMarshaler.create(
TestLogData.builder()
TestLogRecordData.builder()
.setResource(
Resource.create(Attributes.builder().put("testKey", "testValue").build()))
.setInstrumentationScopeInfo(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import io.opentelemetry.exporter.internal.okhttp.OkHttpExporter;
import io.opentelemetry.exporter.internal.otlp.logs.LogsRequestMarshaler;
import io.opentelemetry.sdk.common.CompletableResultCode;
import io.opentelemetry.sdk.logs.data.LogData;
import io.opentelemetry.sdk.logs.data.LogRecordData;
import io.opentelemetry.sdk.logs.export.LogRecordExporter;
import java.util.Collection;
import javax.annotation.concurrent.ThreadSafe;
Expand Down Expand Up @@ -48,7 +48,7 @@ public static OtlpHttpLogRecordExporterBuilder builder() {
* @return the result of the operation
*/
@Override
public CompletableResultCode export(Collection<LogData> logs) {
public CompletableResultCode export(Collection<LogRecordData> logs) {
LogsRequestMarshaler exportRequest = LogsRequestMarshaler.create(logs);
return delegate.export(exportRequest, logs.size());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import io.opentelemetry.exporter.internal.grpc.GrpcExporter;
import io.opentelemetry.exporter.internal.otlp.logs.LogsRequestMarshaler;
import io.opentelemetry.sdk.common.CompletableResultCode;
import io.opentelemetry.sdk.logs.data.LogData;
import io.opentelemetry.sdk.logs.data.LogRecordData;
import io.opentelemetry.sdk.logs.export.LogRecordExporter;
import java.util.Collection;
import javax.annotation.concurrent.ThreadSafe;
Expand Down Expand Up @@ -50,7 +50,7 @@ public static OtlpGrpcLogRecordExporterBuilder builder() {
* @return the result of the operation
*/
@Override
public CompletableResultCode export(Collection<LogData> logs) {
public CompletableResultCode export(Collection<LogRecordData> logs) {
LogsRequestMarshaler request = LogsRequestMarshaler.create(logs);
return delegate.export(request, logs.size());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,9 @@
import io.opentelemetry.proto.logs.v1.ResourceLogs;
import io.opentelemetry.sdk.common.CompletableResultCode;
import io.opentelemetry.sdk.common.InstrumentationScopeInfo;
import io.opentelemetry.sdk.logs.data.LogData;
import io.opentelemetry.sdk.logs.data.LogRecordData;
import io.opentelemetry.sdk.resources.Resource;
import io.opentelemetry.sdk.testing.logs.TestLogData;
import io.opentelemetry.sdk.testing.logs.TestLogRecordData;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.UncheckedIOException;
Expand Down Expand Up @@ -317,7 +317,7 @@ void testServerErrorParseError() {

private static ExportLogsServiceRequest exportAndAssertResult(
OtlpHttpLogRecordExporter otlpHttpLogRecordExporter, boolean expectedResult) {
List<LogData> logs = Collections.singletonList(generateFakeLog());
List<LogRecordData> logs = Collections.singletonList(generateFakeLog());
CompletableResultCode resultCode = otlpHttpLogRecordExporter.export(logs);
resultCode.join(10, TimeUnit.SECONDS);
assertThat(resultCode.isSuccess()).isEqualTo(expectedResult);
Expand Down Expand Up @@ -347,8 +347,8 @@ private static <T extends Message> HttpResponse buildResponse(HttpStatus httpSta
return HttpResponse.of(httpStatus, APPLICATION_PROTOBUF, message.toByteArray());
}

private static LogData generateFakeLog() {
return TestLogData.builder()
private static LogRecordData generateFakeLog() {
return TestLogRecordData.builder()
.setResource(Resource.getDefault())
.setInstrumentationScopeInfo(
InstrumentationScopeInfo.builder("testLib")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,16 +19,16 @@
import io.opentelemetry.exporter.otlp.testing.internal.TelemetryExporterBuilder;
import io.opentelemetry.proto.logs.v1.ResourceLogs;
import io.opentelemetry.sdk.common.InstrumentationScopeInfo;
import io.opentelemetry.sdk.logs.data.LogData;
import io.opentelemetry.sdk.logs.data.LogRecordData;
import io.opentelemetry.sdk.resources.Resource;
import io.opentelemetry.sdk.testing.logs.TestLogData;
import io.opentelemetry.sdk.testing.logs.TestLogRecordData;
import java.io.Closeable;
import java.time.Instant;
import java.util.List;
import org.junit.jupiter.api.Test;

class OtlpGrpcLogRecordExporterTest
extends AbstractGrpcTelemetryExporterTest<LogData, ResourceLogs> {
extends AbstractGrpcTelemetryExporterTest<LogRecordData, ResourceLogs> {

OtlpGrpcLogRecordExporterTest() {
super("log", ResourceLogs.getDefaultInstance());
Expand All @@ -51,13 +51,13 @@ void usingOkHttp() throws Exception {
}

@Override
protected TelemetryExporterBuilder<LogData> exporterBuilder() {
protected TelemetryExporterBuilder<LogRecordData> exporterBuilder() {
return TelemetryExporterBuilder.wrap(OtlpGrpcLogRecordExporter.builder());
}

@Override
protected LogData generateFakeTelemetry() {
return TestLogData.builder()
protected LogRecordData generateFakeTelemetry() {
return TestLogRecordData.builder()
.setResource(Resource.create(Attributes.builder().put("testKey", "testValue").build()))
.setInstrumentationScopeInfo(
InstrumentationScopeInfo.builder("instrumentation").setVersion("1").build())
Expand All @@ -70,7 +70,7 @@ protected LogData generateFakeTelemetry() {
}

@Override
protected Marshaler[] toMarshalers(List<LogData> telemetry) {
protected Marshaler[] toMarshalers(List<LogRecordData> telemetry) {
return ResourceLogsMarshaler.create(telemetry);
}
}
Loading

0 comments on commit 647ed91

Please sign in to comment.