diff --git a/dependencyManagement/build.gradle.kts b/dependencyManagement/build.gradle.kts index 767360e18..5351b2775 100644 --- a/dependencyManagement/build.gradle.kts +++ b/dependencyManagement/build.gradle.kts @@ -7,7 +7,7 @@ data class DependencySet(val group: String, val version: String, val modules: Li val dependencyVersions = hashMapOf() rootProject.extra["versions"] = dependencyVersions -val otelInstrumentationVersion = "2.7.0-alpha" +val otelInstrumentationVersion = "2.8.0-alpha" val DEPENDENCY_BOMS = listOf( "com.fasterxml.jackson:jackson-bom:2.17.2", diff --git a/disk-buffering/src/main/java/io/opentelemetry/contrib/disk/buffering/internal/serialization/mapping/logs/LogRecordDataMapper.java b/disk-buffering/src/main/java/io/opentelemetry/contrib/disk/buffering/internal/serialization/mapping/logs/LogRecordDataMapper.java index deeba2cfb..06ff85847 100644 --- a/disk-buffering/src/main/java/io/opentelemetry/contrib/disk/buffering/internal/serialization/mapping/logs/LogRecordDataMapper.java +++ b/disk-buffering/src/main/java/io/opentelemetry/contrib/disk/buffering/internal/serialization/mapping/logs/LogRecordDataMapper.java @@ -7,8 +7,10 @@ import static io.opentelemetry.contrib.disk.buffering.internal.serialization.mapping.spans.SpanDataMapper.flagsFromInt; import static io.opentelemetry.contrib.disk.buffering.internal.utils.ProtobufTools.toUnsignedInt; +import static java.util.stream.Collectors.toList; import io.opentelemetry.api.common.Attributes; +import io.opentelemetry.api.common.Value; import io.opentelemetry.api.logs.Severity; import io.opentelemetry.api.trace.SpanContext; import io.opentelemetry.api.trace.TraceState; @@ -19,9 +21,9 @@ import io.opentelemetry.proto.logs.v1.LogRecord; import io.opentelemetry.proto.logs.v1.SeverityNumber; import io.opentelemetry.sdk.common.InstrumentationScopeInfo; -import io.opentelemetry.sdk.logs.data.Body; import io.opentelemetry.sdk.logs.data.LogRecordData; import io.opentelemetry.sdk.resources.Resource; +import java.util.stream.Collectors; public final class LogRecordDataMapper { @@ -42,8 +44,8 @@ public LogRecord mapToProto(LogRecordData source) { if (source.getSeverityText() != null) { logRecord.severity_text(source.getSeverityText()); } - if (source.getBody() != null) { - logRecord.body(bodyToAnyValue(source.getBody())); + if (source.getBodyValue() != null) { + logRecord.body(bodyToAnyValue(source.getBodyValue())); } byte flags = source.getSpanContext().getTraceFlags().asByte(); @@ -73,7 +75,7 @@ public LogRecordData mapToSdk( logRecordData.setSeverity(severityNumberToSdk(source.severity_number)); logRecordData.setSeverityText(source.severity_text); if (source.body != null) { - logRecordData.setBody(anyValueToBody(source.body)); + logRecordData.setBodyValue(anyValueToBody(source.body)); } addExtrasToSdkItemBuilder(source, logRecordData, resource, scopeInfo); @@ -99,7 +101,7 @@ private static void addExtrasToSdkItemBuilder( target.setInstrumentationScopeInfo(scopeInfo); } - private static AnyValue bodyToAnyValue(Body body) { + private static AnyValue bodyToAnyValue(Value body) { return new AnyValue.Builder().string_value(body.asString()).build(); } @@ -107,12 +109,30 @@ private static SeverityNumber severityToProto(Severity severity) { return SeverityNumber.fromValue(severity.getSeverityNumber()); } - private static Body anyValueToBody(AnyValue source) { + private static Value anyValueToBody(AnyValue source) { if (source.string_value != null) { - return Body.string(source.string_value); - } else { - return Body.empty(); + return Value.of(source.string_value); + } else if (source.int_value != null) { + return Value.of(source.int_value); + } else if (source.double_value != null) { + return Value.of(source.double_value); + } else if (source.bool_value != null) { + return Value.of(source.bool_value); + } else if (source.bytes_value != null) { + return Value.of(source.bytes_value.toByteArray()); + } else if (source.kvlist_value != null) { + return Value.of( + source.kvlist_value.values.stream() + .collect( + Collectors.toMap( + keyValue -> keyValue.key, keyValue -> anyValueToBody(keyValue.value)))); + } else if (source.array_value != null) { + return Value.of( + source.array_value.values.stream() + .map(LogRecordDataMapper::anyValueToBody) + .collect(toList())); } + throw new IllegalArgumentException("Unrecognized AnyValue type"); } private static Severity severityNumberToSdk(SeverityNumber source) { diff --git a/disk-buffering/src/main/java/io/opentelemetry/contrib/disk/buffering/internal/serialization/mapping/logs/models/LogRecordDataImpl.java b/disk-buffering/src/main/java/io/opentelemetry/contrib/disk/buffering/internal/serialization/mapping/logs/models/LogRecordDataImpl.java index de130e3d1..9ff0f9410 100644 --- a/disk-buffering/src/main/java/io/opentelemetry/contrib/disk/buffering/internal/serialization/mapping/logs/models/LogRecordDataImpl.java +++ b/disk-buffering/src/main/java/io/opentelemetry/contrib/disk/buffering/internal/serialization/mapping/logs/models/LogRecordDataImpl.java @@ -6,13 +6,15 @@ package io.opentelemetry.contrib.disk.buffering.internal.serialization.mapping.logs.models; import com.google.auto.value.AutoValue; +import com.google.errorprone.annotations.CanIgnoreReturnValue; import io.opentelemetry.api.common.Attributes; +import io.opentelemetry.api.common.Value; import io.opentelemetry.api.logs.Severity; import io.opentelemetry.api.trace.SpanContext; import io.opentelemetry.sdk.common.InstrumentationScopeInfo; -import io.opentelemetry.sdk.logs.data.Body; import io.opentelemetry.sdk.logs.data.LogRecordData; import io.opentelemetry.sdk.resources.Resource; +import javax.annotation.Nullable; @AutoValue public abstract class LogRecordDataImpl implements LogRecordData { @@ -21,6 +23,18 @@ public static Builder builder() { return new AutoValue_LogRecordDataImpl.Builder(); } + @Deprecated + public io.opentelemetry.sdk.logs.data.Body getBody() { + Value valueBody = getBodyValue(); + return valueBody == null + ? io.opentelemetry.sdk.logs.data.Body.empty() + : io.opentelemetry.sdk.logs.data.Body.string(valueBody.asString()); + } + + @Override + @Nullable + public abstract Value getBodyValue(); + @AutoValue.Builder public abstract static class Builder { public abstract Builder setResource(Resource value); @@ -37,7 +51,18 @@ public abstract static class Builder { public abstract Builder setSeverityText(String value); - public abstract Builder setBody(Body value); + @Deprecated + @CanIgnoreReturnValue + public Builder setBody(io.opentelemetry.sdk.logs.data.Body body) { + if (body.getType() == io.opentelemetry.sdk.logs.data.Body.Type.STRING) { + setBodyValue(Value.of(body.asString())); + } else if (body.getType() == io.opentelemetry.sdk.logs.data.Body.Type.EMPTY) { + setBodyValue(null); + } + return this; + } + + public abstract Builder setBodyValue(@Nullable Value value); public abstract Builder setAttributes(Attributes value); diff --git a/disk-buffering/src/test/java/io/opentelemetry/contrib/disk/buffering/internal/serialization/mapping/logs/LogRecordDataMapperTest.java b/disk-buffering/src/test/java/io/opentelemetry/contrib/disk/buffering/internal/serialization/mapping/logs/LogRecordDataMapperTest.java index 4e98a8c69..3eb588b45 100644 --- a/disk-buffering/src/test/java/io/opentelemetry/contrib/disk/buffering/internal/serialization/mapping/logs/LogRecordDataMapperTest.java +++ b/disk-buffering/src/test/java/io/opentelemetry/contrib/disk/buffering/internal/serialization/mapping/logs/LogRecordDataMapperTest.java @@ -7,12 +7,12 @@ import static org.junit.jupiter.api.Assertions.assertEquals; +import io.opentelemetry.api.common.Value; import io.opentelemetry.api.logs.Severity; import io.opentelemetry.contrib.disk.buffering.internal.serialization.mapping.logs.models.LogRecordDataImpl; import io.opentelemetry.contrib.disk.buffering.testutils.TestData; import io.opentelemetry.proto.logs.v1.LogRecord; import io.opentelemetry.sdk.common.InstrumentationScopeInfo; -import io.opentelemetry.sdk.logs.data.Body; import io.opentelemetry.sdk.logs.data.LogRecordData; import io.opentelemetry.sdk.resources.Resource; import org.junit.jupiter.api.Test; @@ -25,7 +25,7 @@ class LogRecordDataMapperTest { .setSpanContext(TestData.SPAN_CONTEXT) .setInstrumentationScopeInfo(TestData.INSTRUMENTATION_SCOPE_INFO_FULL) .setAttributes(TestData.ATTRIBUTES) - .setBody(Body.string("Log body")) + .setBodyValue(Value.of("Log body")) .setSeverity(Severity.DEBUG) .setSeverityText("Log severity text") .setTimestampEpochNanos(100L) diff --git a/disk-buffering/src/test/java/io/opentelemetry/contrib/disk/buffering/internal/serialization/mapping/logs/ProtoLogsDataMapperTest.java b/disk-buffering/src/test/java/io/opentelemetry/contrib/disk/buffering/internal/serialization/mapping/logs/ProtoLogsDataMapperTest.java index 48a563300..45c3f6e5e 100644 --- a/disk-buffering/src/test/java/io/opentelemetry/contrib/disk/buffering/internal/serialization/mapping/logs/ProtoLogsDataMapperTest.java +++ b/disk-buffering/src/test/java/io/opentelemetry/contrib/disk/buffering/internal/serialization/mapping/logs/ProtoLogsDataMapperTest.java @@ -8,6 +8,7 @@ import static org.assertj.core.api.Assertions.assertThat; import static org.junit.jupiter.api.Assertions.assertEquals; +import io.opentelemetry.api.common.Value; import io.opentelemetry.api.logs.Severity; import io.opentelemetry.contrib.disk.buffering.internal.serialization.mapping.logs.models.LogRecordDataImpl; import io.opentelemetry.contrib.disk.buffering.testutils.TestData; @@ -15,7 +16,6 @@ import io.opentelemetry.proto.logs.v1.LogsData; import io.opentelemetry.proto.logs.v1.ResourceLogs; import io.opentelemetry.proto.logs.v1.ScopeLogs; -import io.opentelemetry.sdk.logs.data.Body; import io.opentelemetry.sdk.logs.data.LogRecordData; import java.util.Arrays; import java.util.Collection; @@ -31,7 +31,7 @@ class ProtoLogsDataMapperTest { .setSpanContext(TestData.SPAN_CONTEXT) .setInstrumentationScopeInfo(TestData.INSTRUMENTATION_SCOPE_INFO_FULL) .setAttributes(TestData.ATTRIBUTES) - .setBody(Body.string("Log body")) + .setBodyValue(Value.of("Log body")) .setSeverity(Severity.DEBUG) .setSeverityText("Log severity text") .setTimestampEpochNanos(100L) @@ -45,7 +45,7 @@ class ProtoLogsDataMapperTest { .setSpanContext(TestData.SPAN_CONTEXT) .setInstrumentationScopeInfo(TestData.INSTRUMENTATION_SCOPE_INFO_FULL) .setAttributes(TestData.ATTRIBUTES) - .setBody(Body.string("Other log body")) + .setBodyValue(Value.of("Other log body")) .setSeverity(Severity.DEBUG) .setSeverityText("Log severity text") .setTimestampEpochNanos(100L) @@ -59,7 +59,7 @@ class ProtoLogsDataMapperTest { .setSpanContext(TestData.SPAN_CONTEXT) .setInstrumentationScopeInfo(TestData.INSTRUMENTATION_SCOPE_INFO_WITHOUT_VERSION) .setAttributes(TestData.ATTRIBUTES) - .setBody(Body.string("Same resource other scope log")) + .setBodyValue(Value.of("Same resource other scope log")) .setSeverity(Severity.DEBUG) .setSeverityText("Log severity text") .setTimestampEpochNanos(100L) @@ -73,7 +73,7 @@ class ProtoLogsDataMapperTest { .setSpanContext(TestData.SPAN_CONTEXT) .setInstrumentationScopeInfo(TestData.INSTRUMENTATION_SCOPE_INFO_WITHOUT_VERSION) .setAttributes(TestData.ATTRIBUTES) - .setBody(Body.string("Different resource log")) + .setBodyValue(Value.of("Different resource log")) .setSeverity(Severity.DEBUG) .setSeverityText("Log severity text") .setTimestampEpochNanos(100L) diff --git a/disk-buffering/src/test/java/io/opentelemetry/contrib/disk/buffering/internal/serialization/serializers/LogRecordDataSerializerTest.java b/disk-buffering/src/test/java/io/opentelemetry/contrib/disk/buffering/internal/serialization/serializers/LogRecordDataSerializerTest.java index c5d8cea77..1b52bb219 100644 --- a/disk-buffering/src/test/java/io/opentelemetry/contrib/disk/buffering/internal/serialization/serializers/LogRecordDataSerializerTest.java +++ b/disk-buffering/src/test/java/io/opentelemetry/contrib/disk/buffering/internal/serialization/serializers/LogRecordDataSerializerTest.java @@ -6,12 +6,12 @@ package io.opentelemetry.contrib.disk.buffering.internal.serialization.serializers; import io.opentelemetry.api.common.Attributes; +import io.opentelemetry.api.common.Value; import io.opentelemetry.api.logs.Severity; import io.opentelemetry.contrib.disk.buffering.internal.serialization.deserializers.SignalDeserializer; import io.opentelemetry.contrib.disk.buffering.internal.serialization.mapping.logs.models.LogRecordDataImpl; import io.opentelemetry.contrib.disk.buffering.testutils.BaseSignalSerializerTest; import io.opentelemetry.contrib.disk.buffering.testutils.TestData; -import io.opentelemetry.sdk.logs.data.Body; import io.opentelemetry.sdk.logs.data.LogRecordData; import org.junit.jupiter.api.Test; @@ -22,7 +22,7 @@ class LogRecordDataSerializerTest extends BaseSignalSerializerTest { - if (item.getBody().asString().contains("deleted")) { + if (Objects.requireNonNull(item.getBodyValue()).asString().contains("deleted")) { return null; } return item; @@ -87,8 +88,8 @@ void verifyLogFiltering() { List finishedLogRecordItems = memoryLogRecordExporter.getFinishedLogRecordItems(); assertEquals(2, finishedLogRecordItems.size()); - assertEquals("One log", finishedLogRecordItems.get(0).getBody().asString()); - assertEquals("Another log", finishedLogRecordItems.get(1).getBody().asString()); + assertEquals(Value.of("One log"), finishedLogRecordItems.get(0).getBodyValue()); + assertEquals(Value.of("Another log"), finishedLogRecordItems.get(1).getBodyValue()); } private static class ModifiableLogRecordData implements LogRecordData { @@ -136,7 +137,8 @@ public String getSeverityText() { } @Override - public Body getBody() { + @SuppressWarnings("deprecation") // implement deprecated method + public io.opentelemetry.sdk.logs.data.Body getBody() { return delegate.getBody(); }