Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rename LogData to LogRecordData #4774

Merged
merged 3 commits into from
Sep 26, 2022
Merged
Show file tree
Hide file tree
Changes from 2 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 @@ -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.LogExporter;
import java.io.IOException;
import java.util.Collection;
import java.util.logging.Level;
import java.util.logging.Logger;

/**
* A {@link LogExporter} which writes {@linkplain LogData logs} to a {@link Logger} in OTLP JSON
* format. Each log line will include a single {@code ResourceLogs}.
* A {@link LogExporter} 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 OtlpJsonLoggingLogExporter implements LogExporter {

Expand All @@ -34,7 +34,7 @@ public static LogExporter create() {
private OtlpJsonLoggingLogExporter() {}

@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.LogExporter;
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 OtlpJsonLoggingLogExporterTest {
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 OtlpJsonLoggingLogExporterTest {
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.LogExporter;
import java.time.Instant;
import java.time.ZoneOffset;
Expand Down Expand Up @@ -41,10 +41,10 @@ public static SystemOutLogExporter create() {
public SystemOutLogExporter() {}

@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 @@ -58,7 +58,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();
SystemOutLogExporter.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.LogExporter;
import java.util.Collection;
import javax.annotation.concurrent.ThreadSafe;
Expand Down Expand Up @@ -48,7 +48,7 @@ public static OtlpHttpLogExporterBuilder 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.LogExporter;
import java.util.Collection;
import javax.annotation.concurrent.ThreadSafe;
Expand Down Expand Up @@ -50,7 +50,7 @@ public static OtlpGrpcLogExporterBuilder 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 @@ -308,7 +308,7 @@ void testServerErrorParseError() {

private static ExportLogsServiceRequest exportAndAssertResult(
OtlpHttpLogExporter otlpHttpLogExporter, boolean expectedResult) {
List<LogData> logs = Collections.singletonList(generateFakeLog());
List<LogRecordData> logs = Collections.singletonList(generateFakeLog());
CompletableResultCode resultCode = otlpHttpLogExporter.export(logs);
resultCode.join(10, TimeUnit.SECONDS);
assertThat(resultCode.isSuccess()).isEqualTo(expectedResult);
Expand Down Expand Up @@ -338,8 +338,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,15 +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 OtlpGrpcLogExporterTest extends AbstractGrpcTelemetryExporterTest<LogData, ResourceLogs> {
class OtlpGrpcLogExporterTest
extends AbstractGrpcTelemetryExporterTest<LogRecordData, ResourceLogs> {

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

@Override
protected TelemetryExporterBuilder<LogData> exporterBuilder() {
protected TelemetryExporterBuilder<LogRecordData> exporterBuilder() {
return TelemetryExporterBuilder.wrap(OtlpGrpcLogExporter.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 @@ -69,7 +70,7 @@ protected LogData generateFakeTelemetry() {
}

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