Skip to content
Merged
Show file tree
Hide file tree
Changes from 14 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
10 changes: 10 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,16 @@

## Version 1.8.0 (unreleased):

### SDK

#### Logging (alpha)

- This release includes a rework of the Log SDK to
implement [OTEP-0150](https://github.com/open-telemetry/oteps/blob/main/text/logs/0150-logging-library-sdk.md)
and to have more symmetry to the Trace SDK. `LogSink` is now `LogEmitter`. `LogEmitter` instances
are obtained from `SdkLogEmitterProvider`. Other additions include `MultiLogProcessor` (accessed
via `LogProcessor#composite(...)`), `SimpleLogProcessor`, and `InMemoryLogExporter`.

### Auto-configuration (alpha)

- BREAKING CHANGE: Remove deprecated `otel.experimental.exporter.otlp.protocol`,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import io.opentelemetry.sdk.logs.export.LogExporter;
import io.opentelemetry.sdk.resources.Resource;
import java.util.Arrays;
import java.util.concurrent.TimeUnit;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.RegisterExtension;
Expand All @@ -31,30 +32,36 @@ class OtlpJsonLoggingLogExporterTest {
Resource.create(Attributes.builder().put("key", "value").build());

private static final LogData LOG1 =
LogRecord.builder(RESOURCE, InstrumentationLibraryInfo.create("instrumentation", "1"))
.setName("testLog1")
.setBody("body1")
.setFlags(0)
.setSeverity(Severity.INFO)
.setSeverityText("INFO")
.setSpanId("8765432112345876")
.setTraceId("12345678876543211234567887654322")
.setEpochMillis(1631533710L)
.setAttributes(Attributes.of(stringKey("animal"), "cat", longKey("lives"), 9L))
.build();
LogData.create(
RESOURCE,
InstrumentationLibraryInfo.create("instrumentation", "1"),
LogRecord.builder()
.setName("testLog1")
.setBody("body1")
.setFlags(0)
.setSeverity(Severity.INFO)
.setSeverityText("INFO")
.setSpanId("8765432112345876")
.setTraceId("12345678876543211234567887654322")
.setEpoch(1631533710L, TimeUnit.MILLISECONDS)
.setAttributes(Attributes.of(stringKey("animal"), "cat", longKey("lives"), 9L))
.build());

private static final LogData LOG2 =
LogRecord.builder(RESOURCE, InstrumentationLibraryInfo.create("instrumentation2", "2"))
.setName("testLog2")
.setBody("body2")
.setFlags(0)
.setSeverity(Severity.INFO)
.setSeverityText("INFO")
.setSpanId("8765432112345875")
.setTraceId("12345678876543211234567887654322")
.setEpochMillis(1631533710L)
.setAttributes(Attributes.of(booleanKey("important"), true))
.build();
LogData.create(
RESOURCE,
InstrumentationLibraryInfo.create("instrumentation2", "2"),
LogRecord.builder()
.setName("testLog2")
.setBody("body2")
.setFlags(0)
.setSeverity(Severity.INFO)
.setSeverityText("INFO")
.setSpanId("8765432112345875")
.setTraceId("12345678876543211234567887654322")
.setEpoch(1631533710L, TimeUnit.MILLISECONDS)
.setAttributes(Attributes.of(booleanKey("important"), true))
.build());

@RegisterExtension
LogCapturer logs = LogCapturer.create().captureForType(OtlpJsonLoggingLogExporter.class);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import java.time.LocalDateTime;
import java.time.Month;
import java.time.ZoneOffset;
import java.util.concurrent.TimeUnit;
import org.junit.jupiter.api.Test;

class SystemOutLogExporterTest {
Expand Down Expand Up @@ -50,13 +51,16 @@ void format() {
}

private static LogData sampleLog(long timestamp) {
return LogRecord.builder(Resource.empty(), InstrumentationLibraryInfo.create("logTest", "1.0"))
.setAttributes(Attributes.of(stringKey("cheese"), "cheddar", longKey("amount"), 1L))
.setBody(Body.stringBody("message"))
.setSeverity(Severity.ERROR3)
.setEpochMillis(timestamp)
.setTraceId(TraceId.fromLongs(1, 2))
.setSpanId(SpanId.fromLong(3))
.build();
return LogData.create(
Resource.empty(),
InstrumentationLibraryInfo.create("logTest", "1.0"),
LogRecord.builder()
.setAttributes(Attributes.of(stringKey("cheese"), "cheddar", longKey("amount"), 1L))
.setBody(Body.stringBody("message"))
.setSeverity(Severity.ERROR3)
.setEpoch(timestamp, TimeUnit.MILLISECONDS)
.setTraceId(TraceId.fromLongs(1, 2))
.setSpanId(SpanId.fromLong(3))
.build());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -319,18 +319,19 @@ private static <T extends Message> HttpResponse buildResponse(HttpStatus httpSta
}

private static LogData generateFakeLog() {
return LogRecord.builder(
Resource.getDefault(),
InstrumentationLibraryInfo.create("testLib", "1.0", "http://url"))
.setName("log-name")
.setBody(Body.stringBody("log body"))
.setAttributes(Attributes.builder().put("key", "value").build())
.setSeverity(Severity.INFO)
.setSeverityText(Severity.INFO.name())
.setTraceId(IdGenerator.random().generateTraceId())
.setSpanId(IdGenerator.random().generateSpanId())
.setEpochNanos(TimeUnit.MILLISECONDS.toNanos(Instant.now().toEpochMilli()))
.setFlags(0)
.build();
return LogData.create(
Resource.getDefault(),
InstrumentationLibraryInfo.create("testLib", "1.0", "http://url"),
LogRecord.builder()
.setName("log-name")
.setBody(Body.stringBody("log body"))
.setAttributes(Attributes.builder().put("key", "value").build())
.setSeverity(Severity.INFO)
.setSeverityText(Severity.INFO.name())
.setTraceId(IdGenerator.random().generateTraceId())
.setSpanId(IdGenerator.random().generateSpanId())
.setEpoch(Instant.now())
.setFlags(0)
.build());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,12 @@
import io.opentelemetry.exporter.otlp.internal.Serializer;
import io.opentelemetry.proto.collector.logs.v1.internal.ExportLogsServiceRequest;
import io.opentelemetry.sdk.logs.data.LogData;
import io.opentelemetry.sdk.logs.data.LogRecord;
import io.opentelemetry.sdk.trace.data.SpanData;
import java.io.IOException;
import java.util.Collection;

/**
* {@link Marshaler} to convert SDK {@link LogRecord} to OTLP ExportLogsServiceRequest.
* {@link Marshaler} to convert SDK {@link LogData} 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 Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import io.opentelemetry.proto.logs.v1.LogRecord;
import io.opentelemetry.proto.logs.v1.ResourceLogs;
import io.opentelemetry.sdk.common.InstrumentationLibraryInfo;
import io.opentelemetry.sdk.logs.data.LogData;
import io.opentelemetry.sdk.logs.data.Severity;
import io.opentelemetry.sdk.resources.Resource;
import java.io.ByteArrayOutputStream;
Expand All @@ -33,6 +34,7 @@
import java.util.Base64;
import java.util.Collections;
import java.util.Locale;
import java.util.concurrent.TimeUnit;
import org.junit.jupiter.api.Test;

class LogsRequestMarshalerTest {
Expand All @@ -49,18 +51,19 @@ void toProtoResourceLogs() {
ResourceLogsMarshaler[] resourceLogsMarshalers =
ResourceLogsMarshaler.create(
Collections.singleton(
io.opentelemetry.sdk.logs.data.LogRecord.builder(
Resource.builder().put("one", 1).setSchemaUrl("http://url").build(),
InstrumentationLibraryInfo.create("testLib", "1.0", "http://url"))
.setName(NAME)
.setBody(BODY)
.setSeverity(Severity.INFO)
.setSeverityText("INFO")
.setTraceId(TRACE_ID)
.setSpanId(SPAN_ID)
.setAttributes(Attributes.of(AttributeKey.booleanKey("key"), true))
.setEpochNanos(12345)
.build()));
LogData.create(
Resource.builder().put("one", 1).setSchemaUrl("http://url").build(),
InstrumentationLibraryInfo.create("testLib", "1.0", "http://url"),
io.opentelemetry.sdk.logs.data.LogRecord.builder()
.setName(NAME)
.setBody(BODY)
.setSeverity(Severity.INFO)
.setSeverityText("INFO")
.setTraceId(TRACE_ID)
.setSpanId(SPAN_ID)
.setAttributes(Attributes.of(AttributeKey.booleanKey("key"), true))
.setEpoch(12345, TimeUnit.NANOSECONDS)
.build())));

assertThat(resourceLogsMarshalers).hasSize(1);

Expand All @@ -82,18 +85,19 @@ void toProtoLogRecord() {
parse(
LogRecord.getDefaultInstance(),
LogMarshaler.create(
io.opentelemetry.sdk.logs.data.LogRecord.builder(
Resource.create(Attributes.builder().put("testKey", "testValue").build()),
InstrumentationLibraryInfo.create("instrumentation", "1"))
.setName(NAME)
.setBody(BODY)
.setSeverity(Severity.INFO)
.setSeverityText("INFO")
.setTraceId(TRACE_ID)
.setSpanId(SPAN_ID)
.setAttributes(Attributes.of(AttributeKey.booleanKey("key"), true))
.setEpochNanos(12345)
.build()));
LogData.create(
Resource.create(Attributes.builder().put("testKey", "testValue").build()),
InstrumentationLibraryInfo.create("instrumentation", "1"),
io.opentelemetry.sdk.logs.data.LogRecord.builder()
.setName(NAME)
.setBody(BODY)
.setSeverity(Severity.INFO)
.setSeverityText("INFO")
.setTraceId(TRACE_ID)
.setSpanId(SPAN_ID)
.setAttributes(Attributes.of(AttributeKey.booleanKey("key"), true))
.setEpoch(12345, TimeUnit.NANOSECONDS)
.build())));

assertThat(logRecord.getTraceId().toByteArray()).isEqualTo(TRACE_ID_BYTES);
assertThat(logRecord.getSpanId().toByteArray()).isEqualTo(SPAN_ID_BYTES);
Expand All @@ -115,14 +119,15 @@ void toProtoLogRecord_MinimalFields() {
parse(
LogRecord.getDefaultInstance(),
LogMarshaler.create(
io.opentelemetry.sdk.logs.data.LogRecord.builder(
Resource.create(Attributes.builder().put("testKey", "testValue").build()),
InstrumentationLibraryInfo.create("instrumentation", "1"))
.setBody(BODY)
.setSeverity(Severity.INFO)
.setAttributes(Attributes.of(AttributeKey.booleanKey("key"), true))
.setEpochNanos(12345)
.build()));
LogData.create(
Resource.create(Attributes.builder().put("testKey", "testValue").build()),
InstrumentationLibraryInfo.create("instrumentation", "1"),
io.opentelemetry.sdk.logs.data.LogRecord.builder()
.setBody(BODY)
.setSeverity(Severity.INFO)
.setAttributes(Attributes.of(AttributeKey.booleanKey("key"), true))
.setEpoch(12345, TimeUnit.NANOSECONDS)
.build())));

assertThat(logRecord.getTraceId().toByteArray()).isEmpty();
assertThat(logRecord.getSpanId().toByteArray()).isEmpty();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
import java.io.UncheckedIOException;
import java.nio.charset.StandardCharsets;
import java.time.Duration;
import java.time.Instant;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
Expand Down Expand Up @@ -357,19 +358,20 @@ void usingGrpc() {
}

private static LogData generateFakeLog() {
return LogRecord.builder(
Resource.create(Attributes.builder().put("testKey", "testValue").build()),
InstrumentationLibraryInfo.create("instrumentation", "1"))
.setEpochMillis(System.currentTimeMillis())
.setTraceId(TraceId.getInvalid())
.setSpanId(SpanId.getInvalid())
.setFlags(TraceFlags.getDefault().asByte())
.setSeverity(Severity.ERROR)
.setSeverityText("really severe")
.setName("log1")
.setBody("message")
.setAttributes(Attributes.builder().put("animal", "cat").build())
.build();
return LogData.create(
Resource.create(Attributes.builder().put("testKey", "testValue").build()),
InstrumentationLibraryInfo.create("instrumentation", "1"),
LogRecord.builder()
.setEpoch(Instant.now())
.setTraceId(TraceId.getInvalid())
.setSpanId(SpanId.getInvalid())
.setFlags(TraceFlags.getDefault().asByte())
.setSeverity(Severity.ERROR)
.setSeverityText("really severe")
.setName("log1")
.setBody("message")
.setAttributes(Attributes.builder().put("animal", "cat").build())
.build());
}

private static final class FakeCollector extends LogsServiceGrpc.LogsServiceImplBase {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
import io.opentelemetry.sdk.resources.Resource;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.time.Instant;
import java.util.Collections;
import java.util.List;
import java.util.concurrent.TimeUnit;
Expand All @@ -39,19 +40,20 @@ class ExportTest {

private static final List<LogData> LOGS =
Collections.singletonList(
LogRecord.builder(
Resource.create(Attributes.builder().put("testKey", "testValue").build()),
InstrumentationLibraryInfo.create("instrumentation", "1"))
.setEpochMillis(System.currentTimeMillis())
.setTraceId(TraceId.getInvalid())
.setSpanId(SpanId.getInvalid())
.setFlags(TraceFlags.getDefault().asByte())
.setSeverity(Severity.ERROR)
.setSeverityText("really severe")
.setName("log1")
.setBody("message")
.setAttributes(Attributes.builder().put("animal", "cat").build())
.build());
LogData.create(
Resource.create(Attributes.builder().put("testKey", "testValue").build()),
InstrumentationLibraryInfo.create("instrumentation", "1"),
LogRecord.builder()
.setEpoch(Instant.now())
.setTraceId(TraceId.getInvalid())
.setSpanId(SpanId.getInvalid())
.setFlags(TraceFlags.getDefault().asByte())
.setSeverity(Severity.ERROR)
.setSeverityText("really severe")
.setName("log1")
.setBody("message")
.setAttributes(Attributes.builder().put("animal", "cat").build())
.build()));

@RegisterExtension
@Order(1)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
import io.opentelemetry.sdk.resources.Resource;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.time.Instant;
import java.util.Collections;
import java.util.List;
import java.util.concurrent.TimeUnit;
Expand All @@ -39,19 +40,20 @@ class ExportTest {

private static final List<LogData> LOGS =
Collections.singletonList(
LogRecord.builder(
Resource.create(Attributes.builder().put("testKey", "testValue").build()),
InstrumentationLibraryInfo.create("instrumentation", "1"))
.setEpochMillis(System.currentTimeMillis())
.setTraceId(TraceId.getInvalid())
.setSpanId(SpanId.getInvalid())
.setFlags(TraceFlags.getDefault().asByte())
.setSeverity(Severity.ERROR)
.setSeverityText("really severe")
.setName("log1")
.setBody("message")
.setAttributes(Attributes.builder().put("animal", "cat").build())
.build());
LogData.create(
Resource.create(Attributes.builder().put("testKey", "testValue").build()),
InstrumentationLibraryInfo.create("instrumentation", "1"),
LogRecord.builder()
.setEpoch(Instant.now())
.setTraceId(TraceId.getInvalid())
.setSpanId(SpanId.getInvalid())
.setFlags(TraceFlags.getDefault().asByte())
.setSeverity(Severity.ERROR)
.setSeverityText("really severe")
.setName("log1")
.setBody("message")
.setAttributes(Attributes.builder().put("animal", "cat").build())
.build()));

@RegisterExtension
@Order(1)
Expand Down
Loading