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

Update dependency io.opentelemetry.instrumentation:opentelemetry-instrumentation-bom-alpha to v2.8.0-alpha #1456

Merged
merged 2 commits into from
Sep 16, 2024
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
2 changes: 1 addition & 1 deletion dependencyManagement/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ data class DependencySet(val group: String, val version: String, val modules: Li
val dependencyVersions = hashMapOf<String, String>()
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",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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 {

Expand All @@ -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();
Expand Down Expand Up @@ -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);
Expand All @@ -99,20 +101,38 @@ 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();
}

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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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);
Expand All @@ -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);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,14 @@
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;
import io.opentelemetry.proto.logs.v1.LogRecord;
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;
Expand All @@ -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)
Expand All @@ -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)
Expand All @@ -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)
Expand All @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -22,7 +22,7 @@ class LogRecordDataSerializerTest extends BaseSignalSerializerTest<LogRecordData
.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)
Expand All @@ -36,7 +36,7 @@ class LogRecordDataSerializerTest extends BaseSignalSerializerTest<LogRecordData
.setSpanContext(TestData.SPAN_CONTEXT)
.setInstrumentationScopeInfo(TestData.INSTRUMENTATION_SCOPE_INFO_FULL)
.setAttributes(Attributes.empty())
.setBody(Body.string("Log body"))
.setBodyValue(Value.of("Log body"))
.setSeverity(Severity.DEBUG)
.setSeverityText("")
.setTimestampEpochNanos(100L)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;

import io.opentelemetry.api.common.Value;
import io.opentelemetry.api.logs.Severity;
import io.opentelemetry.contrib.disk.buffering.internal.files.TemporaryFileProvider;
import io.opentelemetry.contrib.disk.buffering.internal.serialization.deserializers.SignalDeserializer;
Expand All @@ -24,7 +25,6 @@
import io.opentelemetry.contrib.disk.buffering.internal.storage.responses.ReadableResult;
import io.opentelemetry.contrib.disk.buffering.testutils.TestData;
import io.opentelemetry.sdk.common.Clock;
import io.opentelemetry.sdk.logs.data.Body;
import io.opentelemetry.sdk.logs.data.LogRecordData;
import java.io.File;
import java.io.FileOutputStream;
Expand Down Expand Up @@ -53,7 +53,7 @@ class ReadableFileTest {
.setSpanContext(TestData.SPAN_CONTEXT)
.setInstrumentationScopeInfo(TestData.INSTRUMENTATION_SCOPE_INFO_FULL)
.setAttributes(TestData.ATTRIBUTES)
.setBody(Body.string("First log body"))
.setBodyValue(Value.of("First log body"))
.setSeverity(Severity.DEBUG)
.setSeverityText("Log severity text")
.setTimestampEpochNanos(100L)
Expand All @@ -67,7 +67,7 @@ class ReadableFileTest {
.setSpanContext(TestData.SPAN_CONTEXT)
.setInstrumentationScopeInfo(TestData.INSTRUMENTATION_SCOPE_INFO_FULL)
.setAttributes(TestData.ATTRIBUTES)
.setBody(Body.string("Second log body"))
.setBodyValue(Value.of("Second log body"))
.setSeverity(Severity.DEBUG)
.setSeverityText("Log severity text")
.setTimestampEpochNanos(100L)
Expand All @@ -81,7 +81,7 @@ class ReadableFileTest {
.setSpanContext(TestData.SPAN_CONTEXT)
.setInstrumentationScopeInfo(TestData.INSTRUMENTATION_SCOPE_INFO_FULL)
.setAttributes(TestData.ATTRIBUTES)
.setBody(Body.string("Third log body"))
.setBodyValue(Value.of("Third log body"))
.setSeverity(Severity.DEBUG)
.setSeverityText("Log severity text")
.setTimestampEpochNanos(100L)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,18 +10,19 @@
import io.opentelemetry.api.common.AttributeKey;
import io.opentelemetry.api.common.Attributes;
import io.opentelemetry.api.common.AttributesBuilder;
import io.opentelemetry.api.common.Value;
import io.opentelemetry.api.logs.Logger;
import io.opentelemetry.api.logs.Severity;
import io.opentelemetry.api.trace.SpanContext;
import io.opentelemetry.contrib.interceptor.common.ComposableInterceptor;
import io.opentelemetry.sdk.common.InstrumentationScopeInfo;
import io.opentelemetry.sdk.logs.SdkLoggerProvider;
import io.opentelemetry.sdk.logs.data.Body;
import io.opentelemetry.sdk.logs.data.LogRecordData;
import io.opentelemetry.sdk.logs.export.SimpleLogRecordProcessor;
import io.opentelemetry.sdk.resources.Resource;
import io.opentelemetry.sdk.testing.exporter.InMemoryLogRecordExporter;
import java.util.List;
import java.util.Objects;
import javax.annotation.Nullable;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
Expand Down Expand Up @@ -74,7 +75,7 @@ void verifyLogModification() {
void verifyLogFiltering() {
interceptor.add(
item -> {
if (item.getBody().asString().contains("deleted")) {
if (Objects.requireNonNull(item.getBodyValue()).asString().contains("deleted")) {
return null;
}
return item;
Expand All @@ -87,8 +88,8 @@ void verifyLogFiltering() {
List<LogRecordData> 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 {
Expand Down Expand Up @@ -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();
}

Expand Down
Loading