From 9cf9e22ec771b4be4b52e3dab014f3ea2acd92d2 Mon Sep 17 00:00:00 2001 From: Trask Stalnaker Date: Thu, 12 Feb 2026 16:25:45 -0800 Subject: [PATCH 1/3] Enable errorprone's UnnecessarilyFullyQualified --- .../otel.errorprone-conventions.gradle.kts | 4 -- .../internal/marshal/StringEncoderHolder.java | 3 +- .../otlp/AnyValueStatelessMarshaler.java | 9 ++-- .../otlp/metrics/ExemplarMarshaler.java | 38 +++++--------- .../metrics/ExemplarStatelessMarshaler.java | 37 ++++---------- ...anagedChannelTelemetryExporterBuilder.java | 4 +- .../okhttp/internal/OkHttpHttpSender.java | 5 +- .../okhttp/internal/OkHttpGrpcSenderTest.java | 2 +- .../okhttp/internal/RetryInterceptorTest.java | 2 +- .../zipkin/ZipkinSpanExporterBuilder.java | 3 +- .../ZipkinSpanExporterProviderTest.java | 3 +- .../OtlpExporterIntegrationTest.java | 3 +- .../java/io/opentelemetry/Application.java | 2 +- .../opencensusshim/SpanConverter.java | 3 +- .../opentracingshim/OpenTracingShim.java | 5 +- .../opentracingshim/ScopeManagerShim.java | 3 +- .../opentracingshim/SpanShim.java | 2 +- .../opentracingshim/TracerShim.java | 4 +- .../opentracingshim/SpanBuilderShimTest.java | 16 +++--- .../opentracingshim/TracerShimTest.java | 51 ++++++++----------- ...AutoConfiguredOpenTelemetrySdkBuilder.java | 6 +-- .../ConfigurableSpanExporterTest.java | 5 +- .../sdk/autoconfigure/FullConfigTest.java | 4 +- .../TestTracerProviderConfigurer.java | 4 +- .../fileconfig/AggregationFactoryTest.java | 26 ++++------ .../DeclarativeConfigurationParseTest.java | 9 ++-- .../LogRecordProcessorFactoryTest.java | 27 +++++----- .../fileconfig/LoggerProviderFactoryTest.java | 5 +- .../fileconfig/MetricExporterFactoryTest.java | 2 +- .../fileconfig/MetricReaderFactoryTest.java | 10 ++-- ...OpenTelemetryConfigurationFactoryTest.java | 16 +++--- .../fileconfig/SpanProcessorFactoryTest.java | 26 +++++----- .../fileconfig/TracerProviderFactoryTest.java | 5 +- .../incubator/fileconfig/ViewFactoryTest.java | 5 +- .../internal/DynamicPrimitiveLongList.java | 3 +- .../sdk/testing/assertj/SpanDataAssert.java | 3 +- .../sdk/testing/trace/TestSpanData.java | 5 +- .../opentelemetry/sdk/trace/ReadableSpan.java | 3 +- .../io/opentelemetry/sdk/trace/SdkSpan.java | 3 +- .../opentelemetry/sdk/trace/SpanWrapper.java | 3 +- .../sdk/trace/data/DelegatingSpanData.java | 3 +- .../sdk/trace/data/SpanData.java | 3 +- 42 files changed, 168 insertions(+), 207 deletions(-) diff --git a/buildSrc/src/main/kotlin/otel.errorprone-conventions.gradle.kts b/buildSrc/src/main/kotlin/otel.errorprone-conventions.gradle.kts index 7830e1bd7c5..ae5c204e604 100644 --- a/buildSrc/src/main/kotlin/otel.errorprone-conventions.gradle.kts +++ b/buildSrc/src/main/kotlin/otel.errorprone-conventions.gradle.kts @@ -45,10 +45,6 @@ tasks { // Suggests using Guava types for fields but we don't use Guava disable("ImmutableMemberCollection") - // Fully qualified names may be necessary when deprecating a class to avoid - // deprecation warning. - disable("UnnecessarilyFullyQualified") - // We use animal sniffer disable("Java8ApiChecker") diff --git a/exporters/common/src/main/java/io/opentelemetry/exporter/internal/marshal/StringEncoderHolder.java b/exporters/common/src/main/java/io/opentelemetry/exporter/internal/marshal/StringEncoderHolder.java index b9d9794217a..3f0155b20fe 100644 --- a/exporters/common/src/main/java/io/opentelemetry/exporter/internal/marshal/StringEncoderHolder.java +++ b/exporters/common/src/main/java/io/opentelemetry/exporter/internal/marshal/StringEncoderHolder.java @@ -5,6 +5,7 @@ package io.opentelemetry.exporter.internal.marshal; +import java.lang.reflect.Method; import java.util.Optional; import java.util.logging.Level; import java.util.logging.Logger; @@ -51,7 +52,7 @@ public static StringEncoder createVarHandleEncoder() { try { Class varHandleClass = Class.forName("io.opentelemetry.exporter.internal.marshal.VarHandleStringEncoder"); - java.lang.reflect.Method createMethod = varHandleClass.getMethod("createIfAvailable"); + Method createMethod = varHandleClass.getMethod("createIfAvailable"); return (StringEncoder) createMethod.invoke(null); } catch (Throwable t) { return null; diff --git a/exporters/otlp/common/src/main/java/io/opentelemetry/exporter/internal/otlp/AnyValueStatelessMarshaler.java b/exporters/otlp/common/src/main/java/io/opentelemetry/exporter/internal/otlp/AnyValueStatelessMarshaler.java index 9a441b26bbf..ae34288f9a1 100644 --- a/exporters/otlp/common/src/main/java/io/opentelemetry/exporter/internal/otlp/AnyValueStatelessMarshaler.java +++ b/exporters/otlp/common/src/main/java/io/opentelemetry/exporter/internal/otlp/AnyValueStatelessMarshaler.java @@ -11,6 +11,7 @@ import io.opentelemetry.exporter.internal.marshal.Serializer; import io.opentelemetry.exporter.internal.marshal.StatelessMarshaler; import io.opentelemetry.exporter.internal.marshal.StatelessMarshalerUtil; +import io.opentelemetry.proto.common.v1.internal.AnyValue; import java.io.IOException; import java.nio.ByteBuffer; import java.util.List; @@ -49,14 +50,14 @@ public void writeTo(Serializer output, Value value, MarshalerContext context) return; case ARRAY: output.serializeMessageWithContext( - io.opentelemetry.proto.common.v1.internal.AnyValue.ARRAY_VALUE, + AnyValue.ARRAY_VALUE, (List>) value.getValue(), ArrayAnyValueStatelessMarshaler.INSTANCE, context); return; case KEY_VALUE_LIST: output.serializeMessageWithContext( - io.opentelemetry.proto.common.v1.internal.AnyValue.KVLIST_VALUE, + AnyValue.KVLIST_VALUE, (List) value.getValue(), KeyValueListAnyValueStatelessMarshaler.INSTANCE, context); @@ -92,13 +93,13 @@ public int getBinarySerializedSize(Value value, MarshalerContext context) { (Double) value.getValue(), context); case ARRAY: return StatelessMarshalerUtil.sizeMessageWithContext( - io.opentelemetry.proto.common.v1.internal.AnyValue.ARRAY_VALUE, + AnyValue.ARRAY_VALUE, (List>) value.getValue(), ArrayAnyValueStatelessMarshaler.INSTANCE, context); case KEY_VALUE_LIST: return StatelessMarshalerUtil.sizeMessageWithContext( - io.opentelemetry.proto.common.v1.internal.AnyValue.KVLIST_VALUE, + AnyValue.KVLIST_VALUE, (List) value.getValue(), KeyValueListAnyValueStatelessMarshaler.INSTANCE, context); diff --git a/exporters/otlp/common/src/main/java/io/opentelemetry/exporter/internal/otlp/metrics/ExemplarMarshaler.java b/exporters/otlp/common/src/main/java/io/opentelemetry/exporter/internal/otlp/metrics/ExemplarMarshaler.java index 1e0ec8d25cb..44bab9e6e63 100644 --- a/exporters/otlp/common/src/main/java/io/opentelemetry/exporter/internal/otlp/metrics/ExemplarMarshaler.java +++ b/exporters/otlp/common/src/main/java/io/opentelemetry/exporter/internal/otlp/metrics/ExemplarMarshaler.java @@ -11,6 +11,7 @@ import io.opentelemetry.exporter.internal.marshal.ProtoFieldInfo; import io.opentelemetry.exporter.internal.marshal.Serializer; import io.opentelemetry.exporter.internal.otlp.KeyValueMarshaler; +import io.opentelemetry.proto.metrics.v1.internal.Exemplar; import io.opentelemetry.sdk.metrics.data.DoubleExemplarData; import io.opentelemetry.sdk.metrics.data.ExemplarData; import io.opentelemetry.sdk.metrics.data.LongExemplarData; @@ -66,22 +67,17 @@ private ExemplarMarshaler( @Override public void writeTo(Serializer output) throws IOException { - output.serializeFixed64( - io.opentelemetry.proto.metrics.v1.internal.Exemplar.TIME_UNIX_NANO, timeUnixNano); - if (valueField == io.opentelemetry.proto.metrics.v1.internal.Exemplar.AS_INT) { + output.serializeFixed64(Exemplar.TIME_UNIX_NANO, timeUnixNano); + if (valueField == Exemplar.AS_INT) { output.serializeFixed64Optional(valueField, ((LongExemplarData) value).getValue()); } else { output.serializeDoubleOptional(valueField, ((DoubleExemplarData) value).getValue()); } if (spanContext.isValid()) { - output.serializeSpanId( - io.opentelemetry.proto.metrics.v1.internal.Exemplar.SPAN_ID, spanContext.getSpanId()); - output.serializeTraceId( - io.opentelemetry.proto.metrics.v1.internal.Exemplar.TRACE_ID, spanContext.getTraceId()); + output.serializeSpanId(Exemplar.SPAN_ID, spanContext.getSpanId()); + output.serializeTraceId(Exemplar.TRACE_ID, spanContext.getTraceId()); } - output.serializeRepeatedMessage( - io.opentelemetry.proto.metrics.v1.internal.Exemplar.FILTERED_ATTRIBUTES, - filteredAttributeMarshalers); + output.serializeRepeatedMessage(Exemplar.FILTERED_ATTRIBUTES, filteredAttributeMarshalers); } private static int calculateSize( @@ -91,36 +87,28 @@ private static int calculateSize( SpanContext spanContext, KeyValueMarshaler[] filteredAttributeMarshalers) { int size = 0; - size += - MarshalerUtil.sizeFixed64( - io.opentelemetry.proto.metrics.v1.internal.Exemplar.TIME_UNIX_NANO, timeUnixNano); - if (valueField == io.opentelemetry.proto.metrics.v1.internal.Exemplar.AS_INT) { + size += MarshalerUtil.sizeFixed64(Exemplar.TIME_UNIX_NANO, timeUnixNano); + if (valueField == Exemplar.AS_INT) { size += MarshalerUtil.sizeFixed64Optional(valueField, ((LongExemplarData) value).getValue()); } else { size += MarshalerUtil.sizeDoubleOptional(valueField, ((DoubleExemplarData) value).getValue()); } if (spanContext.isValid()) { - size += - MarshalerUtil.sizeSpanId( - io.opentelemetry.proto.metrics.v1.internal.Exemplar.SPAN_ID, spanContext.getSpanId()); - size += - MarshalerUtil.sizeTraceId( - io.opentelemetry.proto.metrics.v1.internal.Exemplar.TRACE_ID, - spanContext.getTraceId()); + size += MarshalerUtil.sizeSpanId(Exemplar.SPAN_ID, spanContext.getSpanId()); + size += MarshalerUtil.sizeTraceId(Exemplar.TRACE_ID, spanContext.getTraceId()); } size += MarshalerUtil.sizeRepeatedMessage( - io.opentelemetry.proto.metrics.v1.internal.Exemplar.FILTERED_ATTRIBUTES, - filteredAttributeMarshalers); + Exemplar.FILTERED_ATTRIBUTES, filteredAttributeMarshalers); return size; } static ProtoFieldInfo toProtoExemplarValueType(ExemplarData exemplar) { if (exemplar instanceof LongExemplarData) { - return io.opentelemetry.proto.metrics.v1.internal.Exemplar.AS_INT; + return Exemplar.AS_INT; } else { assert exemplar instanceof DoubleExemplarData; - return io.opentelemetry.proto.metrics.v1.internal.Exemplar.AS_DOUBLE; + return Exemplar.AS_DOUBLE; } } } diff --git a/exporters/otlp/common/src/main/java/io/opentelemetry/exporter/internal/otlp/metrics/ExemplarStatelessMarshaler.java b/exporters/otlp/common/src/main/java/io/opentelemetry/exporter/internal/otlp/metrics/ExemplarStatelessMarshaler.java index 9959beb7160..70259467b37 100644 --- a/exporters/otlp/common/src/main/java/io/opentelemetry/exporter/internal/otlp/metrics/ExemplarStatelessMarshaler.java +++ b/exporters/otlp/common/src/main/java/io/opentelemetry/exporter/internal/otlp/metrics/ExemplarStatelessMarshaler.java @@ -15,6 +15,7 @@ import io.opentelemetry.exporter.internal.marshal.StatelessMarshaler; import io.opentelemetry.exporter.internal.marshal.StatelessMarshalerUtil; import io.opentelemetry.exporter.internal.otlp.AttributeKeyValueStatelessMarshaler; +import io.opentelemetry.proto.metrics.v1.internal.Exemplar; import io.opentelemetry.sdk.metrics.data.DoubleExemplarData; import io.opentelemetry.sdk.metrics.data.ExemplarData; import io.opentelemetry.sdk.metrics.data.LongExemplarData; @@ -29,28 +30,20 @@ private ExemplarStatelessMarshaler() {} @Override public void writeTo(Serializer output, ExemplarData exemplar, MarshalerContext context) throws IOException { - output.serializeFixed64( - io.opentelemetry.proto.metrics.v1.internal.Exemplar.TIME_UNIX_NANO, - exemplar.getEpochNanos()); + output.serializeFixed64(Exemplar.TIME_UNIX_NANO, exemplar.getEpochNanos()); ProtoFieldInfo valueField = toProtoExemplarValueType(exemplar); - if (valueField == io.opentelemetry.proto.metrics.v1.internal.Exemplar.AS_INT) { + if (valueField == Exemplar.AS_INT) { output.serializeFixed64Optional(valueField, ((LongExemplarData) exemplar).getValue()); } else { output.serializeDoubleOptional(valueField, ((DoubleExemplarData) exemplar).getValue()); } SpanContext spanContext = exemplar.getSpanContext(); if (spanContext.isValid()) { - output.serializeSpanId( - io.opentelemetry.proto.metrics.v1.internal.Exemplar.SPAN_ID, - spanContext.getSpanId(), - context); - output.serializeTraceId( - io.opentelemetry.proto.metrics.v1.internal.Exemplar.TRACE_ID, - spanContext.getTraceId(), - context); + output.serializeSpanId(Exemplar.SPAN_ID, spanContext.getSpanId(), context); + output.serializeTraceId(Exemplar.TRACE_ID, spanContext.getTraceId(), context); } output.serializeRepeatedMessageWithContext( - io.opentelemetry.proto.metrics.v1.internal.Exemplar.FILTERED_ATTRIBUTES, + Exemplar.FILTERED_ATTRIBUTES, exemplar.getFilteredAttributes(), AttributeKeyValueStatelessMarshaler.INSTANCE, context); @@ -59,12 +52,9 @@ public void writeTo(Serializer output, ExemplarData exemplar, MarshalerContext c @Override public int getBinarySerializedSize(ExemplarData exemplar, MarshalerContext context) { int size = 0; - size += - MarshalerUtil.sizeFixed64( - io.opentelemetry.proto.metrics.v1.internal.Exemplar.TIME_UNIX_NANO, - exemplar.getEpochNanos()); + size += MarshalerUtil.sizeFixed64(Exemplar.TIME_UNIX_NANO, exemplar.getEpochNanos()); ProtoFieldInfo valueField = toProtoExemplarValueType(exemplar); - if (valueField == io.opentelemetry.proto.metrics.v1.internal.Exemplar.AS_INT) { + if (valueField == Exemplar.AS_INT) { size += MarshalerUtil.sizeFixed64Optional(valueField, ((LongExemplarData) exemplar).getValue()); } else { @@ -73,17 +63,12 @@ public int getBinarySerializedSize(ExemplarData exemplar, MarshalerContext conte } SpanContext spanContext = exemplar.getSpanContext(); if (spanContext.isValid()) { - size += - MarshalerUtil.sizeSpanId( - io.opentelemetry.proto.metrics.v1.internal.Exemplar.SPAN_ID, spanContext.getSpanId()); - size += - MarshalerUtil.sizeTraceId( - io.opentelemetry.proto.metrics.v1.internal.Exemplar.TRACE_ID, - spanContext.getTraceId()); + size += MarshalerUtil.sizeSpanId(Exemplar.SPAN_ID, spanContext.getSpanId()); + size += MarshalerUtil.sizeTraceId(Exemplar.TRACE_ID, spanContext.getTraceId()); } size += StatelessMarshalerUtil.sizeRepeatedMessageWithContext( - io.opentelemetry.proto.metrics.v1.internal.Exemplar.FILTERED_ATTRIBUTES, + Exemplar.FILTERED_ATTRIBUTES, exemplar.getFilteredAttributes(), AttributeKeyValueStatelessMarshaler.INSTANCE, context); diff --git a/exporters/otlp/testing-internal/src/main/java/io/opentelemetry/exporter/otlp/testing/internal/ManagedChannelTelemetryExporterBuilder.java b/exporters/otlp/testing-internal/src/main/java/io/opentelemetry/exporter/otlp/testing/internal/ManagedChannelTelemetryExporterBuilder.java index f8b89a0ed36..cbd0168789b 100644 --- a/exporters/otlp/testing-internal/src/main/java/io/opentelemetry/exporter/otlp/testing/internal/ManagedChannelTelemetryExporterBuilder.java +++ b/exporters/otlp/testing-internal/src/main/java/io/opentelemetry/exporter/otlp/testing/internal/ManagedChannelTelemetryExporterBuilder.java @@ -11,6 +11,7 @@ import io.grpc.ManagedChannelBuilder; import io.grpc.netty.GrpcSslContexts; import io.grpc.netty.NettyChannelBuilder; +import io.grpc.okhttp.OkHttpChannelBuilder; import io.netty.handler.ssl.SslContext; import io.opentelemetry.api.metrics.MeterProvider; import io.opentelemetry.common.ComponentLoader; @@ -286,8 +287,7 @@ private static void setSslContext( if (sslContext == null) { return; } - io.grpc.okhttp.OkHttpChannelBuilder okHttpBuilder = - (io.grpc.okhttp.OkHttpChannelBuilder) managedChannelBuilder; + OkHttpChannelBuilder okHttpBuilder = (OkHttpChannelBuilder) managedChannelBuilder; okHttpBuilder.sslSocketFactory(sslContext.getSocketFactory()); break; default: diff --git a/exporters/sender/okhttp/src/main/java/io/opentelemetry/exporter/sender/okhttp/internal/OkHttpHttpSender.java b/exporters/sender/okhttp/src/main/java/io/opentelemetry/exporter/sender/okhttp/internal/OkHttpHttpSender.java index 7e7c8b96379..16b5d90b7f4 100644 --- a/exporters/sender/okhttp/src/main/java/io/opentelemetry/exporter/sender/okhttp/internal/OkHttpHttpSender.java +++ b/exporters/sender/okhttp/src/main/java/io/opentelemetry/exporter/sender/okhttp/internal/OkHttpHttpSender.java @@ -37,6 +37,7 @@ import okhttp3.OkHttpClient; import okhttp3.Request; import okhttp3.RequestBody; +import okhttp3.Response; import okhttp3.ResponseBody; import okio.BufferedSink; import okio.Okio; @@ -139,7 +140,7 @@ public void onFailure(Call call, IOException e) { } @Override - public void onResponse(Call call, okhttp3.Response response) { + public void onResponse(Call call, Response response) { try (ResponseBody body = response.body()) { onResponse.accept( new HttpResponse() { @@ -183,7 +184,7 @@ public CompletableResultCode shutdown() { return CompletableResultCode.ofSuccess(); } - static boolean isRetryable(okhttp3.Response response) { + static boolean isRetryable(Response response) { return RetryUtil.retryableHttpResponseCodes().contains(response.code()); } diff --git a/exporters/sender/okhttp/src/test/java/io/opentelemetry/exporter/sender/okhttp/internal/OkHttpGrpcSenderTest.java b/exporters/sender/okhttp/src/test/java/io/opentelemetry/exporter/sender/okhttp/internal/OkHttpGrpcSenderTest.java index 691d554b9d6..2127f92a072 100644 --- a/exporters/sender/okhttp/src/test/java/io/opentelemetry/exporter/sender/okhttp/internal/OkHttpGrpcSenderTest.java +++ b/exporters/sender/okhttp/src/test/java/io/opentelemetry/exporter/sender/okhttp/internal/OkHttpGrpcSenderTest.java @@ -108,7 +108,7 @@ void shutdown_CompletableResultCodeShouldWaitForThreads() throws Exception { "CompletableResultCode should not be done immediately - it should wait for thread termination"); // Now wait for it to complete - shutdownResult.join(10, java.util.concurrent.TimeUnit.SECONDS); + shutdownResult.join(10, TimeUnit.SECONDS); assertTrue(shutdownResult.isDone(), "CompletableResultCode should be done after waiting"); assertTrue(shutdownResult.isSuccess(), "Shutdown should complete successfully"); } diff --git a/exporters/sender/okhttp/src/test/java/io/opentelemetry/exporter/sender/okhttp/internal/RetryInterceptorTest.java b/exporters/sender/okhttp/src/test/java/io/opentelemetry/exporter/sender/okhttp/internal/RetryInterceptorTest.java index 6ae0a6edd1c..e80c2e65c6d 100644 --- a/exporters/sender/okhttp/src/test/java/io/opentelemetry/exporter/sender/okhttp/internal/RetryInterceptorTest.java +++ b/exporters/sender/okhttp/src/test/java/io/opentelemetry/exporter/sender/okhttp/internal/RetryInterceptorTest.java @@ -68,7 +68,7 @@ class RetryInterceptorTest { @BeforeEach void setUp() { - Logger logger = java.util.logging.Logger.getLogger(RetryInterceptor.class.getName()); + Logger logger = Logger.getLogger(RetryInterceptor.class.getName()); logger.setLevel(Level.FINER); retryExceptionPredicate = spy( diff --git a/exporters/zipkin/src/main/java/io/opentelemetry/exporter/zipkin/ZipkinSpanExporterBuilder.java b/exporters/zipkin/src/main/java/io/opentelemetry/exporter/zipkin/ZipkinSpanExporterBuilder.java index a5714912590..68007dc442a 100644 --- a/exporters/zipkin/src/main/java/io/opentelemetry/exporter/zipkin/ZipkinSpanExporterBuilder.java +++ b/exporters/zipkin/src/main/java/io/opentelemetry/exporter/zipkin/ZipkinSpanExporterBuilder.java @@ -20,6 +20,7 @@ import zipkin2.Span; import zipkin2.reporter.BytesEncoder; import zipkin2.reporter.BytesMessageSender; +import zipkin2.reporter.Sender; import zipkin2.reporter.SpanBytesEncoder; import zipkin2.reporter.okhttp3.OkHttpSender; @@ -55,7 +56,7 @@ public final class ZipkinSpanExporterBuilder { * @deprecated Use {@link #setSender(BytesMessageSender)} insteead. */ @Deprecated - public ZipkinSpanExporterBuilder setSender(zipkin2.reporter.Sender sender) { + public ZipkinSpanExporterBuilder setSender(Sender sender) { return setSender((BytesMessageSender) sender); } diff --git a/exporters/zipkin/src/test/java/io/opentelemetry/exporter/zipkin/internal/ZipkinSpanExporterProviderTest.java b/exporters/zipkin/src/test/java/io/opentelemetry/exporter/zipkin/internal/ZipkinSpanExporterProviderTest.java index 5738e071d47..e21b2a7d6f1 100644 --- a/exporters/zipkin/src/test/java/io/opentelemetry/exporter/zipkin/internal/ZipkinSpanExporterProviderTest.java +++ b/exporters/zipkin/src/test/java/io/opentelemetry/exporter/zipkin/internal/ZipkinSpanExporterProviderTest.java @@ -51,8 +51,7 @@ void createExporter_WithConfiguration() { try (SpanExporter spanExporter = provider.createExporter(DefaultConfigProperties.createFromMap(config))) { - assertThat(spanExporter) - .isInstanceOf(io.opentelemetry.exporter.zipkin.ZipkinSpanExporter.class); + assertThat(spanExporter).isInstanceOf(ZipkinSpanExporter.class); assertThat(spanExporter) .extracting("sender") .extracting("delegate") diff --git a/integration-tests/otlp/src/main/java/io/opentelemetry/integrationtest/OtlpExporterIntegrationTest.java b/integration-tests/otlp/src/main/java/io/opentelemetry/integrationtest/OtlpExporterIntegrationTest.java index caa77fe5b14..5607aa549f5 100644 --- a/integration-tests/otlp/src/main/java/io/opentelemetry/integrationtest/OtlpExporterIntegrationTest.java +++ b/integration-tests/otlp/src/main/java/io/opentelemetry/integrationtest/OtlpExporterIntegrationTest.java @@ -50,6 +50,7 @@ import io.opentelemetry.proto.common.v1.AnyValue; import io.opentelemetry.proto.common.v1.ArrayValue; import io.opentelemetry.proto.common.v1.KeyValueList; +import io.opentelemetry.proto.logs.v1.LogRecord; import io.opentelemetry.proto.logs.v1.ResourceLogs; import io.opentelemetry.proto.logs.v1.ScopeLogs; import io.opentelemetry.proto.metrics.v1.AggregationTemporality; @@ -689,7 +690,7 @@ private static void testLogRecordExporter(LogRecordExporter logRecordExporter) { assertThat(ilLogs.getLogRecordsCount()).isEqualTo(1); // LogRecord via Logger.logRecordBuilder()...emit() - io.opentelemetry.proto.logs.v1.LogRecord protoLog1 = ilLogs.getLogRecords(0); + LogRecord protoLog1 = ilLogs.getLogRecords(0); assertThat(protoLog1.getEventName()).isEqualTo("event name"); assertThat(protoLog1.getBody()) .isEqualTo( diff --git a/integration-tests/tracecontext/src/main/java/io/opentelemetry/Application.java b/integration-tests/tracecontext/src/main/java/io/opentelemetry/Application.java index 35c7e846520..0b64333e147 100644 --- a/integration-tests/tracecontext/src/main/java/io/opentelemetry/Application.java +++ b/integration-tests/tracecontext/src/main/java/io/opentelemetry/Application.java @@ -87,7 +87,7 @@ public String serve(RequestHeaders headers, List requests) { .getTextMapPropagator() .extract(Context.current(), headers, ArmeriaGetter.INSTANCE); - for (io.opentelemetry.Request req : requests) { + for (Request req : requests) { Span span = openTelemetry .getTracer("validation-server") diff --git a/opencensus-shim/src/main/java/io/opentelemetry/opencensusshim/SpanConverter.java b/opencensus-shim/src/main/java/io/opentelemetry/opencensusshim/SpanConverter.java index cf031586e60..a801889414f 100644 --- a/opencensus-shim/src/main/java/io/opentelemetry/opencensusshim/SpanConverter.java +++ b/opencensus-shim/src/main/java/io/opentelemetry/opencensusshim/SpanConverter.java @@ -8,6 +8,7 @@ import io.opencensus.common.Function; import io.opencensus.trace.BlankSpan; import io.opencensus.trace.Span; +import io.opencensus.trace.Span.Kind; import io.opencensus.trace.SpanContext; import io.opencensus.trace.SpanId; import io.opencensus.trace.TraceId; @@ -28,7 +29,7 @@ final class SpanConverter { private SpanConverter() {} - static SpanKind mapKind(@Nullable io.opencensus.trace.Span.Kind ocKind) { + static SpanKind mapKind(@Nullable Kind ocKind) { if (ocKind == null) { return SpanKind.INTERNAL; } diff --git a/opentracing-shim/src/main/java/io/opentelemetry/opentracingshim/OpenTracingShim.java b/opentracing-shim/src/main/java/io/opentelemetry/opentracingshim/OpenTracingShim.java index 47b73b12b36..8fcf5aec207 100644 --- a/opentracing-shim/src/main/java/io/opentelemetry/opentracingshim/OpenTracingShim.java +++ b/opentracing-shim/src/main/java/io/opentelemetry/opentracingshim/OpenTracingShim.java @@ -8,6 +8,7 @@ import io.opentelemetry.api.OpenTelemetry; import io.opentelemetry.api.trace.TracerProvider; import io.opentelemetry.context.propagation.TextMapPropagator; +import io.opentracing.Tracer; /** * Factory for creating an OpenTracing {@link io.opentracing.Tracer} that is implemented using the @@ -26,7 +27,7 @@ private OpenTracingShim() {} * @param openTelemetry the {@code OpenTelemetry} instance used to create this shim. * @return a {@code io.opentracing.Tracer}. */ - public static io.opentracing.Tracer createTracerShim(OpenTelemetry openTelemetry) { + public static Tracer createTracerShim(OpenTelemetry openTelemetry) { TextMapPropagator propagator = openTelemetry.getPropagators().getTextMapPropagator(); return createTracerShim(openTelemetry.getTracerProvider(), propagator, propagator); } @@ -42,7 +43,7 @@ public static io.opentracing.Tracer createTracerShim(OpenTelemetry openTelemetry * io.opentracing.propagation.Format.Builtin#HTTP_HEADERS} format. * @return a {@code io.opentracing.Tracer}. */ - public static io.opentracing.Tracer createTracerShim( + public static Tracer createTracerShim( TracerProvider provider, TextMapPropagator textMapPropagator, TextMapPropagator httpPropagator) { diff --git a/opentracing-shim/src/main/java/io/opentelemetry/opentracingshim/ScopeManagerShim.java b/opentracing-shim/src/main/java/io/opentelemetry/opentracingshim/ScopeManagerShim.java index 06ed3e17372..410c662020f 100644 --- a/opentracing-shim/src/main/java/io/opentelemetry/opentracingshim/ScopeManagerShim.java +++ b/opentracing-shim/src/main/java/io/opentelemetry/opentracingshim/ScopeManagerShim.java @@ -5,6 +5,7 @@ package io.opentelemetry.opentracingshim; +import io.opentelemetry.api.baggage.Baggage; import io.opentelemetry.context.Context; import io.opentracing.Scope; import io.opentracing.ScopeManager; @@ -22,7 +23,7 @@ final class ScopeManagerShim implements ScopeManager { public Span activeSpan() { SpanShim spanShim = SpanShim.current(); io.opentelemetry.api.trace.Span span = io.opentelemetry.api.trace.Span.current(); - io.opentelemetry.api.baggage.Baggage baggage = io.opentelemetry.api.baggage.Baggage.current(); + Baggage baggage = Baggage.current(); if (!span.getSpanContext().isValid()) { if (baggage.isEmpty()) { diff --git a/opentracing-shim/src/main/java/io/opentelemetry/opentracingshim/SpanShim.java b/opentracing-shim/src/main/java/io/opentelemetry/opentracingshim/SpanShim.java index 158f689506d..a5524cd1645 100644 --- a/opentracing-shim/src/main/java/io/opentelemetry/opentracingshim/SpanShim.java +++ b/opentracing-shim/src/main/java/io/opentelemetry/opentracingshim/SpanShim.java @@ -65,7 +65,7 @@ io.opentelemetry.api.trace.Span getSpan() { return span; } - io.opentelemetry.api.baggage.Baggage getBaggage() { + Baggage getBaggage() { return spanContextShim.getBaggage(); } diff --git a/opentracing-shim/src/main/java/io/opentelemetry/opentracingshim/TracerShim.java b/opentracing-shim/src/main/java/io/opentelemetry/opentracingshim/TracerShim.java index 82b48410df1..ace67e893e6 100644 --- a/opentracing-shim/src/main/java/io/opentelemetry/opentracingshim/TracerShim.java +++ b/opentracing-shim/src/main/java/io/opentelemetry/opentracingshim/TracerShim.java @@ -27,14 +27,14 @@ final class TracerShim implements Tracer { private static final Logger logger = Logger.getLogger(TracerShim.class.getName()); - private final io.opentelemetry.api.trace.TracerProvider provider; + private final TracerProvider provider; private final io.opentelemetry.api.trace.Tracer tracer; private final ScopeManager scopeManagerShim; private final Propagation propagation; private final AtomicBoolean isShutdown = new AtomicBoolean(); TracerShim( - io.opentelemetry.api.trace.TracerProvider provider, + TracerProvider provider, TextMapPropagator textMapPropagator, TextMapPropagator httpPropagator) { this.provider = provider; diff --git a/opentracing-shim/src/test/java/io/opentelemetry/opentracingshim/SpanBuilderShimTest.java b/opentracing-shim/src/test/java/io/opentelemetry/opentracingshim/SpanBuilderShimTest.java index a935f1a6971..d6b3ec70a27 100644 --- a/opentracing-shim/src/test/java/io/opentelemetry/opentracingshim/SpanBuilderShimTest.java +++ b/opentracing-shim/src/test/java/io/opentelemetry/opentracingshim/SpanBuilderShimTest.java @@ -10,8 +10,10 @@ import static org.assertj.core.api.Assertions.assertThat; import io.opentelemetry.api.GlobalOpenTelemetry; +import io.opentelemetry.api.baggage.Baggage; import io.opentelemetry.api.common.AttributeKey; import io.opentelemetry.api.common.Attributes; +import io.opentelemetry.api.trace.Span; import io.opentelemetry.api.trace.SpanContext; import io.opentelemetry.api.trace.SpanId; import io.opentelemetry.api.trace.SpanKind; @@ -199,8 +201,7 @@ void parent_wrongRefType() { try { // Incorrect typeref values get discarded. SpanData spanData = ((ReadableSpan) childSpan.getSpan()).toSpanData(); - assertThat(spanData.getParentSpanContext()) - .isEqualTo(io.opentelemetry.api.trace.SpanContext.getInvalid()); + assertThat(spanData.getParentSpanContext()).isEqualTo(SpanContext.getInvalid()); assertThat(spanData.getLinks()).isEmpty(); } finally { childSpan.finish(); @@ -278,9 +279,8 @@ void baggage_multipleParents() { @Test void baggage_spanWithInvalidSpan() { - io.opentelemetry.api.baggage.Baggage baggage = - io.opentelemetry.api.baggage.Baggage.builder().put("foo", "bar").build(); - SpanShim span = new SpanShim(io.opentelemetry.api.trace.Span.getInvalid(), baggage); + Baggage baggage = Baggage.builder().put("foo", "bar").build(); + SpanShim span = new SpanShim(Span.getInvalid(), baggage); SpanShim childSpan = (SpanShim) new SpanBuilderShim(tracer, SPAN_NAME).asChildOf(span).start(); assertThat(childSpan.getBaggage()).isEqualTo(baggage); @@ -288,10 +288,8 @@ void baggage_spanWithInvalidSpan() { @Test void baggage_spanContextWithInvalidSpan() { - io.opentelemetry.api.baggage.Baggage baggage = - io.opentelemetry.api.baggage.Baggage.builder().put("foo", "bar").build(); - SpanContextShim spanContext = - new SpanContextShim(io.opentelemetry.api.trace.Span.getInvalid().getSpanContext(), baggage); + Baggage baggage = Baggage.builder().put("foo", "bar").build(); + SpanContextShim spanContext = new SpanContextShim(Span.getInvalid().getSpanContext(), baggage); SpanShim childSpan = (SpanShim) new SpanBuilderShim(tracer, SPAN_NAME).asChildOf(spanContext).start(); diff --git a/opentracing-shim/src/test/java/io/opentelemetry/opentracingshim/TracerShimTest.java b/opentracing-shim/src/test/java/io/opentelemetry/opentracingshim/TracerShimTest.java index 0e8a1dd5df5..987123ca266 100644 --- a/opentracing-shim/src/test/java/io/opentelemetry/opentracingshim/TracerShimTest.java +++ b/opentracing-shim/src/test/java/io/opentelemetry/opentracingshim/TracerShimTest.java @@ -12,6 +12,7 @@ import io.opentelemetry.api.GlobalOpenTelemetry; import io.opentelemetry.api.OpenTelemetry; +import io.opentelemetry.api.baggage.Baggage; import io.opentelemetry.api.baggage.propagation.W3CBaggagePropagator; import io.opentelemetry.api.trace.TracerProvider; import io.opentelemetry.context.Context; @@ -43,8 +44,7 @@ class TracerShimTest { static final io.opentelemetry.api.trace.Span INVALID_SPAN = io.opentelemetry.api.trace.Span.getInvalid(); - static final io.opentelemetry.api.baggage.Baggage EMPTY_BAGGAGE = - io.opentelemetry.api.baggage.Baggage.empty(); + static final Baggage EMPTY_BAGGAGE = Baggage.empty(); @RegisterExtension static final OpenTelemetryExtension otelTesting = OpenTelemetryExtension.create(); @@ -84,7 +84,7 @@ void activateSpan() { assertThat(tracerShim.activeSpan()).isNull(); assertThat(tracerShim.scopeManager().activeSpan()).isNull(); assertThat(io.opentelemetry.api.trace.Span.current()).isSameAs(INVALID_SPAN); - assertThat(io.opentelemetry.api.baggage.Baggage.current()).isSameAs(EMPTY_BAGGAGE); + assertThat(Baggage.current()).isSameAs(EMPTY_BAGGAGE); try (Scope scope = tracerShim.activateSpan(otSpan)) { assertThat(tracerShim.activeSpan()).isNotNull(); @@ -94,13 +94,13 @@ void activateSpan() { .isSameAs(actualSpan); assertThat(io.opentelemetry.api.trace.Span.current()).isSameAs(actualSpan); - assertThat(io.opentelemetry.api.baggage.Baggage.current()).isSameAs(EMPTY_BAGGAGE); + assertThat(Baggage.current()).isSameAs(EMPTY_BAGGAGE); } assertThat(tracerShim.activeSpan()).isNull(); assertThat(tracerShim.scopeManager().activeSpan()).isNull(); assertThat(io.opentelemetry.api.trace.Span.current()).isSameAs(INVALID_SPAN); - assertThat(io.opentelemetry.api.baggage.Baggage.current()).isSameAs(EMPTY_BAGGAGE); + assertThat(Baggage.current()).isSameAs(EMPTY_BAGGAGE); } @Test @@ -108,7 +108,7 @@ void activateNullSpan() { assertThat(tracerShim.activeSpan()).isNull(); assertThat(tracerShim.scopeManager().activeSpan()).isNull(); assertThat(io.opentelemetry.api.trace.Span.current()).isSameAs(INVALID_SPAN); - assertThat(io.opentelemetry.api.baggage.Baggage.current()).isSameAs(EMPTY_BAGGAGE); + assertThat(Baggage.current()).isSameAs(EMPTY_BAGGAGE); Span otSpan = tracerShim.buildSpan("one").start(); io.opentelemetry.api.trace.Span actualSpan = ((SpanShim) otSpan).getSpan(); @@ -125,7 +125,7 @@ void activateNullSpan() { assertThat(tracerShim.activeSpan()).isNull(); assertThat(tracerShim.scopeManager().activeSpan()).isNull(); assertThat(io.opentelemetry.api.trace.Span.current()).isSameAs(INVALID_SPAN); - assertThat(io.opentelemetry.api.baggage.Baggage.current()).isSameAs(EMPTY_BAGGAGE); + assertThat(Baggage.current()).isSameAs(EMPTY_BAGGAGE); } @Test @@ -135,19 +135,14 @@ void activateSpan_withBaggage() { otSpan.setBaggageItem("hello", "world"); io.opentelemetry.api.trace.Span actualSpan = ((SpanShim) otSpan).getSpan(); - io.opentelemetry.api.baggage.Baggage actualBaggage = - ((SpanContextShim) otSpan.context()).getBaggage(); - assertThat( - io.opentelemetry.api.baggage.Baggage.builder() - .put("foo", "bar") - .put("hello", "world") - .build()) + Baggage actualBaggage = ((SpanContextShim) otSpan.context()).getBaggage(); + assertThat(Baggage.builder().put("foo", "bar").put("hello", "world").build()) .isEqualTo(actualBaggage); assertThat(tracerShim.activeSpan()).isNull(); assertThat(tracerShim.scopeManager().activeSpan()).isNull(); assertThat(io.opentelemetry.api.trace.Span.current()).isSameAs(INVALID_SPAN); - assertThat(io.opentelemetry.api.baggage.Baggage.current()).isSameAs(EMPTY_BAGGAGE); + assertThat(Baggage.current()).isSameAs(EMPTY_BAGGAGE); try (Scope scope = tracerShim.activateSpan(otSpan)) { assertThat(tracerShim.activeSpan()).isNotNull(); @@ -157,7 +152,7 @@ void activateSpan_withBaggage() { .isSameAs(actualSpan); assertThat(io.opentelemetry.api.trace.Span.current()).isSameAs(actualSpan); - assertThat(io.opentelemetry.api.baggage.Baggage.current()).isSameAs(actualBaggage); + assertThat(Baggage.current()).isSameAs(actualBaggage); Span child = tracerShim.buildSpan("child").start(); assertThat(child.getBaggageItem("foo")).isEqualTo("bar"); @@ -166,7 +161,7 @@ void activateSpan_withBaggage() { assertThat(tracerShim.activeSpan()).isNull(); assertThat(tracerShim.scopeManager().activeSpan()).isNull(); assertThat(io.opentelemetry.api.trace.Span.current()).isSameAs(INVALID_SPAN); - assertThat(io.opentelemetry.api.baggage.Baggage.current()).isSameAs(EMPTY_BAGGAGE); + assertThat(Baggage.current()).isSameAs(EMPTY_BAGGAGE); } /* A Span should activate its related Baggage, which may mean implicitly @@ -177,16 +172,12 @@ public void activateSpan_withExistingBaggage() { Span otSpan = tracerShim.buildSpan("one").start(); io.opentelemetry.api.trace.Span actualSpan = ((SpanShim) otSpan).getSpan(); - io.opentelemetry.api.baggage.Baggage otherBaggage = - io.opentelemetry.api.baggage.Baggage.builder() - .put("foo", "bar") - .put("hello", "world") - .build(); + Baggage otherBaggage = Baggage.builder().put("foo", "bar").put("hello", "world").build(); assertThat(tracerShim.activeSpan()).isNull(); assertThat(tracerShim.scopeManager().activeSpan()).isNull(); assertThat(io.opentelemetry.api.trace.Span.current()).isSameAs(INVALID_SPAN); - assertThat(io.opentelemetry.api.baggage.Baggage.current()).isSameAs(EMPTY_BAGGAGE); + assertThat(Baggage.current()).isSameAs(EMPTY_BAGGAGE); try (io.opentelemetry.context.Scope scope1 = otherBaggage.makeCurrent()) { try (Scope scope2 = tracerShim.activateSpan(otSpan)) { @@ -197,14 +188,14 @@ public void activateSpan_withExistingBaggage() { .isSameAs(actualSpan); assertThat(io.opentelemetry.api.trace.Span.current()).isSameAs(actualSpan); - assertThat(io.opentelemetry.api.baggage.Baggage.current()).isSameAs(EMPTY_BAGGAGE); + assertThat(Baggage.current()).isSameAs(EMPTY_BAGGAGE); } } assertThat(tracerShim.activeSpan()).isNull(); assertThat(tracerShim.scopeManager().activeSpan()).isNull(); assertThat(io.opentelemetry.api.trace.Span.current()).isSameAs(INVALID_SPAN); - assertThat(io.opentelemetry.api.baggage.Baggage.current()).isSameAs(EMPTY_BAGGAGE); + assertThat(Baggage.current()).isSameAs(EMPTY_BAGGAGE); } /* @@ -220,7 +211,7 @@ void activateSpan_cacheSpanShim() { assertThat(tracerShim.activeSpan()).isNull(); assertThat(tracerShim.scopeManager().activeSpan()).isNull(); assertThat(io.opentelemetry.api.trace.Span.current()).isSameAs(INVALID_SPAN); - assertThat(io.opentelemetry.api.baggage.Baggage.current()).isSameAs(EMPTY_BAGGAGE); + assertThat(Baggage.current()).isSameAs(EMPTY_BAGGAGE); try (Scope scope = tracerShim.activateSpan(otSpan)) { assertThat(tracerShim.activeSpan()).isSameAs(tracerShim.activeSpan()); @@ -232,7 +223,7 @@ void activateSpan_cacheSpanShim() { assertThat(tracerShim.activeSpan()).isNull(); assertThat(tracerShim.scopeManager().activeSpan()).isNull(); assertThat(io.opentelemetry.api.trace.Span.current()).isSameAs(INVALID_SPAN); - assertThat(io.opentelemetry.api.baggage.Baggage.current()).isSameAs(EMPTY_BAGGAGE); + assertThat(Baggage.current()).isSameAs(EMPTY_BAGGAGE); } /* @@ -256,8 +247,7 @@ void activateSpan_withoutShim() { @Test void activeSpan_onlyBaggage() { - io.opentelemetry.api.baggage.Baggage baggage = - io.opentelemetry.api.baggage.Baggage.builder().put("foo", "bar").build(); + Baggage baggage = Baggage.builder().put("foo", "bar").build(); try (io.opentelemetry.context.Scope scope = Context.root().with(baggage).makeCurrent()) { Span span = tracerShim.activeSpan(); @@ -349,8 +339,7 @@ void extract_onlyBaggage() { W3CBaggagePropagator propagator = W3CBaggagePropagator.getInstance(); tracerShim = new TracerShim(provider, propagator, TextMapPropagator.noop()); - io.opentelemetry.api.baggage.Baggage baggage = - io.opentelemetry.api.baggage.Baggage.builder().put("foo", "bar").build(); + Baggage baggage = Baggage.builder().put("foo", "bar").build(); Map map = new HashMap<>(); propagator.inject(Context.root().with(baggage), map, Map::put); diff --git a/sdk-extensions/autoconfigure/src/main/java/io/opentelemetry/sdk/autoconfigure/AutoConfiguredOpenTelemetrySdkBuilder.java b/sdk-extensions/autoconfigure/src/main/java/io/opentelemetry/sdk/autoconfigure/AutoConfiguredOpenTelemetrySdkBuilder.java index 8d7b7c46317..ddb50a2b0a0 100644 --- a/sdk-extensions/autoconfigure/src/main/java/io/opentelemetry/sdk/autoconfigure/AutoConfiguredOpenTelemetrySdkBuilder.java +++ b/sdk-extensions/autoconfigure/src/main/java/io/opentelemetry/sdk/autoconfigure/AutoConfiguredOpenTelemetrySdkBuilder.java @@ -20,6 +20,7 @@ import io.opentelemetry.sdk.autoconfigure.spi.ConfigurationException; import io.opentelemetry.sdk.autoconfigure.spi.internal.AutoConfigureListener; import io.opentelemetry.sdk.autoconfigure.spi.internal.DefaultConfigProperties; +import io.opentelemetry.sdk.autoconfigure.spi.traces.SdkTracerProviderConfigurer; import io.opentelemetry.sdk.logs.LogRecordProcessor; import io.opentelemetry.sdk.logs.SdkLoggerProvider; import io.opentelemetry.sdk.logs.SdkLoggerProviderBuilder; @@ -615,9 +616,8 @@ void callAutoConfigureListeners(SpiHelper spiHelper, OpenTelemetrySdk openTeleme @SuppressWarnings("deprecation") // Support deprecated SdkTracerProviderConfigurer void mergeSdkTracerProviderConfigurer() { - for (io.opentelemetry.sdk.autoconfigure.spi.traces.SdkTracerProviderConfigurer configurer : - componentLoader.load( - io.opentelemetry.sdk.autoconfigure.spi.traces.SdkTracerProviderConfigurer.class)) { + for (SdkTracerProviderConfigurer configurer : + componentLoader.load(SdkTracerProviderConfigurer.class)) { addTracerProviderCustomizer( (builder, config) -> { configurer.configure(builder, config); diff --git a/sdk-extensions/autoconfigure/src/testFullConfig/java/io/opentelemetry/sdk/autoconfigure/ConfigurableSpanExporterTest.java b/sdk-extensions/autoconfigure/src/testFullConfig/java/io/opentelemetry/sdk/autoconfigure/ConfigurableSpanExporterTest.java index 53a539a5c37..d09dd4ce0d5 100644 --- a/sdk-extensions/autoconfigure/src/testFullConfig/java/io/opentelemetry/sdk/autoconfigure/ConfigurableSpanExporterTest.java +++ b/sdk-extensions/autoconfigure/src/testFullConfig/java/io/opentelemetry/sdk/autoconfigure/ConfigurableSpanExporterTest.java @@ -217,8 +217,7 @@ void configureSpanProcessors_multipleExporters() { spanExporters -> { assertThat(spanExporters.length).isEqualTo(2); assertThat(spanExporters) - .hasAtLeastOneElementOfType( - io.opentelemetry.exporter.zipkin.ZipkinSpanExporter.class) + .hasAtLeastOneElementOfType(ZipkinSpanExporter.class) .hasAtLeastOneElementOfType(OtlpGrpcSpanExporter.class); }); }); @@ -237,7 +236,7 @@ void configureSpanProcessors_multipleExportersWithLogging() { "logging", LoggingSpanExporter.create(), "zipkin", - io.opentelemetry.exporter.zipkin.ZipkinSpanExporter.builder().build()), + ZipkinSpanExporter.builder().build()), InternalTelemetryVersion.LEGACY, MeterProvider.noop(), closeables); diff --git a/sdk-extensions/autoconfigure/src/testFullConfig/java/io/opentelemetry/sdk/autoconfigure/FullConfigTest.java b/sdk-extensions/autoconfigure/src/testFullConfig/java/io/opentelemetry/sdk/autoconfigure/FullConfigTest.java index 8514a7b43d4..dae6767299d 100644 --- a/sdk-extensions/autoconfigure/src/testFullConfig/java/io/opentelemetry/sdk/autoconfigure/FullConfigTest.java +++ b/sdk-extensions/autoconfigure/src/testFullConfig/java/io/opentelemetry/sdk/autoconfigure/FullConfigTest.java @@ -38,6 +38,7 @@ import io.opentelemetry.proto.common.v1.KeyValue; import io.opentelemetry.proto.metrics.v1.Metric; import io.opentelemetry.proto.metrics.v1.ScopeMetrics; +import io.opentelemetry.proto.trace.v1.Span; import io.opentelemetry.sdk.OpenTelemetrySdk; import java.util.ArrayList; import java.util.Collection; @@ -215,8 +216,7 @@ void configures() throws Exception { traceRequest.getResourceSpans(0).getResource().getAttributesList(); assertHasKeyValue(spanResourceAttributes, "service.name", "test"); assertHasKeyValue(spanResourceAttributes, "cat", "meow"); - io.opentelemetry.proto.trace.v1.Span span = - traceRequest.getResourceSpans(0).getScopeSpans(0).getSpans(0); + Span span = traceRequest.getResourceSpans(0).getScopeSpans(0).getSpans(0); assertHasKeyValue(span.getAttributesList(), "configured", true); assertHasKeyValue(span.getAttributesList(), "wrapped", 1); assertHasKeyValue(span.getAttributesList(), "cat", "meow"); diff --git a/sdk-extensions/autoconfigure/src/testFullConfig/java/io/opentelemetry/sdk/autoconfigure/provider/TestTracerProviderConfigurer.java b/sdk-extensions/autoconfigure/src/testFullConfig/java/io/opentelemetry/sdk/autoconfigure/provider/TestTracerProviderConfigurer.java index 31d5e8a2dd7..25cdbd51c33 100644 --- a/sdk-extensions/autoconfigure/src/testFullConfig/java/io/opentelemetry/sdk/autoconfigure/provider/TestTracerProviderConfigurer.java +++ b/sdk-extensions/autoconfigure/src/testFullConfig/java/io/opentelemetry/sdk/autoconfigure/provider/TestTracerProviderConfigurer.java @@ -6,12 +6,12 @@ package io.opentelemetry.sdk.autoconfigure.provider; import io.opentelemetry.sdk.autoconfigure.spi.ConfigProperties; +import io.opentelemetry.sdk.autoconfigure.spi.traces.SdkTracerProviderConfigurer; import io.opentelemetry.sdk.extension.incubator.trace.OnStartSpanProcessor; import io.opentelemetry.sdk.trace.SdkTracerProviderBuilder; @SuppressWarnings("deprecation") // Support testing of SdkTracerProviderConfigurer -public class TestTracerProviderConfigurer - implements io.opentelemetry.sdk.autoconfigure.spi.traces.SdkTracerProviderConfigurer { +public class TestTracerProviderConfigurer implements SdkTracerProviderConfigurer { @Override public void configure(SdkTracerProviderBuilder tracerProvider, ConfigProperties config) { tracerProvider.addSpanProcessor( diff --git a/sdk-extensions/incubator/src/test/java/io/opentelemetry/sdk/extension/incubator/fileconfig/AggregationFactoryTest.java b/sdk-extensions/incubator/src/test/java/io/opentelemetry/sdk/extension/incubator/fileconfig/AggregationFactoryTest.java index 92b355765f3..8cf4ccc6187 100644 --- a/sdk-extensions/incubator/src/test/java/io/opentelemetry/sdk/extension/incubator/fileconfig/AggregationFactoryTest.java +++ b/sdk-extensions/incubator/src/test/java/io/opentelemetry/sdk/extension/incubator/fileconfig/AggregationFactoryTest.java @@ -14,6 +14,7 @@ import io.opentelemetry.sdk.extension.incubator.fileconfig.internal.model.ExplicitBucketHistogramAggregationModel; import io.opentelemetry.sdk.extension.incubator.fileconfig.internal.model.LastValueAggregationModel; import io.opentelemetry.sdk.extension.incubator.fileconfig.internal.model.SumAggregationModel; +import io.opentelemetry.sdk.metrics.Aggregation; import java.util.Arrays; import java.util.stream.Stream; import org.junit.jupiter.params.ParameterizedTest; @@ -24,48 +25,43 @@ class AggregationFactoryTest { @ParameterizedTest @MethodSource("createTestCases") - void create(AggregationModel model, io.opentelemetry.sdk.metrics.Aggregation expectedResult) { - io.opentelemetry.sdk.metrics.Aggregation aggregation = + void create(AggregationModel model, Aggregation expectedResult) { + Aggregation aggregation = AggregationFactory.getInstance().create(model, mock(DeclarativeConfigContext.class)); assertThat(aggregation.toString()).isEqualTo(expectedResult.toString()); } private static Stream createTestCases() { return Stream.of( + Arguments.of(new AggregationModel(), Aggregation.defaultAggregation()), Arguments.of( - new AggregationModel(), io.opentelemetry.sdk.metrics.Aggregation.defaultAggregation()), - Arguments.of( - new AggregationModel().withDrop(new DropAggregationModel()), - io.opentelemetry.sdk.metrics.Aggregation.drop()), - Arguments.of( - new AggregationModel().withSum(new SumAggregationModel()), - io.opentelemetry.sdk.metrics.Aggregation.sum()), + new AggregationModel().withDrop(new DropAggregationModel()), Aggregation.drop()), + Arguments.of(new AggregationModel().withSum(new SumAggregationModel()), Aggregation.sum()), Arguments.of( new AggregationModel().withLastValue(new LastValueAggregationModel()), - io.opentelemetry.sdk.metrics.Aggregation.lastValue()), + Aggregation.lastValue()), Arguments.of( new AggregationModel() .withBase2ExponentialBucketHistogram( new Base2ExponentialBucketHistogramAggregationModel()), - io.opentelemetry.sdk.metrics.Aggregation.base2ExponentialBucketHistogram()), + Aggregation.base2ExponentialBucketHistogram()), Arguments.of( new AggregationModel() .withBase2ExponentialBucketHistogram( new Base2ExponentialBucketHistogramAggregationModel() .withMaxSize(2) .withMaxScale(2)), - io.opentelemetry.sdk.metrics.Aggregation.base2ExponentialBucketHistogram(2, 2)), + Aggregation.base2ExponentialBucketHistogram(2, 2)), Arguments.of( new AggregationModel() .withExplicitBucketHistogram( new ExplicitBucketHistogramAggregationModel().withBoundaries(null)), - io.opentelemetry.sdk.metrics.Aggregation.explicitBucketHistogram()), + Aggregation.explicitBucketHistogram()), Arguments.of( new AggregationModel() .withExplicitBucketHistogram( new ExplicitBucketHistogramAggregationModel() .withBoundaries(Arrays.asList(1.0, 2.0))), - io.opentelemetry.sdk.metrics.Aggregation.explicitBucketHistogram( - Arrays.asList(1.0, 2.0)))); + Aggregation.explicitBucketHistogram(Arrays.asList(1.0, 2.0)))); } } diff --git a/sdk-extensions/incubator/src/test/java/io/opentelemetry/sdk/extension/incubator/fileconfig/DeclarativeConfigurationParseTest.java b/sdk-extensions/incubator/src/test/java/io/opentelemetry/sdk/extension/incubator/fileconfig/DeclarativeConfigurationParseTest.java index ffc1322bcb1..de3818d95cc 100644 --- a/sdk-extensions/incubator/src/test/java/io/opentelemetry/sdk/extension/incubator/fileconfig/DeclarativeConfigurationParseTest.java +++ b/sdk-extensions/incubator/src/test/java/io/opentelemetry/sdk/extension/incubator/fileconfig/DeclarativeConfigurationParseTest.java @@ -111,6 +111,7 @@ import java.util.Collections; import java.util.HashMap; import java.util.Map; +import java.util.stream.Stream; import javax.annotation.Nullable; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Test; @@ -1004,8 +1005,8 @@ void coreSchemaValues(String rawYaml, Object expectedYamlResult) { } @SuppressWarnings("unchecked") - private static java.util.stream.Stream coreSchemaValuesArgs() { - return java.util.stream.Stream.of( + private static Stream coreSchemaValuesArgs() { + return Stream.of( Arguments.of("key1: 0o123\n", mapOf(entry("key1", 83))), Arguments.of("key1: 0123\n", mapOf(entry("key1", 123))), Arguments.of("key1: 0xdeadbeef\n", mapOf(entry("key1", 3735928559L))), @@ -1034,8 +1035,8 @@ void envSubstituteAndLoadYaml(String rawYaml, Object expectedYamlResult) { } @SuppressWarnings("unchecked") - private static java.util.stream.Stream envVarSubstitutionArgs() { - return java.util.stream.Stream.of( + private static Stream envVarSubstitutionArgs() { + return Stream.of( // Simple cases Arguments.of("key1: ${STR_1}\n", mapOf(entry("key1", "value1"))), Arguments.of("key1: ${BOOL}\n", mapOf(entry("key1", true))), diff --git a/sdk-extensions/incubator/src/test/java/io/opentelemetry/sdk/extension/incubator/fileconfig/LogRecordProcessorFactoryTest.java b/sdk-extensions/incubator/src/test/java/io/opentelemetry/sdk/extension/incubator/fileconfig/LogRecordProcessorFactoryTest.java index 7d60aaf02f6..110f31b5aa8 100644 --- a/sdk-extensions/incubator/src/test/java/io/opentelemetry/sdk/extension/incubator/fileconfig/LogRecordProcessorFactoryTest.java +++ b/sdk-extensions/incubator/src/test/java/io/opentelemetry/sdk/extension/incubator/fileconfig/LogRecordProcessorFactoryTest.java @@ -19,6 +19,9 @@ import io.opentelemetry.sdk.extension.incubator.fileconfig.internal.model.LogRecordProcessorPropertyModel; import io.opentelemetry.sdk.extension.incubator.fileconfig.internal.model.OtlpHttpExporterModel; import io.opentelemetry.sdk.extension.incubator.fileconfig.internal.model.SimpleLogRecordProcessorModel; +import io.opentelemetry.sdk.logs.LogRecordProcessor; +import io.opentelemetry.sdk.logs.export.BatchLogRecordProcessor; +import io.opentelemetry.sdk.logs.export.SimpleLogRecordProcessor; import java.io.Closeable; import java.time.Duration; import java.util.ArrayList; @@ -50,13 +53,11 @@ void create_BatchNullExporter() { @Test void create_BatchDefaults() { List closeables = new ArrayList<>(); - io.opentelemetry.sdk.logs.export.BatchLogRecordProcessor expectedProcessor = - io.opentelemetry.sdk.logs.export.BatchLogRecordProcessor.builder( - OtlpHttpLogRecordExporter.getDefault()) - .build(); + BatchLogRecordProcessor expectedProcessor = + BatchLogRecordProcessor.builder(OtlpHttpLogRecordExporter.getDefault()).build(); cleanup.addCloseable(expectedProcessor); - io.opentelemetry.sdk.logs.LogRecordProcessor processor = + LogRecordProcessor processor = LogRecordProcessorFactory.getInstance() .create( new LogRecordProcessorModel() @@ -75,16 +76,15 @@ void create_BatchDefaults() { @Test void create_BatchConfigured() { List closeables = new ArrayList<>(); - io.opentelemetry.sdk.logs.export.BatchLogRecordProcessor expectedProcessor = - io.opentelemetry.sdk.logs.export.BatchLogRecordProcessor.builder( - OtlpHttpLogRecordExporter.getDefault()) + BatchLogRecordProcessor expectedProcessor = + BatchLogRecordProcessor.builder(OtlpHttpLogRecordExporter.getDefault()) .setScheduleDelay(Duration.ofMillis(1)) .setMaxExportBatchSize(2) .setExporterTimeout(Duration.ofMillis(3)) .build(); cleanup.addCloseable(expectedProcessor); - io.opentelemetry.sdk.logs.LogRecordProcessor processor = + LogRecordProcessor processor = LogRecordProcessorFactory.getInstance() .create( new LogRecordProcessorModel() @@ -119,12 +119,11 @@ void create_SimpleNullExporter() { @Test void create_SimpleConfigured() { List closeables = new ArrayList<>(); - io.opentelemetry.sdk.logs.LogRecordProcessor expectedProcessor = - io.opentelemetry.sdk.logs.export.SimpleLogRecordProcessor.create( - OtlpHttpLogRecordExporter.getDefault()); + LogRecordProcessor expectedProcessor = + SimpleLogRecordProcessor.create(OtlpHttpLogRecordExporter.getDefault()); cleanup.addCloseable(expectedProcessor); - io.opentelemetry.sdk.logs.LogRecordProcessor processor = + LogRecordProcessor processor = LogRecordProcessorFactory.getInstance() .create( new LogRecordProcessorModel() @@ -159,7 +158,7 @@ void create_SpiProcessor_Unknown() { @Test void create_SpiExporter_Valid() { - io.opentelemetry.sdk.logs.LogRecordProcessor logRecordProcessor = + LogRecordProcessor logRecordProcessor = LogRecordProcessorFactory.getInstance() .create( new LogRecordProcessorModel() diff --git a/sdk-extensions/incubator/src/test/java/io/opentelemetry/sdk/extension/incubator/fileconfig/LoggerProviderFactoryTest.java b/sdk-extensions/incubator/src/test/java/io/opentelemetry/sdk/extension/incubator/fileconfig/LoggerProviderFactoryTest.java index 207c7e652d1..d1d5e01f286 100644 --- a/sdk-extensions/incubator/src/test/java/io/opentelemetry/sdk/extension/incubator/fileconfig/LoggerProviderFactoryTest.java +++ b/sdk-extensions/incubator/src/test/java/io/opentelemetry/sdk/extension/incubator/fileconfig/LoggerProviderFactoryTest.java @@ -27,6 +27,7 @@ import io.opentelemetry.sdk.extension.incubator.fileconfig.internal.model.OtlpHttpExporterModel; import io.opentelemetry.sdk.logs.LogLimits; import io.opentelemetry.sdk.logs.SdkLoggerProvider; +import io.opentelemetry.sdk.logs.export.BatchLogRecordProcessor; import io.opentelemetry.sdk.logs.internal.LoggerConfig; import java.io.Closeable; import java.util.ArrayList; @@ -116,9 +117,7 @@ private static Stream createArguments() { .setMaxAttributeValueLength(2) .build()) .addLogRecordProcessor( - io.opentelemetry.sdk.logs.export.BatchLogRecordProcessor.builder( - OtlpHttpLogRecordExporter.getDefault()) - .build()) + BatchLogRecordProcessor.builder(OtlpHttpLogRecordExporter.getDefault()).build()) .build())); } diff --git a/sdk-extensions/incubator/src/test/java/io/opentelemetry/sdk/extension/incubator/fileconfig/MetricExporterFactoryTest.java b/sdk-extensions/incubator/src/test/java/io/opentelemetry/sdk/extension/incubator/fileconfig/MetricExporterFactoryTest.java index 14912dfb557..884efd83c2a 100644 --- a/sdk-extensions/incubator/src/test/java/io/opentelemetry/sdk/extension/incubator/fileconfig/MetricExporterFactoryTest.java +++ b/sdk-extensions/incubator/src/test/java/io/opentelemetry/sdk/extension/incubator/fileconfig/MetricExporterFactoryTest.java @@ -324,7 +324,7 @@ void create_Console() { LoggingMetricExporter expectedExporter = LoggingMetricExporter.create(); cleanup.addCloseable(expectedExporter); - io.opentelemetry.sdk.metrics.export.MetricExporter exporter = + MetricExporter exporter = MetricExporterFactory.getInstance() .create( new PushMetricExporterModel().withConsole(new ConsoleMetricExporterModel()), diff --git a/sdk-extensions/incubator/src/test/java/io/opentelemetry/sdk/extension/incubator/fileconfig/MetricReaderFactoryTest.java b/sdk-extensions/incubator/src/test/java/io/opentelemetry/sdk/extension/incubator/fileconfig/MetricReaderFactoryTest.java index bfe0b6a6209..3ecdc64a711 100644 --- a/sdk-extensions/incubator/src/test/java/io/opentelemetry/sdk/extension/incubator/fileconfig/MetricReaderFactoryTest.java +++ b/sdk-extensions/incubator/src/test/java/io/opentelemetry/sdk/extension/incubator/fileconfig/MetricReaderFactoryTest.java @@ -31,6 +31,7 @@ import io.opentelemetry.sdk.extension.incubator.fileconfig.internal.model.PushMetricExporterModel; import io.opentelemetry.sdk.metrics.InstrumentType; import io.opentelemetry.sdk.metrics.export.MetricReader; +import io.opentelemetry.sdk.metrics.export.PeriodicMetricReader; import java.io.Closeable; import java.io.IOException; import java.net.ServerSocket; @@ -68,10 +69,8 @@ void create_PeriodicNullExporter() { @Test void create_PeriodicDefaults() { List closeables = new ArrayList<>(); - io.opentelemetry.sdk.metrics.export.PeriodicMetricReader expectedReader = - io.opentelemetry.sdk.metrics.export.PeriodicMetricReader.builder( - OtlpHttpMetricExporter.getDefault()) - .build(); + PeriodicMetricReader expectedReader = + PeriodicMetricReader.builder(OtlpHttpMetricExporter.getDefault()).build(); cleanup.addCloseable(expectedReader); MetricReaderAndCardinalityLimits readerAndCardinalityLimits = @@ -96,8 +95,7 @@ void create_PeriodicDefaults() { void create_PeriodicConfigured() { List closeables = new ArrayList<>(); MetricReader expectedReader = - io.opentelemetry.sdk.metrics.export.PeriodicMetricReader.builder( - OtlpHttpMetricExporter.getDefault()) + PeriodicMetricReader.builder(OtlpHttpMetricExporter.getDefault()) .setInterval(Duration.ofMillis(1)) .build(); cleanup.addCloseable(expectedReader); diff --git a/sdk-extensions/incubator/src/test/java/io/opentelemetry/sdk/extension/incubator/fileconfig/OpenTelemetryConfigurationFactoryTest.java b/sdk-extensions/incubator/src/test/java/io/opentelemetry/sdk/extension/incubator/fileconfig/OpenTelemetryConfigurationFactoryTest.java index 6366ff9cf14..1d8ed0d3eab 100644 --- a/sdk-extensions/incubator/src/test/java/io/opentelemetry/sdk/extension/incubator/fileconfig/OpenTelemetryConfigurationFactoryTest.java +++ b/sdk-extensions/incubator/src/test/java/io/opentelemetry/sdk/extension/incubator/fileconfig/OpenTelemetryConfigurationFactoryTest.java @@ -56,11 +56,15 @@ import io.opentelemetry.sdk.internal.SdkConfigProvider; import io.opentelemetry.sdk.logs.LogLimits; import io.opentelemetry.sdk.logs.SdkLoggerProvider; +import io.opentelemetry.sdk.logs.export.BatchLogRecordProcessor; import io.opentelemetry.sdk.metrics.InstrumentSelector; import io.opentelemetry.sdk.metrics.SdkMeterProvider; import io.opentelemetry.sdk.metrics.View; +import io.opentelemetry.sdk.metrics.export.PeriodicMetricReader; +import io.opentelemetry.sdk.resources.Resource; import io.opentelemetry.sdk.trace.SdkTracerProvider; import io.opentelemetry.sdk.trace.SpanLimits; +import io.opentelemetry.sdk.trace.export.BatchSpanProcessor; import java.io.Closeable; import java.lang.reflect.Field; import java.util.ArrayList; @@ -207,8 +211,8 @@ void create_Disabled() { @Test void create_Configured() throws NoSuchFieldException { List closeables = new ArrayList<>(); - io.opentelemetry.sdk.resources.Resource expectedResource = - io.opentelemetry.sdk.resources.Resource.getDefault().toBuilder() + Resource expectedResource = + Resource.getDefault().toBuilder() .put("service.name", "my-service") .put("key", "val") // resource attributes from resource ComponentProviders @@ -313,7 +317,7 @@ void create_Configured() throws NoSuchFieldException { .setMaxNumberOfAttributes(2) .build()) .addLogRecordProcessor( - io.opentelemetry.sdk.logs.export.BatchLogRecordProcessor.builder( + BatchLogRecordProcessor.builder( OtlpHttpLogRecordExporter.getDefault()) .build()) .build()) @@ -331,16 +335,14 @@ void create_Configured() throws NoSuchFieldException { .build()) .setSampler(alwaysOn()) .addSpanProcessor( - io.opentelemetry.sdk.trace.export.BatchSpanProcessor.builder( - OtlpHttpSpanExporter.getDefault()) + BatchSpanProcessor.builder(OtlpHttpSpanExporter.getDefault()) .build()) .build()) .setMeterProvider( SdkMeterProvider.builder() .setResource(expectedResource) .registerMetricReader( - io.opentelemetry.sdk.metrics.export.PeriodicMetricReader.builder( - OtlpHttpMetricExporter.getDefault()) + PeriodicMetricReader.builder(OtlpHttpMetricExporter.getDefault()) .build()) .registerView( InstrumentSelector.builder().setName("instrument-name").build(), diff --git a/sdk-extensions/incubator/src/test/java/io/opentelemetry/sdk/extension/incubator/fileconfig/SpanProcessorFactoryTest.java b/sdk-extensions/incubator/src/test/java/io/opentelemetry/sdk/extension/incubator/fileconfig/SpanProcessorFactoryTest.java index ffc0de8cb6e..ef41e271913 100644 --- a/sdk-extensions/incubator/src/test/java/io/opentelemetry/sdk/extension/incubator/fileconfig/SpanProcessorFactoryTest.java +++ b/sdk-extensions/incubator/src/test/java/io/opentelemetry/sdk/extension/incubator/fileconfig/SpanProcessorFactoryTest.java @@ -19,6 +19,9 @@ import io.opentelemetry.sdk.extension.incubator.fileconfig.internal.model.SpanExporterModel; import io.opentelemetry.sdk.extension.incubator.fileconfig.internal.model.SpanProcessorModel; import io.opentelemetry.sdk.extension.incubator.fileconfig.internal.model.SpanProcessorPropertyModel; +import io.opentelemetry.sdk.trace.SpanProcessor; +import io.opentelemetry.sdk.trace.export.BatchSpanProcessor; +import io.opentelemetry.sdk.trace.export.SimpleSpanProcessor; import java.io.Closeable; import java.time.Duration; import java.util.ArrayList; @@ -49,13 +52,11 @@ void create_BatchNullExporter() { @Test void create_BatchDefaults() { List closeables = new ArrayList<>(); - io.opentelemetry.sdk.trace.export.BatchSpanProcessor expectedProcessor = - io.opentelemetry.sdk.trace.export.BatchSpanProcessor.builder( - OtlpHttpSpanExporter.getDefault()) - .build(); + BatchSpanProcessor expectedProcessor = + BatchSpanProcessor.builder(OtlpHttpSpanExporter.getDefault()).build(); cleanup.addCloseable(expectedProcessor); - io.opentelemetry.sdk.trace.SpanProcessor processor = + SpanProcessor processor = SpanProcessorFactory.getInstance() .create( new SpanProcessorModel() @@ -73,16 +74,15 @@ void create_BatchDefaults() { @Test void create_BatchConfigured() { List closeables = new ArrayList<>(); - io.opentelemetry.sdk.trace.export.BatchSpanProcessor expectedProcessor = - io.opentelemetry.sdk.trace.export.BatchSpanProcessor.builder( - OtlpHttpSpanExporter.getDefault()) + BatchSpanProcessor expectedProcessor = + BatchSpanProcessor.builder(OtlpHttpSpanExporter.getDefault()) .setScheduleDelay(Duration.ofMillis(1)) .setMaxExportBatchSize(2) .setExporterTimeout(Duration.ofMillis(3)) .build(); cleanup.addCloseable(expectedProcessor); - io.opentelemetry.sdk.trace.SpanProcessor processor = + SpanProcessor processor = SpanProcessorFactory.getInstance() .create( new SpanProcessorModel() @@ -115,12 +115,10 @@ void create_SimpleNullExporter() { @Test void create_SimpleConfigured() { List closeables = new ArrayList<>(); - io.opentelemetry.sdk.trace.SpanProcessor expectedProcessor = - io.opentelemetry.sdk.trace.export.SimpleSpanProcessor.create( - OtlpHttpSpanExporter.getDefault()); + SpanProcessor expectedProcessor = SimpleSpanProcessor.create(OtlpHttpSpanExporter.getDefault()); cleanup.addCloseable(expectedProcessor); - io.opentelemetry.sdk.trace.SpanProcessor processor = + SpanProcessor processor = SpanProcessorFactory.getInstance() .create( new SpanProcessorModel() @@ -154,7 +152,7 @@ void create_SpiProcessor_Unknown() { @Test void create_SpiExporter_Valid() { - io.opentelemetry.sdk.trace.SpanProcessor spanProcessor = + SpanProcessor spanProcessor = SpanProcessorFactory.getInstance() .create( new SpanProcessorModel() diff --git a/sdk-extensions/incubator/src/test/java/io/opentelemetry/sdk/extension/incubator/fileconfig/TracerProviderFactoryTest.java b/sdk-extensions/incubator/src/test/java/io/opentelemetry/sdk/extension/incubator/fileconfig/TracerProviderFactoryTest.java index 4c785fd5cf7..53c00444c9b 100644 --- a/sdk-extensions/incubator/src/test/java/io/opentelemetry/sdk/extension/incubator/fileconfig/TracerProviderFactoryTest.java +++ b/sdk-extensions/incubator/src/test/java/io/opentelemetry/sdk/extension/incubator/fileconfig/TracerProviderFactoryTest.java @@ -28,6 +28,7 @@ import io.opentelemetry.sdk.trace.SdkTracerProvider; import io.opentelemetry.sdk.trace.SdkTracerProviderBuilder; import io.opentelemetry.sdk.trace.SpanLimits; +import io.opentelemetry.sdk.trace.export.BatchSpanProcessor; import io.opentelemetry.sdk.trace.internal.SdkTracerProviderUtil; import io.opentelemetry.sdk.trace.internal.TracerConfig; import java.io.Closeable; @@ -120,9 +121,7 @@ private static Stream createArguments() { .build()) .setSampler(alwaysOn()) .addSpanProcessor( - io.opentelemetry.sdk.trace.export.BatchSpanProcessor.builder( - OtlpHttpSpanExporter.getDefault()) - .build()) + BatchSpanProcessor.builder(OtlpHttpSpanExporter.getDefault()).build()) .build())); } diff --git a/sdk-extensions/incubator/src/test/java/io/opentelemetry/sdk/extension/incubator/fileconfig/ViewFactoryTest.java b/sdk-extensions/incubator/src/test/java/io/opentelemetry/sdk/extension/incubator/fileconfig/ViewFactoryTest.java index 76be6e49cef..0ce2834dbff 100644 --- a/sdk-extensions/incubator/src/test/java/io/opentelemetry/sdk/extension/incubator/fileconfig/ViewFactoryTest.java +++ b/sdk-extensions/incubator/src/test/java/io/opentelemetry/sdk/extension/incubator/fileconfig/ViewFactoryTest.java @@ -13,6 +13,7 @@ import io.opentelemetry.sdk.extension.incubator.fileconfig.internal.model.ExplicitBucketHistogramAggregationModel; import io.opentelemetry.sdk.extension.incubator.fileconfig.internal.model.IncludeExcludeModel; import io.opentelemetry.sdk.extension.incubator.fileconfig.internal.model.ViewStreamModel; +import io.opentelemetry.sdk.metrics.Aggregation; import io.opentelemetry.sdk.metrics.View; import java.util.Arrays; import java.util.Collections; @@ -42,9 +43,7 @@ void create() { .setAttributeFilter( IncludeExcludePredicate.createExactMatching( Arrays.asList("foo", "bar"), Collections.singletonList("baz"))) - .setAggregation( - io.opentelemetry.sdk.metrics.Aggregation.explicitBucketHistogram( - Arrays.asList(1.0, 2.0))) + .setAggregation(Aggregation.explicitBucketHistogram(Arrays.asList(1.0, 2.0))) .build(); View view = diff --git a/sdk/common/src/main/java/io/opentelemetry/sdk/common/internal/DynamicPrimitiveLongList.java b/sdk/common/src/main/java/io/opentelemetry/sdk/common/internal/DynamicPrimitiveLongList.java index 62e72595179..66f86c822a8 100644 --- a/sdk/common/src/main/java/io/opentelemetry/sdk/common/internal/DynamicPrimitiveLongList.java +++ b/sdk/common/src/main/java/io/opentelemetry/sdk/common/internal/DynamicPrimitiveLongList.java @@ -6,6 +6,7 @@ package io.opentelemetry.sdk.common.internal; import java.util.AbstractList; +import java.util.Arrays; /** * A resizable list for storing primitive `long` values. @@ -130,7 +131,7 @@ private void ensureCapacity(int minCapacity) { int requiredArrays = (minCapacity + subarrayCapacity - 1) / subarrayCapacity; if (requiredArrays > arrayCount) { - arrays = java.util.Arrays.copyOf(arrays, /* newLength= */ requiredArrays); + arrays = Arrays.copyOf(arrays, /* newLength= */ requiredArrays); for (int i = arrayCount; i < requiredArrays; i++) { arrays[i] = new long[subarrayCapacity]; } diff --git a/sdk/testing/src/main/java/io/opentelemetry/sdk/testing/assertj/SpanDataAssert.java b/sdk/testing/src/main/java/io/opentelemetry/sdk/testing/assertj/SpanDataAssert.java index 9559e0e2927..387229fd091 100644 --- a/sdk/testing/src/main/java/io/opentelemetry/sdk/testing/assertj/SpanDataAssert.java +++ b/sdk/testing/src/main/java/io/opentelemetry/sdk/testing/assertj/SpanDataAssert.java @@ -13,6 +13,7 @@ import io.opentelemetry.api.trace.SpanId; import io.opentelemetry.api.trace.SpanKind; import io.opentelemetry.api.trace.TraceState; +import io.opentelemetry.sdk.common.InstrumentationLibraryInfo; import io.opentelemetry.sdk.common.InstrumentationScopeInfo; import io.opentelemetry.sdk.resources.Resource; import io.opentelemetry.sdk.trace.data.EventData; @@ -185,7 +186,7 @@ public SpanDataAssert hasResourceSatisfying(Consumer resource) { */ @Deprecated public SpanDataAssert hasInstrumentationLibraryInfo( - io.opentelemetry.sdk.common.InstrumentationLibraryInfo instrumentationLibraryInfo) { + InstrumentationLibraryInfo instrumentationLibraryInfo) { isNotNull(); if (!actual.getInstrumentationLibraryInfo().equals(instrumentationLibraryInfo)) { failWithActualExpectedAndMessage( diff --git a/sdk/testing/src/main/java/io/opentelemetry/sdk/testing/trace/TestSpanData.java b/sdk/testing/src/main/java/io/opentelemetry/sdk/testing/trace/TestSpanData.java index a141ec1d395..1743c46a3f5 100644 --- a/sdk/testing/src/main/java/io/opentelemetry/sdk/testing/trace/TestSpanData.java +++ b/sdk/testing/src/main/java/io/opentelemetry/sdk/testing/trace/TestSpanData.java @@ -9,6 +9,7 @@ import io.opentelemetry.api.common.Attributes; import io.opentelemetry.api.trace.SpanContext; import io.opentelemetry.api.trace.SpanKind; +import io.opentelemetry.sdk.common.InstrumentationLibraryInfo; import io.opentelemetry.sdk.common.InstrumentationScopeInfo; import io.opentelemetry.sdk.common.internal.InstrumentationScopeUtil; import io.opentelemetry.sdk.resources.Resource; @@ -59,7 +60,7 @@ public final boolean hasEnded() { @Override @Deprecated - public io.opentelemetry.sdk.common.InstrumentationLibraryInfo getInstrumentationLibraryInfo() { + public InstrumentationLibraryInfo getInstrumentationLibraryInfo() { return InstrumentationScopeUtil.toInstrumentationLibraryInfo(getInstrumentationScopeInfo()); } @@ -122,7 +123,7 @@ public TestSpanData build() { */ @Deprecated public Builder setInstrumentationLibraryInfo( - io.opentelemetry.sdk.common.InstrumentationLibraryInfo instrumentationLibraryInfo) { + InstrumentationLibraryInfo instrumentationLibraryInfo) { return setInstrumentationScopeInfo( InstrumentationScopeUtil.toInstrumentationScopeInfo(instrumentationLibraryInfo)); } diff --git a/sdk/trace/src/main/java/io/opentelemetry/sdk/trace/ReadableSpan.java b/sdk/trace/src/main/java/io/opentelemetry/sdk/trace/ReadableSpan.java index f4eafb3c6cd..bb31fc8017b 100644 --- a/sdk/trace/src/main/java/io/opentelemetry/sdk/trace/ReadableSpan.java +++ b/sdk/trace/src/main/java/io/opentelemetry/sdk/trace/ReadableSpan.java @@ -10,6 +10,7 @@ import io.opentelemetry.api.trace.Span; import io.opentelemetry.api.trace.SpanContext; import io.opentelemetry.api.trace.SpanKind; +import io.opentelemetry.sdk.common.InstrumentationLibraryInfo; import io.opentelemetry.sdk.common.InstrumentationScopeInfo; import io.opentelemetry.sdk.common.internal.InstrumentationScopeUtil; import io.opentelemetry.sdk.trace.data.SpanData; @@ -63,7 +64,7 @@ public interface ReadableSpan { * @deprecated Use {@link #getInstrumentationScopeInfo()}. */ @Deprecated - io.opentelemetry.sdk.common.InstrumentationLibraryInfo getInstrumentationLibraryInfo(); + InstrumentationLibraryInfo getInstrumentationLibraryInfo(); /** * Returns the instrumentation scope specified when creating the tracer which produced this span. diff --git a/sdk/trace/src/main/java/io/opentelemetry/sdk/trace/SdkSpan.java b/sdk/trace/src/main/java/io/opentelemetry/sdk/trace/SdkSpan.java index 22f3206a097..e3381b06a3d 100644 --- a/sdk/trace/src/main/java/io/opentelemetry/sdk/trace/SdkSpan.java +++ b/sdk/trace/src/main/java/io/opentelemetry/sdk/trace/SdkSpan.java @@ -14,6 +14,7 @@ import io.opentelemetry.api.trace.StatusCode; import io.opentelemetry.context.Context; import io.opentelemetry.sdk.common.Clock; +import io.opentelemetry.sdk.common.InstrumentationLibraryInfo; import io.opentelemetry.sdk.common.InstrumentationScopeInfo; import io.opentelemetry.sdk.common.internal.AttributeUtil; import io.opentelemetry.sdk.common.internal.AttributesMap; @@ -301,7 +302,7 @@ public String getName() { @Override @Deprecated - public io.opentelemetry.sdk.common.InstrumentationLibraryInfo getInstrumentationLibraryInfo() { + public InstrumentationLibraryInfo getInstrumentationLibraryInfo() { return InstrumentationScopeUtil.toInstrumentationLibraryInfo(getInstrumentationScopeInfo()); } diff --git a/sdk/trace/src/main/java/io/opentelemetry/sdk/trace/SpanWrapper.java b/sdk/trace/src/main/java/io/opentelemetry/sdk/trace/SpanWrapper.java index f285427f0e8..651e07d1127 100644 --- a/sdk/trace/src/main/java/io/opentelemetry/sdk/trace/SpanWrapper.java +++ b/sdk/trace/src/main/java/io/opentelemetry/sdk/trace/SpanWrapper.java @@ -9,6 +9,7 @@ import io.opentelemetry.api.common.Attributes; import io.opentelemetry.api.trace.SpanContext; import io.opentelemetry.api.trace.SpanKind; +import io.opentelemetry.sdk.common.InstrumentationLibraryInfo; import io.opentelemetry.sdk.common.InstrumentationScopeInfo; import io.opentelemetry.sdk.common.internal.InstrumentationScopeUtil; import io.opentelemetry.sdk.resources.Resource; @@ -100,7 +101,7 @@ public Resource getResource() { @Override @Deprecated - public io.opentelemetry.sdk.common.InstrumentationLibraryInfo getInstrumentationLibraryInfo() { + public InstrumentationLibraryInfo getInstrumentationLibraryInfo() { return InstrumentationScopeUtil.toInstrumentationLibraryInfo( delegate().getInstrumentationScopeInfo()); } diff --git a/sdk/trace/src/main/java/io/opentelemetry/sdk/trace/data/DelegatingSpanData.java b/sdk/trace/src/main/java/io/opentelemetry/sdk/trace/data/DelegatingSpanData.java index 61195776db3..d443f85285a 100644 --- a/sdk/trace/src/main/java/io/opentelemetry/sdk/trace/data/DelegatingSpanData.java +++ b/sdk/trace/src/main/java/io/opentelemetry/sdk/trace/data/DelegatingSpanData.java @@ -10,6 +10,7 @@ import io.opentelemetry.api.common.Attributes; import io.opentelemetry.api.trace.SpanContext; import io.opentelemetry.api.trace.SpanKind; +import io.opentelemetry.sdk.common.InstrumentationLibraryInfo; import io.opentelemetry.sdk.common.InstrumentationScopeInfo; import io.opentelemetry.sdk.resources.Resource; import java.util.List; @@ -67,7 +68,7 @@ public Resource getResource() { @Override @Deprecated - public io.opentelemetry.sdk.common.InstrumentationLibraryInfo getInstrumentationLibraryInfo() { + public InstrumentationLibraryInfo getInstrumentationLibraryInfo() { return delegate.getInstrumentationLibraryInfo(); } diff --git a/sdk/trace/src/main/java/io/opentelemetry/sdk/trace/data/SpanData.java b/sdk/trace/src/main/java/io/opentelemetry/sdk/trace/data/SpanData.java index 87abccf1b19..f3dda48d31f 100644 --- a/sdk/trace/src/main/java/io/opentelemetry/sdk/trace/data/SpanData.java +++ b/sdk/trace/src/main/java/io/opentelemetry/sdk/trace/data/SpanData.java @@ -8,6 +8,7 @@ import io.opentelemetry.api.common.Attributes; import io.opentelemetry.api.trace.SpanContext; import io.opentelemetry.api.trace.SpanKind; +import io.opentelemetry.sdk.common.InstrumentationLibraryInfo; import io.opentelemetry.sdk.common.InstrumentationScopeInfo; import io.opentelemetry.sdk.common.internal.InstrumentationScopeUtil; import io.opentelemetry.sdk.resources.Resource; @@ -158,7 +159,7 @@ default String getParentSpanId() { * @deprecated Use {@link #getInstrumentationScopeInfo()}. */ @Deprecated - io.opentelemetry.sdk.common.InstrumentationLibraryInfo getInstrumentationLibraryInfo(); + InstrumentationLibraryInfo getInstrumentationLibraryInfo(); /** * Returns the instrumentation scope specified when creating the tracer which produced this {@code From ff289d53a0d620ee23af73eeeabdbaf5ac2a5da0 Mon Sep 17 00:00:00 2001 From: Trask Stalnaker Date: Sat, 7 Feb 2026 09:52:54 -0800 Subject: [PATCH 2/3] Deprecate ExtendedAttributes, ExtendedAttributeKey, ExtendedAttributeType, ExtendedAttributesBuilder --- .../common/ArrayBackedExtendedAttributes.java | 1 + .../ArrayBackedExtendedAttributesBuilder.java | 26 +-- .../common/ExtendedAttributeKey.java | 2 + .../common/ExtendedAttributeType.java | 3 + .../incubator/common/ExtendedAttributes.java | 4 + .../common/ExtendedAttributesBuilder.java | 39 ++-- .../InternalExtendedAttributeKeyImpl.java | 66 +++--- .../incubator/logs/ExtendedDefaultLogger.java | 5 +- .../logs/ExtendedLogRecordBuilder.java | 46 +++-- .../common/ExtendedAttributesTest.java | 195 ++++++++++-------- .../logs/ExtendedLogsBridgeApiUsageTest.java | 17 +- ...edAttributeKeyValueStatelessMarshaler.java | 59 +++--- .../internal/otlp/IncubatingUtil.java | 23 ++- .../LogsRequestMarshalerIncubatingTest.java | 12 +- .../internal/ExtendedAttributesMap.java | 35 ++-- .../internal/ExtendedAttributesValueTest.java | 18 +- sdk/logs/build.gradle.kts | 6 + .../sdk/logs/ExtendedSdkLogRecordBuilder.java | 8 +- .../sdk/logs/ExtendedSdkLogRecordData.java | 4 +- .../logs/ExtendedSdkReadWriteLogRecord.java | 21 +- .../data/internal/ExtendedLogRecordData.java | 9 +- .../internal/ExtendedReadWriteLogRecord.java | 22 +- sdk/testing/build.gradle.kts | 9 + .../internal/TestExtendedLogRecordData.java | 9 +- 24 files changed, 377 insertions(+), 262 deletions(-) diff --git a/api/incubator/src/main/java/io/opentelemetry/api/incubator/common/ArrayBackedExtendedAttributes.java b/api/incubator/src/main/java/io/opentelemetry/api/incubator/common/ArrayBackedExtendedAttributes.java index 761748ce206..6390138ce28 100644 --- a/api/incubator/src/main/java/io/opentelemetry/api/incubator/common/ArrayBackedExtendedAttributes.java +++ b/api/incubator/src/main/java/io/opentelemetry/api/incubator/common/ArrayBackedExtendedAttributes.java @@ -18,6 +18,7 @@ import javax.annotation.Nullable; import javax.annotation.concurrent.Immutable; +@SuppressWarnings("deprecation") @Immutable final class ArrayBackedExtendedAttributes extends ImmutableKeyValuePairs, Object> implements ExtendedAttributes { diff --git a/api/incubator/src/main/java/io/opentelemetry/api/incubator/common/ArrayBackedExtendedAttributesBuilder.java b/api/incubator/src/main/java/io/opentelemetry/api/incubator/common/ArrayBackedExtendedAttributesBuilder.java index cbdac5429ef..22c6ffc6870 100644 --- a/api/incubator/src/main/java/io/opentelemetry/api/incubator/common/ArrayBackedExtendedAttributesBuilder.java +++ b/api/incubator/src/main/java/io/opentelemetry/api/incubator/common/ArrayBackedExtendedAttributesBuilder.java @@ -5,15 +5,6 @@ package io.opentelemetry.api.incubator.common; -import static io.opentelemetry.api.incubator.common.ExtendedAttributeKey.booleanArrayKey; -import static io.opentelemetry.api.incubator.common.ExtendedAttributeKey.booleanKey; -import static io.opentelemetry.api.incubator.common.ExtendedAttributeKey.doubleArrayKey; -import static io.opentelemetry.api.incubator.common.ExtendedAttributeKey.doubleKey; -import static io.opentelemetry.api.incubator.common.ExtendedAttributeKey.longArrayKey; -import static io.opentelemetry.api.incubator.common.ExtendedAttributeKey.longKey; -import static io.opentelemetry.api.incubator.common.ExtendedAttributeKey.stringArrayKey; -import static io.opentelemetry.api.incubator.common.ExtendedAttributeKey.stringKey; - import io.opentelemetry.api.common.Value; import io.opentelemetry.api.common.ValueType; import java.util.ArrayList; @@ -21,6 +12,7 @@ import java.util.List; import java.util.function.Predicate; +@SuppressWarnings("deprecation") class ArrayBackedExtendedAttributesBuilder implements ExtendedAttributesBuilder { private final List data; @@ -62,16 +54,16 @@ private void putValue(ExtendedAttributeKey key, Value valueObj) { String keyName = key.getKey(); switch (valueObj.getType()) { case STRING: - put(stringKey(keyName), ((Value) valueObj).getValue()); + put(ExtendedAttributeKey.stringKey(keyName), ((Value) valueObj).getValue()); return; case LONG: - put(longKey(keyName), ((Value) valueObj).getValue()); + put(ExtendedAttributeKey.longKey(keyName), ((Value) valueObj).getValue()); return; case DOUBLE: - put(doubleKey(keyName), ((Value) valueObj).getValue()); + put(ExtendedAttributeKey.doubleKey(keyName), ((Value) valueObj).getValue()); return; case BOOLEAN: - put(booleanKey(keyName), ((Value) valueObj).getValue()); + put(ExtendedAttributeKey.booleanKey(keyName), ((Value) valueObj).getValue()); return; case ARRAY: List> arrayValues = (List>) valueObj.getValue(); @@ -82,28 +74,28 @@ private void putValue(ExtendedAttributeKey key, Value valueObj) { for (Value v : arrayValues) { strings.add((String) v.getValue()); } - put(stringArrayKey(keyName), strings); + put(ExtendedAttributeKey.stringArrayKey(keyName), strings); return; case LONG_ARRAY: List longs = new ArrayList<>(arrayValues.size()); for (Value v : arrayValues) { longs.add((Long) v.getValue()); } - put(longArrayKey(keyName), longs); + put(ExtendedAttributeKey.longArrayKey(keyName), longs); return; case DOUBLE_ARRAY: List doubles = new ArrayList<>(arrayValues.size()); for (Value v : arrayValues) { doubles.add((Double) v.getValue()); } - put(doubleArrayKey(keyName), doubles); + put(ExtendedAttributeKey.doubleArrayKey(keyName), doubles); return; case BOOLEAN_ARRAY: List booleans = new ArrayList<>(arrayValues.size()); for (Value v : arrayValues) { booleans.add((Boolean) v.getValue()); } - put(booleanArrayKey(keyName), booleans); + put(ExtendedAttributeKey.booleanArrayKey(keyName), booleans); return; case VALUE: // Not coercible (empty, non-homogeneous, or unsupported element type) diff --git a/api/incubator/src/main/java/io/opentelemetry/api/incubator/common/ExtendedAttributeKey.java b/api/incubator/src/main/java/io/opentelemetry/api/incubator/common/ExtendedAttributeKey.java index 4f48dbd8973..89a90efe8c6 100644 --- a/api/incubator/src/main/java/io/opentelemetry/api/incubator/common/ExtendedAttributeKey.java +++ b/api/incubator/src/main/java/io/opentelemetry/api/incubator/common/ExtendedAttributeKey.java @@ -30,7 +30,9 @@ * * * @param The type of value that can be set with the key. + * @deprecated Use {@link AttributeKey} with {@link AttributeKey#valueKey(String)} instead. */ +@Deprecated @Immutable public interface ExtendedAttributeKey { /** Returns the underlying String representation of the key. */ diff --git a/api/incubator/src/main/java/io/opentelemetry/api/incubator/common/ExtendedAttributeType.java b/api/incubator/src/main/java/io/opentelemetry/api/incubator/common/ExtendedAttributeType.java index 26e655e9ab2..e032e659a31 100644 --- a/api/incubator/src/main/java/io/opentelemetry/api/incubator/common/ExtendedAttributeType.java +++ b/api/incubator/src/main/java/io/opentelemetry/api/incubator/common/ExtendedAttributeType.java @@ -10,7 +10,10 @@ * hence the types of values that are allowed for {@link ExtendedAttributes}. * *

This is a superset of {@link io.opentelemetry.api.common.AttributeType}, + * + * @deprecated Use {@link io.opentelemetry.api.common.AttributeType} instead. */ +@Deprecated public enum ExtendedAttributeType { // Types copied AttributeType STRING, diff --git a/api/incubator/src/main/java/io/opentelemetry/api/incubator/common/ExtendedAttributes.java b/api/incubator/src/main/java/io/opentelemetry/api/incubator/common/ExtendedAttributes.java index 14a16778d3d..5fe75be4cb5 100644 --- a/api/incubator/src/main/java/io/opentelemetry/api/incubator/common/ExtendedAttributes.java +++ b/api/incubator/src/main/java/io/opentelemetry/api/incubator/common/ExtendedAttributes.java @@ -47,7 +47,11 @@ * {@link ExtendedAttributes} *

  • {@link #get(AttributeKey)} supports reading values using standard {@link AttributeKey} * + * + * @deprecated Use {@link Attributes} with {@link + * io.opentelemetry.api.common.AttributeKey#valueKey(String)} instead. */ +@Deprecated @Immutable public interface ExtendedAttributes { diff --git a/api/incubator/src/main/java/io/opentelemetry/api/incubator/common/ExtendedAttributesBuilder.java b/api/incubator/src/main/java/io/opentelemetry/api/incubator/common/ExtendedAttributesBuilder.java index 0f4b9c942e2..a8f7fdf72a4 100644 --- a/api/incubator/src/main/java/io/opentelemetry/api/incubator/common/ExtendedAttributesBuilder.java +++ b/api/incubator/src/main/java/io/opentelemetry/api/incubator/common/ExtendedAttributesBuilder.java @@ -5,16 +5,6 @@ package io.opentelemetry.api.incubator.common; -import static io.opentelemetry.api.incubator.common.ArrayBackedExtendedAttributesBuilder.toList; -import static io.opentelemetry.api.incubator.common.ExtendedAttributeKey.booleanArrayKey; -import static io.opentelemetry.api.incubator.common.ExtendedAttributeKey.booleanKey; -import static io.opentelemetry.api.incubator.common.ExtendedAttributeKey.doubleArrayKey; -import static io.opentelemetry.api.incubator.common.ExtendedAttributeKey.doubleKey; -import static io.opentelemetry.api.incubator.common.ExtendedAttributeKey.longArrayKey; -import static io.opentelemetry.api.incubator.common.ExtendedAttributeKey.longKey; -import static io.opentelemetry.api.incubator.common.ExtendedAttributeKey.stringArrayKey; -import static io.opentelemetry.api.incubator.common.ExtendedAttributeKey.stringKey; - import io.opentelemetry.api.common.AttributeKey; import io.opentelemetry.api.common.Attributes; import io.opentelemetry.api.common.Value; @@ -22,7 +12,13 @@ import java.util.List; import java.util.function.Predicate; -/** A builder of {@link ExtendedAttributes} supporting an arbitrary number of key-value pairs. */ +/** + * A builder of {@link ExtendedAttributes} supporting an arbitrary number of key-value pairs. + * + * @deprecated Use {@link io.opentelemetry.api.common.AttributesBuilder} with {@link + * io.opentelemetry.api.common.AttributeKey#valueKey(String)} instead. + */ +@Deprecated public interface ExtendedAttributesBuilder { /** Create the {@link ExtendedAttributes} from this. */ ExtendedAttributes build(); @@ -85,7 +81,7 @@ default ExtendedAttributesBuilder put(AttributeKey key, T value) { * @return this Builder */ default ExtendedAttributesBuilder put(String key, String value) { - return put(stringKey(key), value); + return put(ExtendedAttributeKey.stringKey(key), value); } /** @@ -97,7 +93,7 @@ default ExtendedAttributesBuilder put(String key, String value) { * @return this Builder */ default ExtendedAttributesBuilder put(String key, long value) { - return put(longKey(key), value); + return put(ExtendedAttributeKey.longKey(key), value); } /** @@ -109,7 +105,7 @@ default ExtendedAttributesBuilder put(String key, long value) { * @return this Builder */ default ExtendedAttributesBuilder put(String key, double value) { - return put(doubleKey(key), value); + return put(ExtendedAttributeKey.doubleKey(key), value); } /** @@ -121,7 +117,7 @@ default ExtendedAttributesBuilder put(String key, double value) { * @return this Builder */ default ExtendedAttributesBuilder put(String key, boolean value) { - return put(booleanKey(key), value); + return put(ExtendedAttributeKey.booleanKey(key), value); } /** @@ -151,7 +147,7 @@ default ExtendedAttributesBuilder put(String key, String... value) { if (value == null) { return this; } - return put(stringArrayKey(key), Arrays.asList(value)); + return put(ExtendedAttributeKey.stringArrayKey(key), Arrays.asList(value)); } /** @@ -179,7 +175,8 @@ default ExtendedAttributesBuilder put(String key, long... value) { if (value == null) { return this; } - return put(longArrayKey(key), toList(value)); + return put( + ExtendedAttributeKey.longArrayKey(key), ArrayBackedExtendedAttributesBuilder.toList(value)); } /** @@ -194,7 +191,9 @@ default ExtendedAttributesBuilder put(String key, double... value) { if (value == null) { return this; } - return put(doubleArrayKey(key), toList(value)); + return put( + ExtendedAttributeKey.doubleArrayKey(key), + ArrayBackedExtendedAttributesBuilder.toList(value)); } /** @@ -209,7 +208,9 @@ default ExtendedAttributesBuilder put(String key, boolean... value) { if (value == null) { return this; } - return put(booleanArrayKey(key), toList(value)); + return put( + ExtendedAttributeKey.booleanArrayKey(key), + ArrayBackedExtendedAttributesBuilder.toList(value)); } /** diff --git a/api/incubator/src/main/java/io/opentelemetry/api/incubator/internal/InternalExtendedAttributeKeyImpl.java b/api/incubator/src/main/java/io/opentelemetry/api/incubator/internal/InternalExtendedAttributeKeyImpl.java index 834c9653f39..1ab91765a35 100644 --- a/api/incubator/src/main/java/io/opentelemetry/api/incubator/internal/InternalExtendedAttributeKeyImpl.java +++ b/api/incubator/src/main/java/io/opentelemetry/api/incubator/internal/InternalExtendedAttributeKeyImpl.java @@ -7,8 +7,6 @@ import io.opentelemetry.api.common.AttributeKey; import io.opentelemetry.api.common.AttributeType; -import io.opentelemetry.api.incubator.common.ExtendedAttributeKey; -import io.opentelemetry.api.incubator.common.ExtendedAttributeType; import io.opentelemetry.api.internal.InternalAttributeKeyImpl; import java.nio.charset.StandardCharsets; import javax.annotation.Nullable; @@ -17,16 +15,19 @@ * This class is internal and is hence not for public use. Its APIs are unstable and can change at * any time. */ -public final class InternalExtendedAttributeKeyImpl implements ExtendedAttributeKey { +@SuppressWarnings("deprecation") +public final class InternalExtendedAttributeKeyImpl + implements io.opentelemetry.api.incubator.common.ExtendedAttributeKey { - private final ExtendedAttributeType type; + private final io.opentelemetry.api.incubator.common.ExtendedAttributeType type; private final String key; private final int hashCode; @Nullable private byte[] keyUtf8; @Nullable private AttributeKey attributeKey; - private InternalExtendedAttributeKeyImpl(ExtendedAttributeType type, String key) { + private InternalExtendedAttributeKeyImpl( + io.opentelemetry.api.incubator.common.ExtendedAttributeType type, String key) { if (type == null) { throw new NullPointerException("Null type"); } @@ -38,13 +39,13 @@ private InternalExtendedAttributeKeyImpl(ExtendedAttributeType type, String key) this.hashCode = buildHashCode(type, key); } - public static ExtendedAttributeKey create( - @Nullable String key, ExtendedAttributeType type) { + public static io.opentelemetry.api.incubator.common.ExtendedAttributeKey create( + @Nullable String key, io.opentelemetry.api.incubator.common.ExtendedAttributeType type) { return new InternalExtendedAttributeKeyImpl<>(type, key != null ? key : ""); } @Override - public ExtendedAttributeType getType() { + public io.opentelemetry.api.incubator.common.ExtendedAttributeType getType() { return type; } @@ -100,7 +101,8 @@ private int buildHashCode() { return buildHashCode(type, key); } - private static int buildHashCode(ExtendedAttributeType type, String key) { + private static int buildHashCode( + io.opentelemetry.api.incubator.common.ExtendedAttributeType type, String key) { int result = 1; result *= 1000003; result ^= type.hashCode(); @@ -110,13 +112,13 @@ private static int buildHashCode(ExtendedAttributeType type, String key) { } /** - * Return the equivalent {@link AttributeKey} for the {@link ExtendedAttributeKey}, or {@code - * null} if the {@link #getType()} has no equivalent {@link - * io.opentelemetry.api.common.AttributeType}. + * Return the equivalent {@link AttributeKey} for the {@link + * io.opentelemetry.api.incubator.common.ExtendedAttributeKey}, or {@code null} if the {@link + * #getType()} has no equivalent {@link io.opentelemetry.api.common.AttributeType}. */ @Nullable - @SuppressWarnings("deprecation") // Supporting deprecated EXTENDED_ATTRIBUTES until removed - public static AttributeKey toAttributeKey(ExtendedAttributeKey extendedAttributeKey) { + public static AttributeKey toAttributeKey( + io.opentelemetry.api.incubator.common.ExtendedAttributeKey extendedAttributeKey) { switch (extendedAttributeKey.getType()) { case STRING: return InternalAttributeKeyImpl.create(extendedAttributeKey.getKey(), AttributeType.STRING); @@ -148,36 +150,50 @@ public static AttributeKey toAttributeKey(ExtendedAttributeKey extende "Unrecognized extendedAttributeKey type: " + extendedAttributeKey.getType()); } - /** Return the equivalent {@link ExtendedAttributeKey} for the {@link AttributeKey}. */ - public static ExtendedAttributeKey toExtendedAttributeKey(AttributeKey attributeKey) { + /** + * Return the equivalent {@link io.opentelemetry.api.incubator.common.ExtendedAttributeKey} for + * the {@link AttributeKey}. + */ + public static + io.opentelemetry.api.incubator.common.ExtendedAttributeKey toExtendedAttributeKey( + AttributeKey attributeKey) { switch (attributeKey.getType()) { case STRING: return InternalExtendedAttributeKeyImpl.create( - attributeKey.getKey(), ExtendedAttributeType.STRING); + attributeKey.getKey(), + io.opentelemetry.api.incubator.common.ExtendedAttributeType.STRING); case BOOLEAN: return InternalExtendedAttributeKeyImpl.create( - attributeKey.getKey(), ExtendedAttributeType.BOOLEAN); + attributeKey.getKey(), + io.opentelemetry.api.incubator.common.ExtendedAttributeType.BOOLEAN); case LONG: return InternalExtendedAttributeKeyImpl.create( - attributeKey.getKey(), ExtendedAttributeType.LONG); + attributeKey.getKey(), + io.opentelemetry.api.incubator.common.ExtendedAttributeType.LONG); case DOUBLE: return InternalExtendedAttributeKeyImpl.create( - attributeKey.getKey(), ExtendedAttributeType.DOUBLE); + attributeKey.getKey(), + io.opentelemetry.api.incubator.common.ExtendedAttributeType.DOUBLE); case STRING_ARRAY: return InternalExtendedAttributeKeyImpl.create( - attributeKey.getKey(), ExtendedAttributeType.STRING_ARRAY); + attributeKey.getKey(), + io.opentelemetry.api.incubator.common.ExtendedAttributeType.STRING_ARRAY); case BOOLEAN_ARRAY: return InternalExtendedAttributeKeyImpl.create( - attributeKey.getKey(), ExtendedAttributeType.BOOLEAN_ARRAY); + attributeKey.getKey(), + io.opentelemetry.api.incubator.common.ExtendedAttributeType.BOOLEAN_ARRAY); case LONG_ARRAY: return InternalExtendedAttributeKeyImpl.create( - attributeKey.getKey(), ExtendedAttributeType.LONG_ARRAY); + attributeKey.getKey(), + io.opentelemetry.api.incubator.common.ExtendedAttributeType.LONG_ARRAY); case DOUBLE_ARRAY: return InternalExtendedAttributeKeyImpl.create( - attributeKey.getKey(), ExtendedAttributeType.DOUBLE_ARRAY); + attributeKey.getKey(), + io.opentelemetry.api.incubator.common.ExtendedAttributeType.DOUBLE_ARRAY); case VALUE: return InternalExtendedAttributeKeyImpl.create( - attributeKey.getKey(), ExtendedAttributeType.VALUE); + attributeKey.getKey(), + io.opentelemetry.api.incubator.common.ExtendedAttributeType.VALUE); } throw new IllegalArgumentException("Unrecognized attributeKey type: " + attributeKey.getType()); } diff --git a/api/incubator/src/main/java/io/opentelemetry/api/incubator/logs/ExtendedDefaultLogger.java b/api/incubator/src/main/java/io/opentelemetry/api/incubator/logs/ExtendedDefaultLogger.java index 14731495606..0984d9bcd60 100644 --- a/api/incubator/src/main/java/io/opentelemetry/api/incubator/logs/ExtendedDefaultLogger.java +++ b/api/incubator/src/main/java/io/opentelemetry/api/incubator/logs/ExtendedDefaultLogger.java @@ -7,7 +7,6 @@ import io.opentelemetry.api.common.AttributeKey; import io.opentelemetry.api.common.Value; -import io.opentelemetry.api.incubator.common.ExtendedAttributeKey; import io.opentelemetry.api.logs.Logger; import io.opentelemetry.api.logs.Severity; import io.opentelemetry.context.Context; @@ -15,6 +14,7 @@ import java.util.concurrent.TimeUnit; import javax.annotation.Nullable; +@SuppressWarnings("deprecation") class ExtendedDefaultLogger implements ExtendedLogger { private static final Logger INSTANCE = new ExtendedDefaultLogger(); @@ -52,7 +52,8 @@ public ExtendedLogRecordBuilder setException(Throwable throwable) { } @Override - public ExtendedLogRecordBuilder setAttribute(ExtendedAttributeKey key, T value) { + public ExtendedLogRecordBuilder setAttribute( + io.opentelemetry.api.incubator.common.ExtendedAttributeKey key, T value) { return this; } diff --git a/api/incubator/src/main/java/io/opentelemetry/api/incubator/logs/ExtendedLogRecordBuilder.java b/api/incubator/src/main/java/io/opentelemetry/api/incubator/logs/ExtendedLogRecordBuilder.java index de25aabe4d4..3dd6dd0b7c3 100644 --- a/api/incubator/src/main/java/io/opentelemetry/api/incubator/logs/ExtendedLogRecordBuilder.java +++ b/api/incubator/src/main/java/io/opentelemetry/api/incubator/logs/ExtendedLogRecordBuilder.java @@ -8,8 +8,6 @@ import io.opentelemetry.api.common.AttributeKey; import io.opentelemetry.api.common.Attributes; import io.opentelemetry.api.common.Value; -import io.opentelemetry.api.incubator.common.ExtendedAttributeKey; -import io.opentelemetry.api.incubator.common.ExtendedAttributes; import io.opentelemetry.api.logs.LogRecordBuilder; import io.opentelemetry.api.logs.Severity; import io.opentelemetry.context.Context; @@ -18,6 +16,7 @@ import javax.annotation.Nullable; /** Extended {@link LogRecordBuilder} with experimental APIs. */ +@SuppressWarnings("deprecation") public interface ExtendedLogRecordBuilder extends LogRecordBuilder { // keep this class even if it is empty, since experimental methods may be added in the future. @@ -74,10 +73,10 @@ default ExtendedLogRecordBuilder setBody(Value body) { * {@inheritDoc} * *

    NOTE: all standard {@link AttributeKey}-value pairs can also be represented as {@link - * ExtendedAttributeKey}-value pairs, but not all {@link ExtendedAttributeKey}-value pairs can be - * represented as standard {@link AttributeKey}-value pairs. From the standpoint of the emitted - * log record, there is no difference between adding attributes using the standard or extended - * attribute APIs. + * io.opentelemetry.api.incubator.common.ExtendedAttributeKey}-value pairs, but not all {@link + * io.opentelemetry.api.incubator.common.ExtendedAttributeKey}-value pairs can be represented as + * standard {@link AttributeKey}-value pairs. From the standpoint of the emitted log record, there + * is no difference between adding attributes using the standard or extended attribute APIs. */ @SuppressWarnings("unchecked") @Override @@ -95,18 +94,22 @@ default ExtendedLogRecordBuilder setAllAttributes(Attributes attributes) { * keys, the old values are replaced by the specified values. * *

    NOTE: all standard {@link AttributeKey}-value pairs can also be represented as {@link - * ExtendedAttributeKey}-value pairs, but not all {@link ExtendedAttributeKey}-value pairs can be - * represented as standard {@link AttributeKey}-value pairs. From the standpoint of the emitted - * log record, there is no difference between adding attributes using the standard or extended - * attribute APIs. + * io.opentelemetry.api.incubator.common.ExtendedAttributeKey}-value pairs, but not all {@link + * io.opentelemetry.api.incubator.common.ExtendedAttributeKey}-value pairs can be represented as + * standard {@link AttributeKey}-value pairs. From the standpoint of the emitted log record, there + * is no difference between adding attributes using the standard or extended attribute APIs. */ @SuppressWarnings("unchecked") - default ExtendedLogRecordBuilder setAllAttributes(ExtendedAttributes attributes) { + default ExtendedLogRecordBuilder setAllAttributes( + io.opentelemetry.api.incubator.common.ExtendedAttributes attributes) { if (attributes == null || attributes.isEmpty()) { return this; } attributes.forEach( - (attributeKey, value) -> setAttribute((ExtendedAttributeKey) attributeKey, value)); + (attributeKey, value) -> + setAttribute( + (io.opentelemetry.api.incubator.common.ExtendedAttributeKey) attributeKey, + value)); return this; } @@ -114,10 +117,10 @@ default ExtendedLogRecordBuilder setAllAttributes(ExtendedAttributes attributes) * {@inheritDoc} * *

    NOTE: all standard {@link AttributeKey}-value pairs can also be represented as {@link - * ExtendedAttributeKey}-value pairs, but not all {@link ExtendedAttributeKey}-value pairs can be - * represented as standard {@link AttributeKey}-value pairs. From the standpoint of the emitted - * log record, there is no difference between adding attributes using the standard or extended - * attribute APIs. + * io.opentelemetry.api.incubator.common.ExtendedAttributeKey}-value pairs, but not all {@link + * io.opentelemetry.api.incubator.common.ExtendedAttributeKey}-value pairs can be represented as + * standard {@link AttributeKey}-value pairs. From the standpoint of the emitted log record, there + * is no difference between adding attributes using the standard or extended attribute APIs. */ @Override ExtendedLogRecordBuilder setAttribute(AttributeKey key, @Nullable T value); @@ -126,12 +129,13 @@ default ExtendedLogRecordBuilder setAllAttributes(ExtendedAttributes attributes) * Set an attribute. * *

    NOTE: all standard {@link AttributeKey}-value pairs can also be represented as {@link - * ExtendedAttributeKey}-value pairs, but not all {@link ExtendedAttributeKey}-value pairs can be - * represented as standard {@link AttributeKey}-value pairs. From the standpoint of the emitted - * log record, there is no difference between adding attributes using the standard or extended - * attribute APIs. + * io.opentelemetry.api.incubator.common.ExtendedAttributeKey}-value pairs, but not all {@link + * io.opentelemetry.api.incubator.common.ExtendedAttributeKey}-value pairs can be represented as + * standard {@link AttributeKey}-value pairs. From the standpoint of the emitted log record, there + * is no difference between adding attributes using the standard or extended attribute APIs. */ - ExtendedLogRecordBuilder setAttribute(ExtendedAttributeKey key, T value); + ExtendedLogRecordBuilder setAttribute( + io.opentelemetry.api.incubator.common.ExtendedAttributeKey key, T value); /** Set standard {@code exception.*} attributes based on the {@code throwable}. */ ExtendedLogRecordBuilder setException(Throwable throwable); diff --git a/api/incubator/src/test/java/io/opentelemetry/api/incubator/common/ExtendedAttributesTest.java b/api/incubator/src/test/java/io/opentelemetry/api/incubator/common/ExtendedAttributesTest.java index 2d94aca5556..ee649872527 100644 --- a/api/incubator/src/test/java/io/opentelemetry/api/incubator/common/ExtendedAttributesTest.java +++ b/api/incubator/src/test/java/io/opentelemetry/api/incubator/common/ExtendedAttributesTest.java @@ -5,15 +5,6 @@ package io.opentelemetry.api.incubator.common; -import static io.opentelemetry.api.incubator.common.ExtendedAttributeKey.booleanArrayKey; -import static io.opentelemetry.api.incubator.common.ExtendedAttributeKey.booleanKey; -import static io.opentelemetry.api.incubator.common.ExtendedAttributeKey.doubleArrayKey; -import static io.opentelemetry.api.incubator.common.ExtendedAttributeKey.doubleKey; -import static io.opentelemetry.api.incubator.common.ExtendedAttributeKey.longArrayKey; -import static io.opentelemetry.api.incubator.common.ExtendedAttributeKey.longKey; -import static io.opentelemetry.api.incubator.common.ExtendedAttributeKey.stringArrayKey; -import static io.opentelemetry.api.incubator.common.ExtendedAttributeKey.stringKey; -import static io.opentelemetry.api.incubator.common.ExtendedAttributeKey.valueKey; import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.entry; @@ -229,7 +220,9 @@ private static Stream attributesArgs() { .put("key", ImmutableMap.builder().put("child", "value").build()) .build()), Arguments.of( - ExtendedAttributes.builder().put(valueKey("key"), Value.of("value")).build(), + ExtendedAttributes.builder() + .put(ExtendedAttributeKey.valueKey("key"), Value.of("value")) + .build(), ImmutableMap.builder().put("key", "value").build()), Arguments.of( ExtendedAttributes.builder() @@ -292,7 +285,7 @@ private static Stream attributesArgs() { .put("key8", 1L, 2L) .put("key9", 1.1, 2.2) .put("key10", ExtendedAttributes.builder().put("child", "value").build()) - .put(valueKey("key11"), Value.of("value")) + .put(ExtendedAttributeKey.valueKey("key11"), Value.of("value")) .build(), ImmutableMap.builder() .put("key1", "value1") @@ -393,76 +386,88 @@ private static ExtendedAttributeType getType(Object value) { void complexValueStoredAsString() { // When putting a VALUE attribute with a string Value, it should be stored as STRING type ExtendedAttributes attributes = - ExtendedAttributes.builder().put(valueKey("key"), Value.of("test")).build(); + ExtendedAttributes.builder() + .put(ExtendedAttributeKey.valueKey("key"), Value.of("test")) + .build(); // Should be stored as STRING type internally - assertThat(attributes.get(stringKey("key"))).isEqualTo("test"); - assertThat(attributes.get(valueKey("key"))).isEqualTo(Value.of("test")); + assertThat(attributes.get(ExtendedAttributeKey.stringKey("key"))).isEqualTo("test"); + assertThat(attributes.get(ExtendedAttributeKey.valueKey("key"))).isEqualTo(Value.of("test")); // forEach should show STRING type Map, Object> entriesSeen = new HashMap<>(); attributes.forEach(entriesSeen::put); - assertThat(entriesSeen).containsExactly(entry(stringKey("key"), "test")); + assertThat(entriesSeen).containsExactly(entry(ExtendedAttributeKey.stringKey("key"), "test")); // asMap should show STRING type - assertThat(attributes.asMap()).containsExactly(entry(stringKey("key"), "test")); + assertThat(attributes.asMap()) + .containsExactly(entry(ExtendedAttributeKey.stringKey("key"), "test")); } @Test void complexValueStoredAsLong() { // When putting a VALUE attribute with a long Value, it should be stored as LONG type ExtendedAttributes attributes = - ExtendedAttributes.builder().put(valueKey("key"), Value.of(123L)).build(); + ExtendedAttributes.builder() + .put(ExtendedAttributeKey.valueKey("key"), Value.of(123L)) + .build(); // Should be stored as LONG type internally - assertThat(attributes.get(longKey("key"))).isEqualTo(123L); - assertThat(attributes.get(valueKey("key"))).isEqualTo(Value.of(123L)); + assertThat(attributes.get(ExtendedAttributeKey.longKey("key"))).isEqualTo(123L); + assertThat(attributes.get(ExtendedAttributeKey.valueKey("key"))).isEqualTo(Value.of(123L)); // forEach should show LONG type Map, Object> entriesSeen = new HashMap<>(); attributes.forEach(entriesSeen::put); - assertThat(entriesSeen).containsExactly(entry(longKey("key"), 123L)); + assertThat(entriesSeen).containsExactly(entry(ExtendedAttributeKey.longKey("key"), 123L)); // asMap should show LONG type - assertThat(attributes.asMap()).containsExactly(entry(longKey("key"), 123L)); + assertThat(attributes.asMap()) + .containsExactly(entry(ExtendedAttributeKey.longKey("key"), 123L)); } @Test void complexValueStoredAsDouble() { // When putting a VALUE attribute with a double Value, it should be stored as DOUBLE type ExtendedAttributes attributes = - ExtendedAttributes.builder().put(valueKey("key"), Value.of(1.23)).build(); + ExtendedAttributes.builder() + .put(ExtendedAttributeKey.valueKey("key"), Value.of(1.23)) + .build(); // Should be stored as DOUBLE type internally - assertThat(attributes.get(doubleKey("key"))).isEqualTo(1.23); - assertThat(attributes.get(valueKey("key"))).isEqualTo(Value.of(1.23)); + assertThat(attributes.get(ExtendedAttributeKey.doubleKey("key"))).isEqualTo(1.23); + assertThat(attributes.get(ExtendedAttributeKey.valueKey("key"))).isEqualTo(Value.of(1.23)); // forEach should show DOUBLE type Map, Object> entriesSeen = new HashMap<>(); attributes.forEach(entriesSeen::put); - assertThat(entriesSeen).containsExactly(entry(doubleKey("key"), 1.23)); + assertThat(entriesSeen).containsExactly(entry(ExtendedAttributeKey.doubleKey("key"), 1.23)); // asMap should show DOUBLE type - assertThat(attributes.asMap()).containsExactly(entry(doubleKey("key"), 1.23)); + assertThat(attributes.asMap()) + .containsExactly(entry(ExtendedAttributeKey.doubleKey("key"), 1.23)); } @Test void complexValueStoredAsBoolean() { // When putting a VALUE attribute with a boolean Value, it should be stored as BOOLEAN type ExtendedAttributes attributes = - ExtendedAttributes.builder().put(valueKey("key"), Value.of(true)).build(); + ExtendedAttributes.builder() + .put(ExtendedAttributeKey.valueKey("key"), Value.of(true)) + .build(); // Should be stored as BOOLEAN type internally - assertThat(attributes.get(booleanKey("key"))).isEqualTo(true); - assertThat(attributes.get(valueKey("key"))).isEqualTo(Value.of(true)); + assertThat(attributes.get(ExtendedAttributeKey.booleanKey("key"))).isEqualTo(true); + assertThat(attributes.get(ExtendedAttributeKey.valueKey("key"))).isEqualTo(Value.of(true)); // forEach should show BOOLEAN type Map, Object> entriesSeen = new HashMap<>(); attributes.forEach(entriesSeen::put); - assertThat(entriesSeen).containsExactly(entry(booleanKey("key"), true)); + assertThat(entriesSeen).containsExactly(entry(ExtendedAttributeKey.booleanKey("key"), true)); // asMap should show BOOLEAN type - assertThat(attributes.asMap()).containsExactly(entry(booleanKey("key"), true)); + assertThat(attributes.asMap()) + .containsExactly(entry(ExtendedAttributeKey.booleanKey("key"), true)); } @Test @@ -471,22 +476,28 @@ void complexValueStoredAsStringArray() { // STRING_ARRAY type ExtendedAttributes attributes = ExtendedAttributes.builder() - .put(valueKey("key"), Value.of(Arrays.asList(Value.of("a"), Value.of("b")))) + .put( + ExtendedAttributeKey.valueKey("key"), + Value.of(Arrays.asList(Value.of("a"), Value.of("b")))) .build(); // Should be stored as STRING_ARRAY type internally - assertThat(attributes.get(stringArrayKey("key"))).containsExactly("a", "b"); - assertThat(attributes.get(valueKey("key"))) + assertThat(attributes.get(ExtendedAttributeKey.stringArrayKey("key"))) + .containsExactly("a", "b"); + assertThat(attributes.get(ExtendedAttributeKey.valueKey("key"))) .isEqualTo(Value.of(Arrays.asList(Value.of("a"), Value.of("b")))); // forEach should show STRING_ARRAY type Map, Object> entriesSeen = new HashMap<>(); attributes.forEach(entriesSeen::put); - assertThat(entriesSeen).containsExactly(entry(stringArrayKey("key"), Arrays.asList("a", "b"))); + assertThat(entriesSeen) + .containsExactly( + entry(ExtendedAttributeKey.stringArrayKey("key"), Arrays.asList("a", "b"))); // asMap should show STRING_ARRAY type assertThat(attributes.asMap()) - .containsExactly(entry(stringArrayKey("key"), Arrays.asList("a", "b"))); + .containsExactly( + entry(ExtendedAttributeKey.stringArrayKey("key"), Arrays.asList("a", "b"))); } @Test @@ -495,22 +506,25 @@ void complexValueStoredAsLongArray() { // LONG_ARRAY type ExtendedAttributes attributes = ExtendedAttributes.builder() - .put(valueKey("key"), Value.of(Arrays.asList(Value.of(1L), Value.of(2L)))) + .put( + ExtendedAttributeKey.valueKey("key"), + Value.of(Arrays.asList(Value.of(1L), Value.of(2L)))) .build(); // Should be stored as LONG_ARRAY type internally - assertThat(attributes.get(longArrayKey("key"))).containsExactly(1L, 2L); - assertThat(attributes.get(valueKey("key"))) + assertThat(attributes.get(ExtendedAttributeKey.longArrayKey("key"))).containsExactly(1L, 2L); + assertThat(attributes.get(ExtendedAttributeKey.valueKey("key"))) .isEqualTo(Value.of(Arrays.asList(Value.of(1L), Value.of(2L)))); // forEach should show LONG_ARRAY type Map, Object> entriesSeen = new HashMap<>(); attributes.forEach(entriesSeen::put); - assertThat(entriesSeen).containsExactly(entry(longArrayKey("key"), Arrays.asList(1L, 2L))); + assertThat(entriesSeen) + .containsExactly(entry(ExtendedAttributeKey.longArrayKey("key"), Arrays.asList(1L, 2L))); // asMap should show LONG_ARRAY type assertThat(attributes.asMap()) - .containsExactly(entry(longArrayKey("key"), Arrays.asList(1L, 2L))); + .containsExactly(entry(ExtendedAttributeKey.longArrayKey("key"), Arrays.asList(1L, 2L))); } @Test @@ -519,22 +533,28 @@ void complexValueStoredAsDoubleArray() { // DOUBLE_ARRAY type ExtendedAttributes attributes = ExtendedAttributes.builder() - .put(valueKey("key"), Value.of(Arrays.asList(Value.of(1.1), Value.of(2.2)))) + .put( + ExtendedAttributeKey.valueKey("key"), + Value.of(Arrays.asList(Value.of(1.1), Value.of(2.2)))) .build(); // Should be stored as DOUBLE_ARRAY type internally - assertThat(attributes.get(doubleArrayKey("key"))).containsExactly(1.1, 2.2); - assertThat(attributes.get(valueKey("key"))) + assertThat(attributes.get(ExtendedAttributeKey.doubleArrayKey("key"))) + .containsExactly(1.1, 2.2); + assertThat(attributes.get(ExtendedAttributeKey.valueKey("key"))) .isEqualTo(Value.of(Arrays.asList(Value.of(1.1), Value.of(2.2)))); // forEach should show DOUBLE_ARRAY type Map, Object> entriesSeen = new HashMap<>(); attributes.forEach(entriesSeen::put); - assertThat(entriesSeen).containsExactly(entry(doubleArrayKey("key"), Arrays.asList(1.1, 2.2))); + assertThat(entriesSeen) + .containsExactly( + entry(ExtendedAttributeKey.doubleArrayKey("key"), Arrays.asList(1.1, 2.2))); // asMap should show DOUBLE_ARRAY type assertThat(attributes.asMap()) - .containsExactly(entry(doubleArrayKey("key"), Arrays.asList(1.1, 2.2))); + .containsExactly( + entry(ExtendedAttributeKey.doubleArrayKey("key"), Arrays.asList(1.1, 2.2))); } @Test @@ -543,23 +563,28 @@ void complexValueStoredAsBooleanArray() { // BOOLEAN_ARRAY type ExtendedAttributes attributes = ExtendedAttributes.builder() - .put(valueKey("key"), Value.of(Arrays.asList(Value.of(true), Value.of(false)))) + .put( + ExtendedAttributeKey.valueKey("key"), + Value.of(Arrays.asList(Value.of(true), Value.of(false)))) .build(); // Should be stored as BOOLEAN_ARRAY type internally - assertThat(attributes.get(booleanArrayKey("key"))).containsExactly(true, false); - assertThat(attributes.get(valueKey("key"))) + assertThat(attributes.get(ExtendedAttributeKey.booleanArrayKey("key"))) + .containsExactly(true, false); + assertThat(attributes.get(ExtendedAttributeKey.valueKey("key"))) .isEqualTo(Value.of(Arrays.asList(Value.of(true), Value.of(false)))); // forEach should show BOOLEAN_ARRAY type Map, Object> entriesSeen = new HashMap<>(); attributes.forEach(entriesSeen::put); assertThat(entriesSeen) - .containsExactly(entry(booleanArrayKey("key"), Arrays.asList(true, false))); + .containsExactly( + entry(ExtendedAttributeKey.booleanArrayKey("key"), Arrays.asList(true, false))); // asMap should show BOOLEAN_ARRAY type assertThat(attributes.asMap()) - .containsExactly(entry(booleanArrayKey("key"), Arrays.asList(true, false))); + .containsExactly( + entry(ExtendedAttributeKey.booleanArrayKey("key"), Arrays.asList(true, false))); } @Test @@ -575,17 +600,17 @@ void simpleAttributeRetrievedAsComplexValue() { .put("doubleArray", 1.1, 2.2) .put("booleanArray", true, false) .build(); - assertThat(attributes.get(valueKey("string"))).isEqualTo(Value.of("test")); - assertThat(attributes.get(valueKey("long"))).isEqualTo(Value.of(123L)); - assertThat(attributes.get(valueKey("double"))).isEqualTo(Value.of(1.23)); - assertThat(attributes.get(valueKey("boolean"))).isEqualTo(Value.of(true)); - assertThat(attributes.get(valueKey("stringArray"))) + assertThat(attributes.get(ExtendedAttributeKey.valueKey("string"))).isEqualTo(Value.of("test")); + assertThat(attributes.get(ExtendedAttributeKey.valueKey("long"))).isEqualTo(Value.of(123L)); + assertThat(attributes.get(ExtendedAttributeKey.valueKey("double"))).isEqualTo(Value.of(1.23)); + assertThat(attributes.get(ExtendedAttributeKey.valueKey("boolean"))).isEqualTo(Value.of(true)); + assertThat(attributes.get(ExtendedAttributeKey.valueKey("stringArray"))) .isEqualTo(Value.of(Arrays.asList(Value.of("a"), Value.of("b")))); - assertThat(attributes.get(valueKey("longArray"))) + assertThat(attributes.get(ExtendedAttributeKey.valueKey("longArray"))) .isEqualTo(Value.of(Arrays.asList(Value.of(1L), Value.of(2L)))); - assertThat(attributes.get(valueKey("doubleArray"))) + assertThat(attributes.get(ExtendedAttributeKey.valueKey("doubleArray"))) .isEqualTo(Value.of(Arrays.asList(Value.of(1.1), Value.of(2.2)))); - assertThat(attributes.get(valueKey("booleanArray"))) + assertThat(attributes.get(ExtendedAttributeKey.valueKey("booleanArray"))) .isEqualTo(Value.of(Arrays.asList(Value.of(true), Value.of(false)))); } @@ -593,12 +618,12 @@ void simpleAttributeRetrievedAsComplexValue() { void emptyValueArrayRetrievedAsAnyArrayType() { ExtendedAttributes attributes = ExtendedAttributes.builder() - .put(valueKey("key"), Value.of(Collections.emptyList())) + .put(ExtendedAttributeKey.valueKey("key"), Value.of(Collections.emptyList())) .build(); - assertThat(attributes.get(stringArrayKey("key"))).isEmpty(); - assertThat(attributes.get(longArrayKey("key"))).isEmpty(); - assertThat(attributes.get(doubleArrayKey("key"))).isEmpty(); - assertThat(attributes.get(booleanArrayKey("key"))).isEmpty(); + assertThat(attributes.get(ExtendedAttributeKey.stringArrayKey("key"))).isEmpty(); + assertThat(attributes.get(ExtendedAttributeKey.longArrayKey("key"))).isEmpty(); + assertThat(attributes.get(ExtendedAttributeKey.doubleArrayKey("key"))).isEmpty(); + assertThat(attributes.get(ExtendedAttributeKey.booleanArrayKey("key"))).isEmpty(); } @Test @@ -617,14 +642,14 @@ void putNullKey() { @Test void putNullValue() { ExtendedAttributes attributes = - ExtendedAttributes.builder().put(stringKey("key"), null).build(); + ExtendedAttributes.builder().put(ExtendedAttributeKey.stringKey("key"), null).build(); assertThat(attributes.isEmpty()).isTrue(); } @Test void putEmptyKey() { ExtendedAttributes attributes = - ExtendedAttributes.builder().put(stringKey(""), "value").build(); + ExtendedAttributes.builder().put(ExtendedAttributeKey.stringKey(""), "value").build(); assertThat(attributes.isEmpty()).isTrue(); } @@ -637,7 +662,7 @@ void extendedAttributesNotConvertibleToValue() { .build(); // Getting as VALUE should return null since EXTENDED_ATTRIBUTES cannot be converted to Value - assertThat(attributes.get(valueKey("key"))).isNull(); + assertThat(attributes.get(ExtendedAttributeKey.valueKey("key"))).isNull(); } @Test @@ -645,15 +670,16 @@ void complexValueWithKeyValueList() { // KEY_VALUE_LIST should be kept as VALUE type Value kvListValue = Value.of(Collections.emptyMap()); ExtendedAttributes attributes = - ExtendedAttributes.builder().put(valueKey("key"), kvListValue).build(); + ExtendedAttributes.builder().put(ExtendedAttributeKey.valueKey("key"), kvListValue).build(); // Should be stored as VALUE type - assertThat(attributes.get(valueKey("key"))).isEqualTo(kvListValue); + assertThat(attributes.get(ExtendedAttributeKey.valueKey("key"))).isEqualTo(kvListValue); // forEach should show VALUE type Map, Object> entriesSeen = new HashMap<>(); attributes.forEach(entriesSeen::put); - assertThat(entriesSeen).containsExactly(entry(valueKey("key"), kvListValue)); + assertThat(entriesSeen) + .containsExactly(entry(ExtendedAttributeKey.valueKey("key"), kvListValue)); } @Test @@ -661,15 +687,16 @@ void complexValueWithBytes() { // BYTES should be kept as VALUE type Value bytesValue = Value.of(new byte[] {1, 2, 3}); ExtendedAttributes attributes = - ExtendedAttributes.builder().put(valueKey("key"), bytesValue).build(); + ExtendedAttributes.builder().put(ExtendedAttributeKey.valueKey("key"), bytesValue).build(); // Should be stored as VALUE type - assertThat(attributes.get(valueKey("key"))).isEqualTo(bytesValue); + assertThat(attributes.get(ExtendedAttributeKey.valueKey("key"))).isEqualTo(bytesValue); // forEach should show VALUE type Map, Object> entriesSeen = new HashMap<>(); attributes.forEach(entriesSeen::put); - assertThat(entriesSeen).containsExactly(entry(valueKey("key"), bytesValue)); + assertThat(entriesSeen) + .containsExactly(entry(ExtendedAttributeKey.valueKey("key"), bytesValue)); } @Test @@ -677,15 +704,16 @@ void complexValueWithNonHomogeneousArray() { // Non-homogeneous array should be kept as VALUE type Value mixedArray = Value.of(Arrays.asList(Value.of("string"), Value.of(123L))); ExtendedAttributes attributes = - ExtendedAttributes.builder().put(valueKey("key"), mixedArray).build(); + ExtendedAttributes.builder().put(ExtendedAttributeKey.valueKey("key"), mixedArray).build(); // Should be stored as VALUE type - assertThat(attributes.get(valueKey("key"))).isEqualTo(mixedArray); + assertThat(attributes.get(ExtendedAttributeKey.valueKey("key"))).isEqualTo(mixedArray); // forEach should show VALUE type Map, Object> entriesSeen = new HashMap<>(); attributes.forEach(entriesSeen::put); - assertThat(entriesSeen).containsExactly(entry(valueKey("key"), mixedArray)); + assertThat(entriesSeen) + .containsExactly(entry(ExtendedAttributeKey.valueKey("key"), mixedArray)); } @Test @@ -697,15 +725,16 @@ void complexValueWithNestedArray() { Value.of(Arrays.asList(Value.of("a"), Value.of("b"))), Value.of(Arrays.asList(Value.of("c"), Value.of("d"))))); ExtendedAttributes attributes = - ExtendedAttributes.builder().put(valueKey("key"), nestedArray).build(); + ExtendedAttributes.builder().put(ExtendedAttributeKey.valueKey("key"), nestedArray).build(); // Should be stored as VALUE type - assertThat(attributes.get(valueKey("key"))).isEqualTo(nestedArray); + assertThat(attributes.get(ExtendedAttributeKey.valueKey("key"))).isEqualTo(nestedArray); // forEach should show VALUE type Map, Object> entriesSeen = new HashMap<>(); attributes.forEach(entriesSeen::put); - assertThat(entriesSeen).containsExactly(entry(valueKey("key"), nestedArray)); + assertThat(entriesSeen) + .containsExactly(entry(ExtendedAttributeKey.valueKey("key"), nestedArray)); } @Test @@ -714,9 +743,9 @@ void getNonExistentArrayType() { ExtendedAttributes attributes = ExtendedAttributes.builder().put("key", "value").build(); // Looking for an array type when only a string exists should return null - assertThat(attributes.get(stringArrayKey("key"))).isNull(); - assertThat(attributes.get(longArrayKey("key"))).isNull(); - assertThat(attributes.get(doubleArrayKey("key"))).isNull(); - assertThat(attributes.get(booleanArrayKey("key"))).isNull(); + assertThat(attributes.get(ExtendedAttributeKey.stringArrayKey("key"))).isNull(); + assertThat(attributes.get(ExtendedAttributeKey.longArrayKey("key"))).isNull(); + assertThat(attributes.get(ExtendedAttributeKey.doubleArrayKey("key"))).isNull(); + assertThat(attributes.get(ExtendedAttributeKey.booleanArrayKey("key"))).isNull(); } } diff --git a/api/incubator/src/test/java/io/opentelemetry/api/incubator/logs/ExtendedLogsBridgeApiUsageTest.java b/api/incubator/src/test/java/io/opentelemetry/api/incubator/logs/ExtendedLogsBridgeApiUsageTest.java index b451bbf5dba..0e82953e929 100644 --- a/api/incubator/src/test/java/io/opentelemetry/api/incubator/logs/ExtendedLogsBridgeApiUsageTest.java +++ b/api/incubator/src/test/java/io/opentelemetry/api/incubator/logs/ExtendedLogsBridgeApiUsageTest.java @@ -13,8 +13,6 @@ import io.opentelemetry.api.common.Attributes; import io.opentelemetry.api.common.KeyValue; import io.opentelemetry.api.common.Value; -import io.opentelemetry.api.incubator.common.ExtendedAttributeKey; -import io.opentelemetry.api.incubator.common.ExtendedAttributes; import io.opentelemetry.api.logs.Logger; import io.opentelemetry.api.logs.Severity; import io.opentelemetry.internal.testing.slf4j.SuppressLogger; @@ -31,6 +29,7 @@ import org.junit.jupiter.api.Test; /** Demonstrating usage of extended Logs Bridge API. */ +@SuppressWarnings("deprecation") class ExtendedLogsBridgeApiUsageTest { private static final java.util.logging.Logger logger = @@ -106,15 +105,16 @@ private static String flipCoin() { AttributeKey> doubleArrKey = AttributeKey.doubleArrayKey("acme.double_array"); // VALUE key - ExtendedAttributeKey> valueKey = ExtendedAttributeKey.valueKey("acme.value"); + io.opentelemetry.api.incubator.common.ExtendedAttributeKey> valueKey = + io.opentelemetry.api.incubator.common.ExtendedAttributeKey.valueKey("acme.value"); @Test @SuppressLogger(ExtendedLogsBridgeApiUsageTest.class) void extendedAttributesUsage() { // Initialize from builder. Varargs style initialization (ExtendedAttributes.of(...) not // supported. - ExtendedAttributes extendedAttributes = - ExtendedAttributes.builder() + io.opentelemetry.api.incubator.common.ExtendedAttributes extendedAttributes = + io.opentelemetry.api.incubator.common.ExtendedAttributes.builder() .put(strKey, "value") .put(longKey, 1L) .put(booleanKey, true) @@ -191,7 +191,10 @@ void logRecordBuilder_ExtendedAttributes() { Value.of( KeyValue.of("childStr", Value.of("value")), KeyValue.of("childLong", Value.of(1L)))) .setAllAttributes(Attributes.builder().put("key1", "value").build()) - .setAllAttributes(ExtendedAttributes.builder().put("key2", "value").build()) + .setAllAttributes( + io.opentelemetry.api.incubator.common.ExtendedAttributes.builder() + .put("key2", "value") + .build()) .emit(); assertThat(exporter.getFinishedLogRecordItems()) @@ -225,7 +228,7 @@ void logRecordBuilder_ExtendedAttributes() { // But preferably access and serialize full extended attributes assertThat(extendedLogRecordData.getExtendedAttributes()) .isEqualTo( - ExtendedAttributes.builder() + io.opentelemetry.api.incubator.common.ExtendedAttributes.builder() .put(strKey, "value") .put(longKey, 1L) .put(booleanKey, true) diff --git a/exporters/otlp/common/src/main/java/io/opentelemetry/exporter/internal/otlp/ExtendedAttributeKeyValueStatelessMarshaler.java b/exporters/otlp/common/src/main/java/io/opentelemetry/exporter/internal/otlp/ExtendedAttributeKeyValueStatelessMarshaler.java index b812a9d2a29..06c2918faf6 100644 --- a/exporters/otlp/common/src/main/java/io/opentelemetry/exporter/internal/otlp/ExtendedAttributeKeyValueStatelessMarshaler.java +++ b/exporters/otlp/common/src/main/java/io/opentelemetry/exporter/internal/otlp/ExtendedAttributeKeyValueStatelessMarshaler.java @@ -6,9 +6,6 @@ package io.opentelemetry.exporter.internal.otlp; import io.opentelemetry.api.common.Value; -import io.opentelemetry.api.incubator.common.ExtendedAttributeKey; -import io.opentelemetry.api.incubator.common.ExtendedAttributeType; -import io.opentelemetry.api.incubator.common.ExtendedAttributes; import io.opentelemetry.api.incubator.internal.InternalExtendedAttributeKeyImpl; import io.opentelemetry.exporter.internal.marshal.CodedOutputStream; import io.opentelemetry.exporter.internal.marshal.MarshalerContext; @@ -27,13 +24,16 @@ import java.util.Objects; /** - * A Marshaler of {@link ExtendedAttributes} key value pairs. See {@link KeyValueMarshaler}. + * A Marshaler of {@link io.opentelemetry.api.incubator.common.ExtendedAttributes} key value pairs. + * See {@link KeyValueMarshaler}. * *

    This class is internal and is hence not for public use. Its APIs are unstable and can change * at any time. */ +@SuppressWarnings("deprecation") public final class ExtendedAttributeKeyValueStatelessMarshaler - implements StatelessMarshaler2, Object> { + implements StatelessMarshaler2< + io.opentelemetry.api.incubator.common.ExtendedAttributeKey, Object> { private static final ExtendedAttributeKeyValueStatelessMarshaler INSTANCE = new ExtendedAttributeKeyValueStatelessMarshaler(); private static final byte[] EMPTY_BYTES = new byte[0]; @@ -43,12 +43,12 @@ private ExtendedAttributeKeyValueStatelessMarshaler() {} /** * Serializes the {@code attributes}. This method reads elements from context, use together with * {@link ExtendedAttributeKeyValueStatelessMarshaler#sizeExtendedAttributes(ProtoFieldInfo, - * ExtendedAttributes, MarshalerContext)}. + * io.opentelemetry.api.incubator.common.ExtendedAttributes, MarshalerContext)}. */ public static void serializeExtendedAttributes( Serializer output, ProtoFieldInfo field, - ExtendedAttributes attributes, + io.opentelemetry.api.incubator.common.ExtendedAttributes attributes, MarshalerContext context) throws IOException { output.writeStartRepeated(field); @@ -76,10 +76,12 @@ public static void serializeExtendedAttributes( /** * Sizes the {@code attributes}. This method adds elements to context, use together with {@link * ExtendedAttributeKeyValueStatelessMarshaler#serializeExtendedAttributes(Serializer, - * ProtoFieldInfo, ExtendedAttributes, MarshalerContext)}. + * ProtoFieldInfo, io.opentelemetry.api.incubator.common.ExtendedAttributes, MarshalerContext)}. */ public static int sizeExtendedAttributes( - ProtoFieldInfo field, ExtendedAttributes attributes, MarshalerContext context) { + ProtoFieldInfo field, + io.opentelemetry.api.incubator.common.ExtendedAttributes attributes, + MarshalerContext context) { if (attributes.isEmpty()) { return 0; } @@ -101,7 +103,7 @@ public static int sizeExtendedAttributes( @Override public void writeTo( Serializer output, - ExtendedAttributeKey attributeKey, + io.opentelemetry.api.incubator.common.ExtendedAttributeKey attributeKey, Object value, MarshalerContext context) throws IOException { @@ -119,7 +121,9 @@ public void writeTo( @Override public int getBinarySerializedSize( - ExtendedAttributeKey attributeKey, Object value, MarshalerContext context) { + io.opentelemetry.api.incubator.common.ExtendedAttributeKey attributeKey, + Object value, + MarshalerContext context) { int size = 0; if (!attributeKey.getKey().isEmpty()) { if (attributeKey instanceof InternalExtendedAttributeKeyImpl) { @@ -138,15 +142,19 @@ public int getBinarySerializedSize( } private static class ValueStatelessMarshaler - implements StatelessMarshaler2, Object> { + implements StatelessMarshaler2< + io.opentelemetry.api.incubator.common.ExtendedAttributeKey, Object> { static final ValueStatelessMarshaler INSTANCE = new ValueStatelessMarshaler(); // Supporting deprecated EXTENDED_ATTRIBUTES type until removed - @SuppressWarnings({"unchecked", "deprecation"}) + @SuppressWarnings("unchecked") @Override public int getBinarySerializedSize( - ExtendedAttributeKey attributeKey, Object value, MarshalerContext context) { - ExtendedAttributeType attributeType = attributeKey.getType(); + io.opentelemetry.api.incubator.common.ExtendedAttributeKey attributeKey, + Object value, + MarshalerContext context) { + io.opentelemetry.api.incubator.common.ExtendedAttributeType attributeType = + attributeKey.getType(); switch (attributeType) { case STRING: return StringAnyValueStatelessMarshaler.INSTANCE.getBinarySerializedSize( @@ -173,7 +181,7 @@ public int getBinarySerializedSize( case EXTENDED_ATTRIBUTES: return StatelessMarshalerUtil.sizeMessageWithContext( AnyValue.KVLIST_VALUE, - (ExtendedAttributes) value, + (io.opentelemetry.api.incubator.common.ExtendedAttributes) value, ExtendedAttributesKeyValueListStatelessMarshaler.INSTANCE, context); case VALUE: @@ -186,15 +194,16 @@ public int getBinarySerializedSize( } // Supporting deprecated EXTENDED_ATTRIBUTES type until removed - @SuppressWarnings({"unchecked", "deprecation"}) + @SuppressWarnings("unchecked") @Override public void writeTo( Serializer output, - ExtendedAttributeKey attributeKey, + io.opentelemetry.api.incubator.common.ExtendedAttributeKey attributeKey, Object value, MarshalerContext context) throws IOException { - ExtendedAttributeType attributeType = attributeKey.getType(); + io.opentelemetry.api.incubator.common.ExtendedAttributeType attributeType = + attributeKey.getType(); switch (attributeType) { case STRING: StringAnyValueStatelessMarshaler.INSTANCE.writeTo(output, (String) value, context); @@ -222,7 +231,7 @@ public void writeTo( case EXTENDED_ATTRIBUTES: output.serializeMessageWithContext( AnyValue.KVLIST_VALUE, - (ExtendedAttributes) value, + (io.opentelemetry.api.incubator.common.ExtendedAttributes) value, ExtendedAttributesKeyValueListStatelessMarshaler.INSTANCE, context); return; @@ -237,20 +246,24 @@ public void writeTo( } private static class ExtendedAttributesKeyValueListStatelessMarshaler - implements StatelessMarshaler { + implements StatelessMarshaler { private static final ExtendedAttributesKeyValueListStatelessMarshaler INSTANCE = new ExtendedAttributesKeyValueListStatelessMarshaler(); private ExtendedAttributesKeyValueListStatelessMarshaler() {} @Override - public void writeTo(Serializer output, ExtendedAttributes value, MarshalerContext context) + public void writeTo( + Serializer output, + io.opentelemetry.api.incubator.common.ExtendedAttributes value, + MarshalerContext context) throws IOException { serializeExtendedAttributes(output, KeyValueList.VALUES, value, context); } @Override - public int getBinarySerializedSize(ExtendedAttributes value, MarshalerContext context) { + public int getBinarySerializedSize( + io.opentelemetry.api.incubator.common.ExtendedAttributes value, MarshalerContext context) { return sizeExtendedAttributes(KeyValueList.VALUES, value, context); } } diff --git a/exporters/otlp/common/src/main/java/io/opentelemetry/exporter/internal/otlp/IncubatingUtil.java b/exporters/otlp/common/src/main/java/io/opentelemetry/exporter/internal/otlp/IncubatingUtil.java index da34f7756cc..f4c5cf4c855 100644 --- a/exporters/otlp/common/src/main/java/io/opentelemetry/exporter/internal/otlp/IncubatingUtil.java +++ b/exporters/otlp/common/src/main/java/io/opentelemetry/exporter/internal/otlp/IncubatingUtil.java @@ -6,8 +6,6 @@ package io.opentelemetry.exporter.internal.otlp; import io.opentelemetry.api.common.Value; -import io.opentelemetry.api.incubator.common.ExtendedAttributeKey; -import io.opentelemetry.api.incubator.common.ExtendedAttributes; import io.opentelemetry.api.incubator.internal.InternalExtendedAttributeKeyImpl; import io.opentelemetry.exporter.internal.marshal.MarshalerContext; import io.opentelemetry.exporter.internal.marshal.Serializer; @@ -27,6 +25,7 @@ *

    This class is internal and is hence not for public use. Its APIs are unstable and can change * at any time. */ +@SuppressWarnings("deprecation") public class IncubatingUtil { private static final boolean INCUBATOR_AVAILABLE; @@ -62,18 +61,21 @@ public static int extendedAttributesSize(LogRecordData logRecordData) { } // TODO(jack-berg): move to KeyValueMarshaler when ExtendedAttributes is stable - private static KeyValueMarshaler[] createForExtendedAttributes(ExtendedAttributes attributes) { + private static KeyValueMarshaler[] createForExtendedAttributes( + io.opentelemetry.api.incubator.common.ExtendedAttributes attributes) { if (attributes.isEmpty()) { return EMPTY_REPEATED; } KeyValueMarshaler[] marshalers = new KeyValueMarshaler[attributes.size()]; attributes.forEach( - new BiConsumer, Object>() { + new BiConsumer, Object>() { int index = 0; @Override - public void accept(ExtendedAttributeKey attributeKey, Object o) { + public void accept( + io.opentelemetry.api.incubator.common.ExtendedAttributeKey attributeKey, + Object o) { marshalers[index++] = create(attributeKey, o); } }); @@ -82,8 +84,9 @@ public void accept(ExtendedAttributeKey attributeKey, Object o) { // TODO(jack-berg): move to KeyValueMarshaler when ExtendedAttributes is stable // Supporting deprecated EXTENDED_ATTRIBUTES type until removed - @SuppressWarnings({"unchecked", "deprecation"}) - private static KeyValueMarshaler create(ExtendedAttributeKey attributeKey, Object value) { + @SuppressWarnings("unchecked") + private static KeyValueMarshaler create( + io.opentelemetry.api.incubator.common.ExtendedAttributeKey attributeKey, Object value) { byte[] keyUtf8; if (attributeKey.getKey().isEmpty()) { keyUtf8 = EMPTY_BYTES; @@ -117,7 +120,8 @@ private static KeyValueMarshaler create(ExtendedAttributeKey attributeKey, Ob keyUtf8, new KeyValueListAnyValueMarshaler( new KeyValueListAnyValueMarshaler.KeyValueListMarshaler( - createForExtendedAttributes((ExtendedAttributes) value)))); + createForExtendedAttributes( + (io.opentelemetry.api.incubator.common.ExtendedAttributes) value)))); case VALUE: return new KeyValueMarshaler(keyUtf8, AnyValueMarshaler.create((Value) value)); } @@ -137,7 +141,8 @@ public static void serializeExtendedAttributes( output, LogRecord.ATTRIBUTES, getExtendedAttributes(log), context); } - private static ExtendedAttributes getExtendedAttributes(LogRecordData logRecordData) { + private static io.opentelemetry.api.incubator.common.ExtendedAttributes getExtendedAttributes( + LogRecordData logRecordData) { if (!(logRecordData instanceof ExtendedLogRecordData)) { throw new IllegalArgumentException("logRecordData must be ExtendedLogRecordData"); } diff --git a/exporters/otlp/common/src/testIncubating/java/io/opentelemetry/exporter/internal/otlp/logs/LogsRequestMarshalerIncubatingTest.java b/exporters/otlp/common/src/testIncubating/java/io/opentelemetry/exporter/internal/otlp/logs/LogsRequestMarshalerIncubatingTest.java index 84639db8312..56f1107e47a 100644 --- a/exporters/otlp/common/src/testIncubating/java/io/opentelemetry/exporter/internal/otlp/logs/LogsRequestMarshalerIncubatingTest.java +++ b/exporters/otlp/common/src/testIncubating/java/io/opentelemetry/exporter/internal/otlp/logs/LogsRequestMarshalerIncubatingTest.java @@ -14,8 +14,6 @@ import com.google.protobuf.util.JsonFormat; import io.opentelemetry.api.common.Attributes; import io.opentelemetry.api.common.Value; -import io.opentelemetry.api.incubator.common.ExtendedAttributeKey; -import io.opentelemetry.api.incubator.common.ExtendedAttributes; import io.opentelemetry.api.internal.OtelEncodingUtils; import io.opentelemetry.api.logs.Severity; import io.opentelemetry.api.trace.SpanContext; @@ -99,7 +97,7 @@ void toProtoLogRecord(MarshalerSource marshalerSource) { // Extended fields .setEventName(EVENT_NAME) .setExtendedAttributes( - ExtendedAttributes.builder() + io.opentelemetry.api.incubator.common.ExtendedAttributes.builder() .put("str_key", "str_value") .put("str_arr_key", "str_value1", "str_value2") .put("bool_key", true) @@ -110,19 +108,21 @@ void toProtoLogRecord(MarshalerSource marshalerSource) { .put("int_arr_key", 1, 2) .put( "kv_list_key", - ExtendedAttributes.builder() + io.opentelemetry.api.incubator.common.ExtendedAttributes.builder() .put("bool_key", true) .put("double_key", 1.1) .put("int_key", 1) .put( "kv_list_key", - ExtendedAttributes.builder() + io.opentelemetry.api.incubator.common.ExtendedAttributes + .builder() .put("str_key", "str_value") .build()) .put("str_key", "str_value") .build()) .put( - ExtendedAttributeKey.valueKey("value_key"), + io.opentelemetry.api.incubator.common.ExtendedAttributeKey.valueKey( + "value_key"), Value.of( io.opentelemetry.api.common.KeyValue.of( "bool_key", Value.of(true)), diff --git a/sdk/common/src/main/java/io/opentelemetry/sdk/common/internal/ExtendedAttributesMap.java b/sdk/common/src/main/java/io/opentelemetry/sdk/common/internal/ExtendedAttributesMap.java index 0adefdb6216..9c5ed61d3cc 100644 --- a/sdk/common/src/main/java/io/opentelemetry/sdk/common/internal/ExtendedAttributesMap.java +++ b/sdk/common/src/main/java/io/opentelemetry/sdk/common/internal/ExtendedAttributesMap.java @@ -6,9 +6,6 @@ package io.opentelemetry.sdk.common.internal; import io.opentelemetry.api.common.Attributes; -import io.opentelemetry.api.incubator.common.ExtendedAttributeKey; -import io.opentelemetry.api.incubator.common.ExtendedAttributes; -import io.opentelemetry.api.incubator.common.ExtendedAttributesBuilder; import java.util.Collections; import java.util.HashMap; import java.util.Map; @@ -19,13 +16,16 @@ * A map with a fixed capacity that drops attributes when the map gets full, and which truncates * string and array string attribute values to the {@link #lengthLimit}. * - *

    {@link ExtendedAttributes} analog of {@link AttributesMap}. + *

    {@link io.opentelemetry.api.incubator.common.ExtendedAttributes} analog of {@link + * AttributesMap}. * *

    This class is internal and is hence not for public use. Its APIs are unstable and can change * at any time. */ -public final class ExtendedAttributesMap extends HashMap, Object> - implements ExtendedAttributes { +@SuppressWarnings("deprecation") +public final class ExtendedAttributesMap + extends HashMap, Object> + implements io.opentelemetry.api.incubator.common.ExtendedAttributes { private static final long serialVersionUID = -2674974862318200501L; @@ -51,7 +51,8 @@ public static ExtendedAttributesMap create(long capacity, int lengthLimit) { /** Add the attribute key value pair, applying capacity and length limits. */ @Override @Nullable - public Object put(ExtendedAttributeKey key, @Nullable Object value) { + public Object put( + io.opentelemetry.api.incubator.common.ExtendedAttributeKey key, @Nullable Object value) { if (value == null) { return null; } @@ -62,7 +63,8 @@ public Object put(ExtendedAttributeKey key, @Nullable Object value) { return super.put(key, AttributeUtil.applyAttributeLengthLimit(value, lengthLimit)); } - public void putIfCapacity(ExtendedAttributeKey key, @Nullable T value) { + public void putIfCapacity( + io.opentelemetry.api.incubator.common.ExtendedAttributeKey key, @Nullable T value) { put(key, value); } @@ -76,12 +78,12 @@ public int getTotalAddedValues() { @SuppressWarnings("unchecked") @Nullable @Override - public T get(ExtendedAttributeKey key) { + public T get(io.opentelemetry.api.incubator.common.ExtendedAttributeKey key) { return (T) super.get(key); } @Override - public Map, Object> asMap() { + public Map, Object> asMap() { // Because ExtendedAttributes is marked Immutable, IDEs may recognize this as redundant usage. // However, this class is private and is actually mutable, so we need to wrap with // unmodifiableMap anyways. We implement the immutable ExtendedAttributes for this class to @@ -91,12 +93,15 @@ public Map, Object> asMap() { } @Override - public ExtendedAttributesBuilder toBuilder() { - return ExtendedAttributes.builder().putAll(this); + public io.opentelemetry.api.incubator.common.ExtendedAttributesBuilder toBuilder() { + return io.opentelemetry.api.incubator.common.ExtendedAttributes.builder().putAll(this); } @Override - public void forEach(BiConsumer, ? super Object> action) { + public void forEach( + BiConsumer< + ? super io.opentelemetry.api.incubator.common.ExtendedAttributeKey, ? super Object> + action) { // https://github.com/open-telemetry/opentelemetry-java/issues/4161 // Help out android desugaring by having an explicit call to HashMap.forEach, when forEach is // just called through ExtendedAttributes.forEach desugaring is unable to correctly handle it. @@ -121,7 +126,7 @@ public String toString() { } /** Create an immutable copy of the extended attributes in this map. */ - public ExtendedAttributes immutableCopy() { - return ExtendedAttributes.builder().putAll(this).build(); + public io.opentelemetry.api.incubator.common.ExtendedAttributes immutableCopy() { + return io.opentelemetry.api.incubator.common.ExtendedAttributes.builder().putAll(this).build(); } } diff --git a/sdk/common/src/test/java/io/opentelemetry/sdk/common/internal/ExtendedAttributesValueTest.java b/sdk/common/src/test/java/io/opentelemetry/sdk/common/internal/ExtendedAttributesValueTest.java index 4d71f27394a..6a5eaae7cc3 100644 --- a/sdk/common/src/test/java/io/opentelemetry/sdk/common/internal/ExtendedAttributesValueTest.java +++ b/sdk/common/src/test/java/io/opentelemetry/sdk/common/internal/ExtendedAttributesValueTest.java @@ -9,11 +9,11 @@ import io.opentelemetry.api.common.KeyValue; import io.opentelemetry.api.common.Value; -import io.opentelemetry.api.incubator.common.ExtendedAttributeKey; import java.nio.ByteBuffer; import java.util.List; import org.junit.jupiter.api.Test; +@SuppressWarnings("deprecation") class ExtendedAttributesValueTest { @Test @@ -22,9 +22,10 @@ void put_ByteArrayTruncation() { byte[] bytes = new byte[] {1, 2, 3, 4, 5, 6, 7, 8, 9, 10}; Value value = Value.of(bytes); - map.put(ExtendedAttributeKey.valueKey("key"), value); + map.put(io.opentelemetry.api.incubator.common.ExtendedAttributeKey.valueKey("key"), value); - Value result = map.get(ExtendedAttributeKey.valueKey("key")); + Value result = + map.get(io.opentelemetry.api.incubator.common.ExtendedAttributeKey.valueKey("key")); ByteBuffer buffer = (ByteBuffer) result.getValue(); byte[] resultBytes = new byte[buffer.remaining()]; buffer.get(resultBytes); @@ -37,9 +38,10 @@ void put_ValueArrayTruncation() { Value arrayValue = Value.of(Value.of("short"), Value.of("this is too long")); - map.put(ExtendedAttributeKey.valueKey("key"), arrayValue); + map.put(io.opentelemetry.api.incubator.common.ExtendedAttributeKey.valueKey("key"), arrayValue); - Value result = map.get(ExtendedAttributeKey.valueKey("key")); + Value result = + map.get(io.opentelemetry.api.incubator.common.ExtendedAttributeKey.valueKey("key")); @SuppressWarnings("unchecked") List> resultList = (List>) result.getValue(); assertThat(resultList).hasSize(2); @@ -56,9 +58,11 @@ void put_ValueKeyValueListTruncation() { KeyValue.of("key1", Value.of("short")), KeyValue.of("key2", Value.of("this is too long"))); - map.put(ExtendedAttributeKey.valueKey("key"), kvListValue); + map.put( + io.opentelemetry.api.incubator.common.ExtendedAttributeKey.valueKey("key"), kvListValue); - Value result = map.get(ExtendedAttributeKey.valueKey("key")); + Value result = + map.get(io.opentelemetry.api.incubator.common.ExtendedAttributeKey.valueKey("key")); @SuppressWarnings("unchecked") List resultList = (List) result.getValue(); assertThat(resultList).hasSize(2); diff --git a/sdk/logs/build.gradle.kts b/sdk/logs/build.gradle.kts index b205b03e90e..62de7b3a136 100644 --- a/sdk/logs/build.gradle.kts +++ b/sdk/logs/build.gradle.kts @@ -39,4 +39,10 @@ tasks { check { dependsOn(testing.suites) } + // ExtendedSdkLogRecordData generated AutoValue class imports deprecated ExtendedAttributes. + // @SuppressWarnings can't suppress import statement warnings. + // TODO: remove after removing ExtendedAttributes + named("compileJava") { + options.compilerArgs.add("-Xlint:-deprecation") + } } diff --git a/sdk/logs/src/main/java/io/opentelemetry/sdk/logs/ExtendedSdkLogRecordBuilder.java b/sdk/logs/src/main/java/io/opentelemetry/sdk/logs/ExtendedSdkLogRecordBuilder.java index 53818c7155c..6c41c3069c9 100644 --- a/sdk/logs/src/main/java/io/opentelemetry/sdk/logs/ExtendedSdkLogRecordBuilder.java +++ b/sdk/logs/src/main/java/io/opentelemetry/sdk/logs/ExtendedSdkLogRecordBuilder.java @@ -7,7 +7,6 @@ import io.opentelemetry.api.common.AttributeKey; import io.opentelemetry.api.common.Value; -import io.opentelemetry.api.incubator.common.ExtendedAttributeKey; import io.opentelemetry.api.incubator.logs.ExtendedLogRecordBuilder; import io.opentelemetry.api.logs.Severity; import io.opentelemetry.api.trace.Span; @@ -19,6 +18,7 @@ import javax.annotation.Nullable; /** SDK implementation of {@link ExtendedLogRecordBuilder}. */ +@SuppressWarnings("deprecation") final class ExtendedSdkLogRecordBuilder extends SdkLogRecordBuilder implements ExtendedLogRecordBuilder { @@ -108,7 +108,8 @@ public ExtendedSdkLogRecordBuilder setBody(Value value) { } @Override - public ExtendedSdkLogRecordBuilder setAttribute(ExtendedAttributeKey key, T value) { + public ExtendedSdkLogRecordBuilder setAttribute( + io.opentelemetry.api.incubator.common.ExtendedAttributeKey key, T value) { if (key == null || key.getKey().isEmpty() || value == null) { return this; } @@ -126,7 +127,8 @@ public ExtendedSdkLogRecordBuilder setAttribute(AttributeKey key, @Nullab if (key == null || key.getKey().isEmpty() || value == null) { return this; } - return setAttribute(ExtendedAttributeKey.fromAttributeKey(key), value); + return setAttribute( + io.opentelemetry.api.incubator.common.ExtendedAttributeKey.fromAttributeKey(key), value); } @Override diff --git a/sdk/logs/src/main/java/io/opentelemetry/sdk/logs/ExtendedSdkLogRecordData.java b/sdk/logs/src/main/java/io/opentelemetry/sdk/logs/ExtendedSdkLogRecordData.java index 2daa873793e..03d05bf9056 100644 --- a/sdk/logs/src/main/java/io/opentelemetry/sdk/logs/ExtendedSdkLogRecordData.java +++ b/sdk/logs/src/main/java/io/opentelemetry/sdk/logs/ExtendedSdkLogRecordData.java @@ -7,7 +7,6 @@ import com.google.auto.value.AutoValue; import io.opentelemetry.api.common.Value; -import io.opentelemetry.api.incubator.common.ExtendedAttributes; import io.opentelemetry.api.logs.Severity; import io.opentelemetry.api.trace.SpanContext; import io.opentelemetry.sdk.common.InstrumentationScopeInfo; @@ -20,6 +19,7 @@ @AutoValue @AutoValue.CopyAnnotations @Immutable +@SuppressWarnings("deprecation") abstract class ExtendedSdkLogRecordData implements ExtendedLogRecordData { ExtendedSdkLogRecordData() {} @@ -34,7 +34,7 @@ static ExtendedSdkLogRecordData create( Severity severity, @Nullable String severityText, @Nullable Value body, - ExtendedAttributes attributes, + io.opentelemetry.api.incubator.common.ExtendedAttributes attributes, int totalAttributeCount) { return new AutoValue_ExtendedSdkLogRecordData( resource, diff --git a/sdk/logs/src/main/java/io/opentelemetry/sdk/logs/ExtendedSdkReadWriteLogRecord.java b/sdk/logs/src/main/java/io/opentelemetry/sdk/logs/ExtendedSdkReadWriteLogRecord.java index daf4ab359ef..2d740be37f0 100644 --- a/sdk/logs/src/main/java/io/opentelemetry/sdk/logs/ExtendedSdkReadWriteLogRecord.java +++ b/sdk/logs/src/main/java/io/opentelemetry/sdk/logs/ExtendedSdkReadWriteLogRecord.java @@ -8,8 +8,6 @@ import io.opentelemetry.api.common.AttributeKey; import io.opentelemetry.api.common.Attributes; import io.opentelemetry.api.common.Value; -import io.opentelemetry.api.incubator.common.ExtendedAttributeKey; -import io.opentelemetry.api.incubator.common.ExtendedAttributes; import io.opentelemetry.api.internal.GuardedBy; import io.opentelemetry.api.logs.Severity; import io.opentelemetry.api.trace.SpanContext; @@ -22,6 +20,7 @@ import javax.annotation.concurrent.ThreadSafe; @ThreadSafe +@SuppressWarnings("deprecation") class ExtendedSdkReadWriteLogRecord extends SdkReadWriteLogRecord implements ExtendedReadWriteLogRecord { @@ -91,11 +90,13 @@ public ExtendedSdkReadWriteLogRecord setAttribute(AttributeKey key, T val if (key == null || key.getKey().isEmpty() || value == null) { return this; } - return setAttribute(ExtendedAttributeKey.fromAttributeKey(key), value); + return setAttribute( + io.opentelemetry.api.incubator.common.ExtendedAttributeKey.fromAttributeKey(key), value); } @Override - public ExtendedSdkReadWriteLogRecord setAttribute(ExtendedAttributeKey key, T value) { + public ExtendedSdkReadWriteLogRecord setAttribute( + io.opentelemetry.api.incubator.common.ExtendedAttributeKey key, T value) { if (key == null || key.getKey().isEmpty() || value == null) { return this; } @@ -110,10 +111,11 @@ public ExtendedSdkReadWriteLogRecord setAttribute(ExtendedAttributeKey ke return this; } - private ExtendedAttributes getImmutableExtendedAttributes() { + private io.opentelemetry.api.incubator.common.ExtendedAttributes + getImmutableExtendedAttributes() { synchronized (lock) { if (extendedAttributes == null) { - return ExtendedAttributes.empty(); + return io.opentelemetry.api.incubator.common.ExtendedAttributes.empty(); } return extendedAttributes.immutableCopy(); } @@ -145,12 +147,13 @@ public Attributes getAttributes() { @Nullable @Override public T getAttribute(AttributeKey key) { - return getAttribute(ExtendedAttributeKey.fromAttributeKey(key)); + return getAttribute( + io.opentelemetry.api.incubator.common.ExtendedAttributeKey.fromAttributeKey(key)); } @Nullable @Override - public T getAttribute(ExtendedAttributeKey key) { + public T getAttribute(io.opentelemetry.api.incubator.common.ExtendedAttributeKey key) { synchronized (lock) { if (extendedAttributes == null || extendedAttributes.isEmpty()) { return null; @@ -160,7 +163,7 @@ public T getAttribute(ExtendedAttributeKey key) { } @Override - public ExtendedAttributes getExtendedAttributes() { + public io.opentelemetry.api.incubator.common.ExtendedAttributes getExtendedAttributes() { return getImmutableExtendedAttributes(); } } diff --git a/sdk/logs/src/main/java/io/opentelemetry/sdk/logs/data/internal/ExtendedLogRecordData.java b/sdk/logs/src/main/java/io/opentelemetry/sdk/logs/data/internal/ExtendedLogRecordData.java index 65710807321..47642cc4c48 100644 --- a/sdk/logs/src/main/java/io/opentelemetry/sdk/logs/data/internal/ExtendedLogRecordData.java +++ b/sdk/logs/src/main/java/io/opentelemetry/sdk/logs/data/internal/ExtendedLogRecordData.java @@ -6,7 +6,6 @@ package io.opentelemetry.sdk.logs.data.internal; import io.opentelemetry.api.common.Attributes; -import io.opentelemetry.api.incubator.common.ExtendedAttributes; import io.opentelemetry.sdk.logs.data.LogRecordData; /** @@ -14,10 +13,14 @@ * APIs (or a version of them) may be promoted to the public stable API in the future, but no * guarantees are made. */ +@SuppressWarnings("deprecation") public interface ExtendedLogRecordData extends LogRecordData { - /** Returns the attributes for this log, or {@link ExtendedAttributes#empty()} if unset. */ - ExtendedAttributes getExtendedAttributes(); + /** + * Returns the attributes for this log, or {@link + * io.opentelemetry.api.incubator.common.ExtendedAttributes#empty()} if unset. + */ + io.opentelemetry.api.incubator.common.ExtendedAttributes getExtendedAttributes(); /** * Returns the attributes for this log, or {@link Attributes#empty()} if unset. diff --git a/sdk/logs/src/main/java/io/opentelemetry/sdk/logs/internal/ExtendedReadWriteLogRecord.java b/sdk/logs/src/main/java/io/opentelemetry/sdk/logs/internal/ExtendedReadWriteLogRecord.java index 527c1e14063..c3137c76f19 100644 --- a/sdk/logs/src/main/java/io/opentelemetry/sdk/logs/internal/ExtendedReadWriteLogRecord.java +++ b/sdk/logs/src/main/java/io/opentelemetry/sdk/logs/internal/ExtendedReadWriteLogRecord.java @@ -5,8 +5,6 @@ package io.opentelemetry.sdk.logs.internal; -import io.opentelemetry.api.incubator.common.ExtendedAttributeKey; -import io.opentelemetry.api.incubator.common.ExtendedAttributes; import io.opentelemetry.sdk.logs.ReadWriteLogRecord; import io.opentelemetry.sdk.logs.data.internal.ExtendedLogRecordData; import javax.annotation.Nullable; @@ -19,6 +17,7 @@ * APIs (or a version of them) may be promoted to the public stable API in the future, but no * guarantees are made. */ +@SuppressWarnings("deprecation") public interface ExtendedReadWriteLogRecord extends ReadWriteLogRecord { /** @@ -27,7 +26,8 @@ public interface ExtendedReadWriteLogRecord extends ReadWriteLogRecord { * *

    Note: the behavior of null values is undefined, and hence strongly discouraged. */ - ExtendedReadWriteLogRecord setAttribute(ExtendedAttributeKey key, T value); + ExtendedReadWriteLogRecord setAttribute( + io.opentelemetry.api.incubator.common.ExtendedAttributeKey key, T value); /** * Sets attributes to the {@link ReadWriteLogRecord}. If the {@link ReadWriteLogRecord} previously @@ -37,13 +37,16 @@ public interface ExtendedReadWriteLogRecord extends ReadWriteLogRecord { * @return this. */ @SuppressWarnings("unchecked") - default ExtendedReadWriteLogRecord setAllAttributes(ExtendedAttributes extendedAttributes) { + default ExtendedReadWriteLogRecord setAllAttributes( + io.opentelemetry.api.incubator.common.ExtendedAttributes extendedAttributes) { if (extendedAttributes == null || extendedAttributes.isEmpty()) { return this; } extendedAttributes.forEach( (attributeKey, value) -> - this.setAttribute((ExtendedAttributeKey) attributeKey, value)); + this.setAttribute( + (io.opentelemetry.api.incubator.common.ExtendedAttributeKey) attributeKey, + value)); return this; } @@ -56,8 +59,11 @@ default ExtendedReadWriteLogRecord setAllAttributes(ExtendedAttributes extendedA * getAttributes().get(key) */ @Nullable - T getAttribute(ExtendedAttributeKey key); + T getAttribute(io.opentelemetry.api.incubator.common.ExtendedAttributeKey key); - /** Returns the attributes for this log, or {@link ExtendedAttributes#empty()} if unset. */ - ExtendedAttributes getExtendedAttributes(); + /** + * Returns the attributes for this log, or {@link + * io.opentelemetry.api.incubator.common.ExtendedAttributes#empty()} if unset. + */ + io.opentelemetry.api.incubator.common.ExtendedAttributes getExtendedAttributes(); } diff --git a/sdk/testing/build.gradle.kts b/sdk/testing/build.gradle.kts index 44bbcad90d8..247e83aedb8 100644 --- a/sdk/testing/build.gradle.kts +++ b/sdk/testing/build.gradle.kts @@ -32,3 +32,12 @@ testing { } } } + +tasks { + // TestExtendedLogRecordData generated AutoValue class imports deprecated ExtendedAttributes. + // @SuppressWarnings can't suppress import statement warnings. + // TODO: remove after removing ExtendedAttributes + named("compileJava") { + options.compilerArgs.add("-Xlint:-deprecation") + } +} diff --git a/sdk/testing/src/main/java/io/opentelemetry/sdk/testing/logs/internal/TestExtendedLogRecordData.java b/sdk/testing/src/main/java/io/opentelemetry/sdk/testing/logs/internal/TestExtendedLogRecordData.java index 44fe6bf6bfa..6bb4257e861 100644 --- a/sdk/testing/src/main/java/io/opentelemetry/sdk/testing/logs/internal/TestExtendedLogRecordData.java +++ b/sdk/testing/src/main/java/io/opentelemetry/sdk/testing/logs/internal/TestExtendedLogRecordData.java @@ -8,7 +8,6 @@ import com.google.auto.value.AutoValue; import io.opentelemetry.api.common.Attributes; import io.opentelemetry.api.common.Value; -import io.opentelemetry.api.incubator.common.ExtendedAttributes; import io.opentelemetry.api.logs.Severity; import io.opentelemetry.api.trace.SpanContext; import io.opentelemetry.sdk.common.InstrumentationScopeInfo; @@ -188,13 +187,17 @@ public Builder setBody(Body body) { /** Set the attributes. */ public Builder setAttributes(Attributes attributes) { - return setExtendedAttributes(ExtendedAttributes.builder().putAll(attributes).build()); + return setExtendedAttributes( + io.opentelemetry.api.incubator.common.ExtendedAttributes.builder() + .putAll(attributes) + .build()); } /** Set the total attribute count. */ public abstract Builder setTotalAttributeCount(int totalAttributeCount); /** Set extended attributes. * */ - public abstract Builder setExtendedAttributes(ExtendedAttributes extendedAttributes); + public abstract Builder setExtendedAttributes( + io.opentelemetry.api.incubator.common.ExtendedAttributes extendedAttributes); } } From 385b0a6fbc0069ddd32c28bd40eef59d7e427d34 Mon Sep 17 00:00:00 2001 From: Trask Stalnaker Date: Fri, 13 Feb 2026 09:04:13 -0800 Subject: [PATCH 3/3] remove noise --- .../InternalExtendedAttributeKeyImpl.java | 64 +++++++------------ .../incubator/logs/ExtendedDefaultLogger.java | 4 +- .../logs/ExtendedLogRecordBuilder.java | 45 ++++++------- .../logs/ExtendedLogsBridgeApiUsageTest.java | 16 ++--- ...edAttributeKeyValueStatelessMarshaler.java | 54 ++++++---------- .../internal/otlp/IncubatingUtil.java | 20 +++--- .../LogsRequestMarshalerIncubatingTest.java | 12 ++-- .../internal/ExtendedAttributesMap.java | 34 +++++----- .../internal/ExtendedAttributesValueTest.java | 17 ++--- .../sdk/logs/ExtendedSdkLogRecordBuilder.java | 7 +- .../sdk/logs/ExtendedSdkLogRecordData.java | 3 +- .../logs/ExtendedSdkReadWriteLogRecord.java | 20 +++--- .../data/internal/ExtendedLogRecordData.java | 8 +-- .../internal/ExtendedReadWriteLogRecord.java | 21 +++--- .../internal/TestExtendedLogRecordData.java | 9 +-- 15 files changed, 139 insertions(+), 195 deletions(-) diff --git a/api/incubator/src/main/java/io/opentelemetry/api/incubator/internal/InternalExtendedAttributeKeyImpl.java b/api/incubator/src/main/java/io/opentelemetry/api/incubator/internal/InternalExtendedAttributeKeyImpl.java index 1ab91765a35..a4ea4acd059 100644 --- a/api/incubator/src/main/java/io/opentelemetry/api/incubator/internal/InternalExtendedAttributeKeyImpl.java +++ b/api/incubator/src/main/java/io/opentelemetry/api/incubator/internal/InternalExtendedAttributeKeyImpl.java @@ -7,6 +7,8 @@ import io.opentelemetry.api.common.AttributeKey; import io.opentelemetry.api.common.AttributeType; +import io.opentelemetry.api.incubator.common.ExtendedAttributeKey; +import io.opentelemetry.api.incubator.common.ExtendedAttributeType; import io.opentelemetry.api.internal.InternalAttributeKeyImpl; import java.nio.charset.StandardCharsets; import javax.annotation.Nullable; @@ -16,18 +18,16 @@ * any time. */ @SuppressWarnings("deprecation") -public final class InternalExtendedAttributeKeyImpl - implements io.opentelemetry.api.incubator.common.ExtendedAttributeKey { +public final class InternalExtendedAttributeKeyImpl implements ExtendedAttributeKey { - private final io.opentelemetry.api.incubator.common.ExtendedAttributeType type; + private final ExtendedAttributeType type; private final String key; private final int hashCode; @Nullable private byte[] keyUtf8; @Nullable private AttributeKey attributeKey; - private InternalExtendedAttributeKeyImpl( - io.opentelemetry.api.incubator.common.ExtendedAttributeType type, String key) { + private InternalExtendedAttributeKeyImpl(ExtendedAttributeType type, String key) { if (type == null) { throw new NullPointerException("Null type"); } @@ -39,13 +39,13 @@ private InternalExtendedAttributeKeyImpl( this.hashCode = buildHashCode(type, key); } - public static io.opentelemetry.api.incubator.common.ExtendedAttributeKey create( - @Nullable String key, io.opentelemetry.api.incubator.common.ExtendedAttributeType type) { + public static ExtendedAttributeKey create( + @Nullable String key, ExtendedAttributeType type) { return new InternalExtendedAttributeKeyImpl<>(type, key != null ? key : ""); } @Override - public io.opentelemetry.api.incubator.common.ExtendedAttributeType getType() { + public ExtendedAttributeType getType() { return type; } @@ -101,8 +101,7 @@ private int buildHashCode() { return buildHashCode(type, key); } - private static int buildHashCode( - io.opentelemetry.api.incubator.common.ExtendedAttributeType type, String key) { + private static int buildHashCode(ExtendedAttributeType type, String key) { int result = 1; result *= 1000003; result ^= type.hashCode(); @@ -112,13 +111,12 @@ private static int buildHashCode( } /** - * Return the equivalent {@link AttributeKey} for the {@link - * io.opentelemetry.api.incubator.common.ExtendedAttributeKey}, or {@code null} if the {@link - * #getType()} has no equivalent {@link io.opentelemetry.api.common.AttributeType}. + * Return the equivalent {@link AttributeKey} for the {@link ExtendedAttributeKey}, or {@code + * null} if the {@link #getType()} has no equivalent {@link + * io.opentelemetry.api.common.AttributeType}. */ @Nullable - public static AttributeKey toAttributeKey( - io.opentelemetry.api.incubator.common.ExtendedAttributeKey extendedAttributeKey) { + public static AttributeKey toAttributeKey(ExtendedAttributeKey extendedAttributeKey) { switch (extendedAttributeKey.getType()) { case STRING: return InternalAttributeKeyImpl.create(extendedAttributeKey.getKey(), AttributeType.STRING); @@ -150,50 +148,36 @@ public static AttributeKey toAttributeKey( "Unrecognized extendedAttributeKey type: " + extendedAttributeKey.getType()); } - /** - * Return the equivalent {@link io.opentelemetry.api.incubator.common.ExtendedAttributeKey} for - * the {@link AttributeKey}. - */ - public static - io.opentelemetry.api.incubator.common.ExtendedAttributeKey toExtendedAttributeKey( - AttributeKey attributeKey) { + /** Return the equivalent {@link ExtendedAttributeKey} for the {@link AttributeKey}. */ + public static ExtendedAttributeKey toExtendedAttributeKey(AttributeKey attributeKey) { switch (attributeKey.getType()) { case STRING: return InternalExtendedAttributeKeyImpl.create( - attributeKey.getKey(), - io.opentelemetry.api.incubator.common.ExtendedAttributeType.STRING); + attributeKey.getKey(), ExtendedAttributeType.STRING); case BOOLEAN: return InternalExtendedAttributeKeyImpl.create( - attributeKey.getKey(), - io.opentelemetry.api.incubator.common.ExtendedAttributeType.BOOLEAN); + attributeKey.getKey(), ExtendedAttributeType.BOOLEAN); case LONG: return InternalExtendedAttributeKeyImpl.create( - attributeKey.getKey(), - io.opentelemetry.api.incubator.common.ExtendedAttributeType.LONG); + attributeKey.getKey(), ExtendedAttributeType.LONG); case DOUBLE: return InternalExtendedAttributeKeyImpl.create( - attributeKey.getKey(), - io.opentelemetry.api.incubator.common.ExtendedAttributeType.DOUBLE); + attributeKey.getKey(), ExtendedAttributeType.DOUBLE); case STRING_ARRAY: return InternalExtendedAttributeKeyImpl.create( - attributeKey.getKey(), - io.opentelemetry.api.incubator.common.ExtendedAttributeType.STRING_ARRAY); + attributeKey.getKey(), ExtendedAttributeType.STRING_ARRAY); case BOOLEAN_ARRAY: return InternalExtendedAttributeKeyImpl.create( - attributeKey.getKey(), - io.opentelemetry.api.incubator.common.ExtendedAttributeType.BOOLEAN_ARRAY); + attributeKey.getKey(), ExtendedAttributeType.BOOLEAN_ARRAY); case LONG_ARRAY: return InternalExtendedAttributeKeyImpl.create( - attributeKey.getKey(), - io.opentelemetry.api.incubator.common.ExtendedAttributeType.LONG_ARRAY); + attributeKey.getKey(), ExtendedAttributeType.LONG_ARRAY); case DOUBLE_ARRAY: return InternalExtendedAttributeKeyImpl.create( - attributeKey.getKey(), - io.opentelemetry.api.incubator.common.ExtendedAttributeType.DOUBLE_ARRAY); + attributeKey.getKey(), ExtendedAttributeType.DOUBLE_ARRAY); case VALUE: return InternalExtendedAttributeKeyImpl.create( - attributeKey.getKey(), - io.opentelemetry.api.incubator.common.ExtendedAttributeType.VALUE); + attributeKey.getKey(), ExtendedAttributeType.VALUE); } throw new IllegalArgumentException("Unrecognized attributeKey type: " + attributeKey.getType()); } diff --git a/api/incubator/src/main/java/io/opentelemetry/api/incubator/logs/ExtendedDefaultLogger.java b/api/incubator/src/main/java/io/opentelemetry/api/incubator/logs/ExtendedDefaultLogger.java index 0984d9bcd60..77b7970ecf0 100644 --- a/api/incubator/src/main/java/io/opentelemetry/api/incubator/logs/ExtendedDefaultLogger.java +++ b/api/incubator/src/main/java/io/opentelemetry/api/incubator/logs/ExtendedDefaultLogger.java @@ -7,6 +7,7 @@ import io.opentelemetry.api.common.AttributeKey; import io.opentelemetry.api.common.Value; +import io.opentelemetry.api.incubator.common.ExtendedAttributeKey; import io.opentelemetry.api.logs.Logger; import io.opentelemetry.api.logs.Severity; import io.opentelemetry.context.Context; @@ -52,8 +53,7 @@ public ExtendedLogRecordBuilder setException(Throwable throwable) { } @Override - public ExtendedLogRecordBuilder setAttribute( - io.opentelemetry.api.incubator.common.ExtendedAttributeKey key, T value) { + public ExtendedLogRecordBuilder setAttribute(ExtendedAttributeKey key, T value) { return this; } diff --git a/api/incubator/src/main/java/io/opentelemetry/api/incubator/logs/ExtendedLogRecordBuilder.java b/api/incubator/src/main/java/io/opentelemetry/api/incubator/logs/ExtendedLogRecordBuilder.java index 3dd6dd0b7c3..1e1f0872cbd 100644 --- a/api/incubator/src/main/java/io/opentelemetry/api/incubator/logs/ExtendedLogRecordBuilder.java +++ b/api/incubator/src/main/java/io/opentelemetry/api/incubator/logs/ExtendedLogRecordBuilder.java @@ -8,6 +8,8 @@ import io.opentelemetry.api.common.AttributeKey; import io.opentelemetry.api.common.Attributes; import io.opentelemetry.api.common.Value; +import io.opentelemetry.api.incubator.common.ExtendedAttributeKey; +import io.opentelemetry.api.incubator.common.ExtendedAttributes; import io.opentelemetry.api.logs.LogRecordBuilder; import io.opentelemetry.api.logs.Severity; import io.opentelemetry.context.Context; @@ -73,10 +75,10 @@ default ExtendedLogRecordBuilder setBody(Value body) { * {@inheritDoc} * *

    NOTE: all standard {@link AttributeKey}-value pairs can also be represented as {@link - * io.opentelemetry.api.incubator.common.ExtendedAttributeKey}-value pairs, but not all {@link - * io.opentelemetry.api.incubator.common.ExtendedAttributeKey}-value pairs can be represented as - * standard {@link AttributeKey}-value pairs. From the standpoint of the emitted log record, there - * is no difference between adding attributes using the standard or extended attribute APIs. + * ExtendedAttributeKey}-value pairs, but not all {@link ExtendedAttributeKey}-value pairs can be + * represented as standard {@link AttributeKey}-value pairs. From the standpoint of the emitted + * log record, there is no difference between adding attributes using the standard or extended + * attribute APIs. */ @SuppressWarnings("unchecked") @Override @@ -94,22 +96,18 @@ default ExtendedLogRecordBuilder setAllAttributes(Attributes attributes) { * keys, the old values are replaced by the specified values. * *

    NOTE: all standard {@link AttributeKey}-value pairs can also be represented as {@link - * io.opentelemetry.api.incubator.common.ExtendedAttributeKey}-value pairs, but not all {@link - * io.opentelemetry.api.incubator.common.ExtendedAttributeKey}-value pairs can be represented as - * standard {@link AttributeKey}-value pairs. From the standpoint of the emitted log record, there - * is no difference between adding attributes using the standard or extended attribute APIs. + * ExtendedAttributeKey}-value pairs, but not all {@link ExtendedAttributeKey}-value pairs can be + * represented as standard {@link AttributeKey}-value pairs. From the standpoint of the emitted + * log record, there is no difference between adding attributes using the standard or extended + * attribute APIs. */ @SuppressWarnings("unchecked") - default ExtendedLogRecordBuilder setAllAttributes( - io.opentelemetry.api.incubator.common.ExtendedAttributes attributes) { + default ExtendedLogRecordBuilder setAllAttributes(ExtendedAttributes attributes) { if (attributes == null || attributes.isEmpty()) { return this; } attributes.forEach( - (attributeKey, value) -> - setAttribute( - (io.opentelemetry.api.incubator.common.ExtendedAttributeKey) attributeKey, - value)); + (attributeKey, value) -> setAttribute((ExtendedAttributeKey) attributeKey, value)); return this; } @@ -117,10 +115,10 @@ default ExtendedLogRecordBuilder setAllAttributes( * {@inheritDoc} * *

    NOTE: all standard {@link AttributeKey}-value pairs can also be represented as {@link - * io.opentelemetry.api.incubator.common.ExtendedAttributeKey}-value pairs, but not all {@link - * io.opentelemetry.api.incubator.common.ExtendedAttributeKey}-value pairs can be represented as - * standard {@link AttributeKey}-value pairs. From the standpoint of the emitted log record, there - * is no difference between adding attributes using the standard or extended attribute APIs. + * ExtendedAttributeKey}-value pairs, but not all {@link ExtendedAttributeKey}-value pairs can be + * represented as standard {@link AttributeKey}-value pairs. From the standpoint of the emitted + * log record, there is no difference between adding attributes using the standard or extended + * attribute APIs. */ @Override ExtendedLogRecordBuilder setAttribute(AttributeKey key, @Nullable T value); @@ -129,13 +127,12 @@ default ExtendedLogRecordBuilder setAllAttributes( * Set an attribute. * *

    NOTE: all standard {@link AttributeKey}-value pairs can also be represented as {@link - * io.opentelemetry.api.incubator.common.ExtendedAttributeKey}-value pairs, but not all {@link - * io.opentelemetry.api.incubator.common.ExtendedAttributeKey}-value pairs can be represented as - * standard {@link AttributeKey}-value pairs. From the standpoint of the emitted log record, there - * is no difference between adding attributes using the standard or extended attribute APIs. + * ExtendedAttributeKey}-value pairs, but not all {@link ExtendedAttributeKey}-value pairs can be + * represented as standard {@link AttributeKey}-value pairs. From the standpoint of the emitted + * log record, there is no difference between adding attributes using the standard or extended + * attribute APIs. */ - ExtendedLogRecordBuilder setAttribute( - io.opentelemetry.api.incubator.common.ExtendedAttributeKey key, T value); + ExtendedLogRecordBuilder setAttribute(ExtendedAttributeKey key, T value); /** Set standard {@code exception.*} attributes based on the {@code throwable}. */ ExtendedLogRecordBuilder setException(Throwable throwable); diff --git a/api/incubator/src/test/java/io/opentelemetry/api/incubator/logs/ExtendedLogsBridgeApiUsageTest.java b/api/incubator/src/test/java/io/opentelemetry/api/incubator/logs/ExtendedLogsBridgeApiUsageTest.java index 0e82953e929..5837b5cda85 100644 --- a/api/incubator/src/test/java/io/opentelemetry/api/incubator/logs/ExtendedLogsBridgeApiUsageTest.java +++ b/api/incubator/src/test/java/io/opentelemetry/api/incubator/logs/ExtendedLogsBridgeApiUsageTest.java @@ -13,6 +13,8 @@ import io.opentelemetry.api.common.Attributes; import io.opentelemetry.api.common.KeyValue; import io.opentelemetry.api.common.Value; +import io.opentelemetry.api.incubator.common.ExtendedAttributeKey; +import io.opentelemetry.api.incubator.common.ExtendedAttributes; import io.opentelemetry.api.logs.Logger; import io.opentelemetry.api.logs.Severity; import io.opentelemetry.internal.testing.slf4j.SuppressLogger; @@ -105,16 +107,15 @@ private static String flipCoin() { AttributeKey> doubleArrKey = AttributeKey.doubleArrayKey("acme.double_array"); // VALUE key - io.opentelemetry.api.incubator.common.ExtendedAttributeKey> valueKey = - io.opentelemetry.api.incubator.common.ExtendedAttributeKey.valueKey("acme.value"); + ExtendedAttributeKey> valueKey = ExtendedAttributeKey.valueKey("acme.value"); @Test @SuppressLogger(ExtendedLogsBridgeApiUsageTest.class) void extendedAttributesUsage() { // Initialize from builder. Varargs style initialization (ExtendedAttributes.of(...) not // supported. - io.opentelemetry.api.incubator.common.ExtendedAttributes extendedAttributes = - io.opentelemetry.api.incubator.common.ExtendedAttributes.builder() + ExtendedAttributes extendedAttributes = + ExtendedAttributes.builder() .put(strKey, "value") .put(longKey, 1L) .put(booleanKey, true) @@ -191,10 +192,7 @@ void logRecordBuilder_ExtendedAttributes() { Value.of( KeyValue.of("childStr", Value.of("value")), KeyValue.of("childLong", Value.of(1L)))) .setAllAttributes(Attributes.builder().put("key1", "value").build()) - .setAllAttributes( - io.opentelemetry.api.incubator.common.ExtendedAttributes.builder() - .put("key2", "value") - .build()) + .setAllAttributes(ExtendedAttributes.builder().put("key2", "value").build()) .emit(); assertThat(exporter.getFinishedLogRecordItems()) @@ -228,7 +226,7 @@ void logRecordBuilder_ExtendedAttributes() { // But preferably access and serialize full extended attributes assertThat(extendedLogRecordData.getExtendedAttributes()) .isEqualTo( - io.opentelemetry.api.incubator.common.ExtendedAttributes.builder() + ExtendedAttributes.builder() .put(strKey, "value") .put(longKey, 1L) .put(booleanKey, true) diff --git a/exporters/otlp/common/src/main/java/io/opentelemetry/exporter/internal/otlp/ExtendedAttributeKeyValueStatelessMarshaler.java b/exporters/otlp/common/src/main/java/io/opentelemetry/exporter/internal/otlp/ExtendedAttributeKeyValueStatelessMarshaler.java index 06c2918faf6..704198c2474 100644 --- a/exporters/otlp/common/src/main/java/io/opentelemetry/exporter/internal/otlp/ExtendedAttributeKeyValueStatelessMarshaler.java +++ b/exporters/otlp/common/src/main/java/io/opentelemetry/exporter/internal/otlp/ExtendedAttributeKeyValueStatelessMarshaler.java @@ -6,6 +6,9 @@ package io.opentelemetry.exporter.internal.otlp; import io.opentelemetry.api.common.Value; +import io.opentelemetry.api.incubator.common.ExtendedAttributeKey; +import io.opentelemetry.api.incubator.common.ExtendedAttributeType; +import io.opentelemetry.api.incubator.common.ExtendedAttributes; import io.opentelemetry.api.incubator.internal.InternalExtendedAttributeKeyImpl; import io.opentelemetry.exporter.internal.marshal.CodedOutputStream; import io.opentelemetry.exporter.internal.marshal.MarshalerContext; @@ -24,16 +27,14 @@ import java.util.Objects; /** - * A Marshaler of {@link io.opentelemetry.api.incubator.common.ExtendedAttributes} key value pairs. - * See {@link KeyValueMarshaler}. + * A Marshaler of {@link ExtendedAttributes} key value pairs. See {@link KeyValueMarshaler}. * *

    This class is internal and is hence not for public use. Its APIs are unstable and can change * at any time. */ @SuppressWarnings("deprecation") public final class ExtendedAttributeKeyValueStatelessMarshaler - implements StatelessMarshaler2< - io.opentelemetry.api.incubator.common.ExtendedAttributeKey, Object> { + implements StatelessMarshaler2, Object> { private static final ExtendedAttributeKeyValueStatelessMarshaler INSTANCE = new ExtendedAttributeKeyValueStatelessMarshaler(); private static final byte[] EMPTY_BYTES = new byte[0]; @@ -43,12 +44,12 @@ private ExtendedAttributeKeyValueStatelessMarshaler() {} /** * Serializes the {@code attributes}. This method reads elements from context, use together with * {@link ExtendedAttributeKeyValueStatelessMarshaler#sizeExtendedAttributes(ProtoFieldInfo, - * io.opentelemetry.api.incubator.common.ExtendedAttributes, MarshalerContext)}. + * ExtendedAttributes, MarshalerContext)}. */ public static void serializeExtendedAttributes( Serializer output, ProtoFieldInfo field, - io.opentelemetry.api.incubator.common.ExtendedAttributes attributes, + ExtendedAttributes attributes, MarshalerContext context) throws IOException { output.writeStartRepeated(field); @@ -76,12 +77,10 @@ public static void serializeExtendedAttributes( /** * Sizes the {@code attributes}. This method adds elements to context, use together with {@link * ExtendedAttributeKeyValueStatelessMarshaler#serializeExtendedAttributes(Serializer, - * ProtoFieldInfo, io.opentelemetry.api.incubator.common.ExtendedAttributes, MarshalerContext)}. + * ProtoFieldInfo, ExtendedAttributes, MarshalerContext)}. */ public static int sizeExtendedAttributes( - ProtoFieldInfo field, - io.opentelemetry.api.incubator.common.ExtendedAttributes attributes, - MarshalerContext context) { + ProtoFieldInfo field, ExtendedAttributes attributes, MarshalerContext context) { if (attributes.isEmpty()) { return 0; } @@ -103,7 +102,7 @@ public static int sizeExtendedAttributes( @Override public void writeTo( Serializer output, - io.opentelemetry.api.incubator.common.ExtendedAttributeKey attributeKey, + ExtendedAttributeKey attributeKey, Object value, MarshalerContext context) throws IOException { @@ -121,9 +120,7 @@ public void writeTo( @Override public int getBinarySerializedSize( - io.opentelemetry.api.incubator.common.ExtendedAttributeKey attributeKey, - Object value, - MarshalerContext context) { + ExtendedAttributeKey attributeKey, Object value, MarshalerContext context) { int size = 0; if (!attributeKey.getKey().isEmpty()) { if (attributeKey instanceof InternalExtendedAttributeKeyImpl) { @@ -142,19 +139,15 @@ public int getBinarySerializedSize( } private static class ValueStatelessMarshaler - implements StatelessMarshaler2< - io.opentelemetry.api.incubator.common.ExtendedAttributeKey, Object> { + implements StatelessMarshaler2, Object> { static final ValueStatelessMarshaler INSTANCE = new ValueStatelessMarshaler(); // Supporting deprecated EXTENDED_ATTRIBUTES type until removed @SuppressWarnings("unchecked") @Override public int getBinarySerializedSize( - io.opentelemetry.api.incubator.common.ExtendedAttributeKey attributeKey, - Object value, - MarshalerContext context) { - io.opentelemetry.api.incubator.common.ExtendedAttributeType attributeType = - attributeKey.getType(); + ExtendedAttributeKey attributeKey, Object value, MarshalerContext context) { + ExtendedAttributeType attributeType = attributeKey.getType(); switch (attributeType) { case STRING: return StringAnyValueStatelessMarshaler.INSTANCE.getBinarySerializedSize( @@ -181,7 +174,7 @@ public int getBinarySerializedSize( case EXTENDED_ATTRIBUTES: return StatelessMarshalerUtil.sizeMessageWithContext( AnyValue.KVLIST_VALUE, - (io.opentelemetry.api.incubator.common.ExtendedAttributes) value, + (ExtendedAttributes) value, ExtendedAttributesKeyValueListStatelessMarshaler.INSTANCE, context); case VALUE: @@ -198,12 +191,11 @@ public int getBinarySerializedSize( @Override public void writeTo( Serializer output, - io.opentelemetry.api.incubator.common.ExtendedAttributeKey attributeKey, + ExtendedAttributeKey attributeKey, Object value, MarshalerContext context) throws IOException { - io.opentelemetry.api.incubator.common.ExtendedAttributeType attributeType = - attributeKey.getType(); + ExtendedAttributeType attributeType = attributeKey.getType(); switch (attributeType) { case STRING: StringAnyValueStatelessMarshaler.INSTANCE.writeTo(output, (String) value, context); @@ -231,7 +223,7 @@ public void writeTo( case EXTENDED_ATTRIBUTES: output.serializeMessageWithContext( AnyValue.KVLIST_VALUE, - (io.opentelemetry.api.incubator.common.ExtendedAttributes) value, + (ExtendedAttributes) value, ExtendedAttributesKeyValueListStatelessMarshaler.INSTANCE, context); return; @@ -246,24 +238,20 @@ public void writeTo( } private static class ExtendedAttributesKeyValueListStatelessMarshaler - implements StatelessMarshaler { + implements StatelessMarshaler { private static final ExtendedAttributesKeyValueListStatelessMarshaler INSTANCE = new ExtendedAttributesKeyValueListStatelessMarshaler(); private ExtendedAttributesKeyValueListStatelessMarshaler() {} @Override - public void writeTo( - Serializer output, - io.opentelemetry.api.incubator.common.ExtendedAttributes value, - MarshalerContext context) + public void writeTo(Serializer output, ExtendedAttributes value, MarshalerContext context) throws IOException { serializeExtendedAttributes(output, KeyValueList.VALUES, value, context); } @Override - public int getBinarySerializedSize( - io.opentelemetry.api.incubator.common.ExtendedAttributes value, MarshalerContext context) { + public int getBinarySerializedSize(ExtendedAttributes value, MarshalerContext context) { return sizeExtendedAttributes(KeyValueList.VALUES, value, context); } } diff --git a/exporters/otlp/common/src/main/java/io/opentelemetry/exporter/internal/otlp/IncubatingUtil.java b/exporters/otlp/common/src/main/java/io/opentelemetry/exporter/internal/otlp/IncubatingUtil.java index f4c5cf4c855..4ee235aa1e1 100644 --- a/exporters/otlp/common/src/main/java/io/opentelemetry/exporter/internal/otlp/IncubatingUtil.java +++ b/exporters/otlp/common/src/main/java/io/opentelemetry/exporter/internal/otlp/IncubatingUtil.java @@ -6,6 +6,8 @@ package io.opentelemetry.exporter.internal.otlp; import io.opentelemetry.api.common.Value; +import io.opentelemetry.api.incubator.common.ExtendedAttributeKey; +import io.opentelemetry.api.incubator.common.ExtendedAttributes; import io.opentelemetry.api.incubator.internal.InternalExtendedAttributeKeyImpl; import io.opentelemetry.exporter.internal.marshal.MarshalerContext; import io.opentelemetry.exporter.internal.marshal.Serializer; @@ -61,21 +63,18 @@ public static int extendedAttributesSize(LogRecordData logRecordData) { } // TODO(jack-berg): move to KeyValueMarshaler when ExtendedAttributes is stable - private static KeyValueMarshaler[] createForExtendedAttributes( - io.opentelemetry.api.incubator.common.ExtendedAttributes attributes) { + private static KeyValueMarshaler[] createForExtendedAttributes(ExtendedAttributes attributes) { if (attributes.isEmpty()) { return EMPTY_REPEATED; } KeyValueMarshaler[] marshalers = new KeyValueMarshaler[attributes.size()]; attributes.forEach( - new BiConsumer, Object>() { + new BiConsumer, Object>() { int index = 0; @Override - public void accept( - io.opentelemetry.api.incubator.common.ExtendedAttributeKey attributeKey, - Object o) { + public void accept(ExtendedAttributeKey attributeKey, Object o) { marshalers[index++] = create(attributeKey, o); } }); @@ -85,8 +84,7 @@ public void accept( // TODO(jack-berg): move to KeyValueMarshaler when ExtendedAttributes is stable // Supporting deprecated EXTENDED_ATTRIBUTES type until removed @SuppressWarnings("unchecked") - private static KeyValueMarshaler create( - io.opentelemetry.api.incubator.common.ExtendedAttributeKey attributeKey, Object value) { + private static KeyValueMarshaler create(ExtendedAttributeKey attributeKey, Object value) { byte[] keyUtf8; if (attributeKey.getKey().isEmpty()) { keyUtf8 = EMPTY_BYTES; @@ -120,8 +118,7 @@ private static KeyValueMarshaler create( keyUtf8, new KeyValueListAnyValueMarshaler( new KeyValueListAnyValueMarshaler.KeyValueListMarshaler( - createForExtendedAttributes( - (io.opentelemetry.api.incubator.common.ExtendedAttributes) value)))); + createForExtendedAttributes((ExtendedAttributes) value)))); case VALUE: return new KeyValueMarshaler(keyUtf8, AnyValueMarshaler.create((Value) value)); } @@ -141,8 +138,7 @@ public static void serializeExtendedAttributes( output, LogRecord.ATTRIBUTES, getExtendedAttributes(log), context); } - private static io.opentelemetry.api.incubator.common.ExtendedAttributes getExtendedAttributes( - LogRecordData logRecordData) { + private static ExtendedAttributes getExtendedAttributes(LogRecordData logRecordData) { if (!(logRecordData instanceof ExtendedLogRecordData)) { throw new IllegalArgumentException("logRecordData must be ExtendedLogRecordData"); } diff --git a/exporters/otlp/common/src/testIncubating/java/io/opentelemetry/exporter/internal/otlp/logs/LogsRequestMarshalerIncubatingTest.java b/exporters/otlp/common/src/testIncubating/java/io/opentelemetry/exporter/internal/otlp/logs/LogsRequestMarshalerIncubatingTest.java index 56f1107e47a..84639db8312 100644 --- a/exporters/otlp/common/src/testIncubating/java/io/opentelemetry/exporter/internal/otlp/logs/LogsRequestMarshalerIncubatingTest.java +++ b/exporters/otlp/common/src/testIncubating/java/io/opentelemetry/exporter/internal/otlp/logs/LogsRequestMarshalerIncubatingTest.java @@ -14,6 +14,8 @@ import com.google.protobuf.util.JsonFormat; import io.opentelemetry.api.common.Attributes; import io.opentelemetry.api.common.Value; +import io.opentelemetry.api.incubator.common.ExtendedAttributeKey; +import io.opentelemetry.api.incubator.common.ExtendedAttributes; import io.opentelemetry.api.internal.OtelEncodingUtils; import io.opentelemetry.api.logs.Severity; import io.opentelemetry.api.trace.SpanContext; @@ -97,7 +99,7 @@ void toProtoLogRecord(MarshalerSource marshalerSource) { // Extended fields .setEventName(EVENT_NAME) .setExtendedAttributes( - io.opentelemetry.api.incubator.common.ExtendedAttributes.builder() + ExtendedAttributes.builder() .put("str_key", "str_value") .put("str_arr_key", "str_value1", "str_value2") .put("bool_key", true) @@ -108,21 +110,19 @@ void toProtoLogRecord(MarshalerSource marshalerSource) { .put("int_arr_key", 1, 2) .put( "kv_list_key", - io.opentelemetry.api.incubator.common.ExtendedAttributes.builder() + ExtendedAttributes.builder() .put("bool_key", true) .put("double_key", 1.1) .put("int_key", 1) .put( "kv_list_key", - io.opentelemetry.api.incubator.common.ExtendedAttributes - .builder() + ExtendedAttributes.builder() .put("str_key", "str_value") .build()) .put("str_key", "str_value") .build()) .put( - io.opentelemetry.api.incubator.common.ExtendedAttributeKey.valueKey( - "value_key"), + ExtendedAttributeKey.valueKey("value_key"), Value.of( io.opentelemetry.api.common.KeyValue.of( "bool_key", Value.of(true)), diff --git a/sdk/common/src/main/java/io/opentelemetry/sdk/common/internal/ExtendedAttributesMap.java b/sdk/common/src/main/java/io/opentelemetry/sdk/common/internal/ExtendedAttributesMap.java index 9c5ed61d3cc..233fa7eace9 100644 --- a/sdk/common/src/main/java/io/opentelemetry/sdk/common/internal/ExtendedAttributesMap.java +++ b/sdk/common/src/main/java/io/opentelemetry/sdk/common/internal/ExtendedAttributesMap.java @@ -6,6 +6,9 @@ package io.opentelemetry.sdk.common.internal; import io.opentelemetry.api.common.Attributes; +import io.opentelemetry.api.incubator.common.ExtendedAttributeKey; +import io.opentelemetry.api.incubator.common.ExtendedAttributes; +import io.opentelemetry.api.incubator.common.ExtendedAttributesBuilder; import java.util.Collections; import java.util.HashMap; import java.util.Map; @@ -16,16 +19,14 @@ * A map with a fixed capacity that drops attributes when the map gets full, and which truncates * string and array string attribute values to the {@link #lengthLimit}. * - *

    {@link io.opentelemetry.api.incubator.common.ExtendedAttributes} analog of {@link - * AttributesMap}. + *

    {@link ExtendedAttributes} analog of {@link AttributesMap}. * *

    This class is internal and is hence not for public use. Its APIs are unstable and can change * at any time. */ @SuppressWarnings("deprecation") -public final class ExtendedAttributesMap - extends HashMap, Object> - implements io.opentelemetry.api.incubator.common.ExtendedAttributes { +public final class ExtendedAttributesMap extends HashMap, Object> + implements ExtendedAttributes { private static final long serialVersionUID = -2674974862318200501L; @@ -51,8 +52,7 @@ public static ExtendedAttributesMap create(long capacity, int lengthLimit) { /** Add the attribute key value pair, applying capacity and length limits. */ @Override @Nullable - public Object put( - io.opentelemetry.api.incubator.common.ExtendedAttributeKey key, @Nullable Object value) { + public Object put(ExtendedAttributeKey key, @Nullable Object value) { if (value == null) { return null; } @@ -63,8 +63,7 @@ public Object put( return super.put(key, AttributeUtil.applyAttributeLengthLimit(value, lengthLimit)); } - public void putIfCapacity( - io.opentelemetry.api.incubator.common.ExtendedAttributeKey key, @Nullable T value) { + public void putIfCapacity(ExtendedAttributeKey key, @Nullable T value) { put(key, value); } @@ -78,12 +77,12 @@ public int getTotalAddedValues() { @SuppressWarnings("unchecked") @Nullable @Override - public T get(io.opentelemetry.api.incubator.common.ExtendedAttributeKey key) { + public T get(ExtendedAttributeKey key) { return (T) super.get(key); } @Override - public Map, Object> asMap() { + public Map, Object> asMap() { // Because ExtendedAttributes is marked Immutable, IDEs may recognize this as redundant usage. // However, this class is private and is actually mutable, so we need to wrap with // unmodifiableMap anyways. We implement the immutable ExtendedAttributes for this class to @@ -93,15 +92,12 @@ public Map, Object } @Override - public io.opentelemetry.api.incubator.common.ExtendedAttributesBuilder toBuilder() { - return io.opentelemetry.api.incubator.common.ExtendedAttributes.builder().putAll(this); + public ExtendedAttributesBuilder toBuilder() { + return ExtendedAttributes.builder().putAll(this); } @Override - public void forEach( - BiConsumer< - ? super io.opentelemetry.api.incubator.common.ExtendedAttributeKey, ? super Object> - action) { + public void forEach(BiConsumer, ? super Object> action) { // https://github.com/open-telemetry/opentelemetry-java/issues/4161 // Help out android desugaring by having an explicit call to HashMap.forEach, when forEach is // just called through ExtendedAttributes.forEach desugaring is unable to correctly handle it. @@ -126,7 +122,7 @@ public String toString() { } /** Create an immutable copy of the extended attributes in this map. */ - public io.opentelemetry.api.incubator.common.ExtendedAttributes immutableCopy() { - return io.opentelemetry.api.incubator.common.ExtendedAttributes.builder().putAll(this).build(); + public ExtendedAttributes immutableCopy() { + return ExtendedAttributes.builder().putAll(this).build(); } } diff --git a/sdk/common/src/test/java/io/opentelemetry/sdk/common/internal/ExtendedAttributesValueTest.java b/sdk/common/src/test/java/io/opentelemetry/sdk/common/internal/ExtendedAttributesValueTest.java index 6a5eaae7cc3..e3350b82efd 100644 --- a/sdk/common/src/test/java/io/opentelemetry/sdk/common/internal/ExtendedAttributesValueTest.java +++ b/sdk/common/src/test/java/io/opentelemetry/sdk/common/internal/ExtendedAttributesValueTest.java @@ -9,6 +9,7 @@ import io.opentelemetry.api.common.KeyValue; import io.opentelemetry.api.common.Value; +import io.opentelemetry.api.incubator.common.ExtendedAttributeKey; import java.nio.ByteBuffer; import java.util.List; import org.junit.jupiter.api.Test; @@ -22,10 +23,9 @@ void put_ByteArrayTruncation() { byte[] bytes = new byte[] {1, 2, 3, 4, 5, 6, 7, 8, 9, 10}; Value value = Value.of(bytes); - map.put(io.opentelemetry.api.incubator.common.ExtendedAttributeKey.valueKey("key"), value); + map.put(ExtendedAttributeKey.valueKey("key"), value); - Value result = - map.get(io.opentelemetry.api.incubator.common.ExtendedAttributeKey.valueKey("key")); + Value result = map.get(ExtendedAttributeKey.valueKey("key")); ByteBuffer buffer = (ByteBuffer) result.getValue(); byte[] resultBytes = new byte[buffer.remaining()]; buffer.get(resultBytes); @@ -38,10 +38,9 @@ void put_ValueArrayTruncation() { Value arrayValue = Value.of(Value.of("short"), Value.of("this is too long")); - map.put(io.opentelemetry.api.incubator.common.ExtendedAttributeKey.valueKey("key"), arrayValue); + map.put(ExtendedAttributeKey.valueKey("key"), arrayValue); - Value result = - map.get(io.opentelemetry.api.incubator.common.ExtendedAttributeKey.valueKey("key")); + Value result = map.get(ExtendedAttributeKey.valueKey("key")); @SuppressWarnings("unchecked") List> resultList = (List>) result.getValue(); assertThat(resultList).hasSize(2); @@ -58,11 +57,9 @@ void put_ValueKeyValueListTruncation() { KeyValue.of("key1", Value.of("short")), KeyValue.of("key2", Value.of("this is too long"))); - map.put( - io.opentelemetry.api.incubator.common.ExtendedAttributeKey.valueKey("key"), kvListValue); + map.put(ExtendedAttributeKey.valueKey("key"), kvListValue); - Value result = - map.get(io.opentelemetry.api.incubator.common.ExtendedAttributeKey.valueKey("key")); + Value result = map.get(ExtendedAttributeKey.valueKey("key")); @SuppressWarnings("unchecked") List resultList = (List) result.getValue(); assertThat(resultList).hasSize(2); diff --git a/sdk/logs/src/main/java/io/opentelemetry/sdk/logs/ExtendedSdkLogRecordBuilder.java b/sdk/logs/src/main/java/io/opentelemetry/sdk/logs/ExtendedSdkLogRecordBuilder.java index 6c41c3069c9..edcc555623c 100644 --- a/sdk/logs/src/main/java/io/opentelemetry/sdk/logs/ExtendedSdkLogRecordBuilder.java +++ b/sdk/logs/src/main/java/io/opentelemetry/sdk/logs/ExtendedSdkLogRecordBuilder.java @@ -7,6 +7,7 @@ import io.opentelemetry.api.common.AttributeKey; import io.opentelemetry.api.common.Value; +import io.opentelemetry.api.incubator.common.ExtendedAttributeKey; import io.opentelemetry.api.incubator.logs.ExtendedLogRecordBuilder; import io.opentelemetry.api.logs.Severity; import io.opentelemetry.api.trace.Span; @@ -108,8 +109,7 @@ public ExtendedSdkLogRecordBuilder setBody(Value value) { } @Override - public ExtendedSdkLogRecordBuilder setAttribute( - io.opentelemetry.api.incubator.common.ExtendedAttributeKey key, T value) { + public ExtendedSdkLogRecordBuilder setAttribute(ExtendedAttributeKey key, T value) { if (key == null || key.getKey().isEmpty() || value == null) { return this; } @@ -127,8 +127,7 @@ public ExtendedSdkLogRecordBuilder setAttribute(AttributeKey key, @Nullab if (key == null || key.getKey().isEmpty() || value == null) { return this; } - return setAttribute( - io.opentelemetry.api.incubator.common.ExtendedAttributeKey.fromAttributeKey(key), value); + return setAttribute(ExtendedAttributeKey.fromAttributeKey(key), value); } @Override diff --git a/sdk/logs/src/main/java/io/opentelemetry/sdk/logs/ExtendedSdkLogRecordData.java b/sdk/logs/src/main/java/io/opentelemetry/sdk/logs/ExtendedSdkLogRecordData.java index 03d05bf9056..842a7ec2ea6 100644 --- a/sdk/logs/src/main/java/io/opentelemetry/sdk/logs/ExtendedSdkLogRecordData.java +++ b/sdk/logs/src/main/java/io/opentelemetry/sdk/logs/ExtendedSdkLogRecordData.java @@ -7,6 +7,7 @@ import com.google.auto.value.AutoValue; import io.opentelemetry.api.common.Value; +import io.opentelemetry.api.incubator.common.ExtendedAttributes; import io.opentelemetry.api.logs.Severity; import io.opentelemetry.api.trace.SpanContext; import io.opentelemetry.sdk.common.InstrumentationScopeInfo; @@ -34,7 +35,7 @@ static ExtendedSdkLogRecordData create( Severity severity, @Nullable String severityText, @Nullable Value body, - io.opentelemetry.api.incubator.common.ExtendedAttributes attributes, + ExtendedAttributes attributes, int totalAttributeCount) { return new AutoValue_ExtendedSdkLogRecordData( resource, diff --git a/sdk/logs/src/main/java/io/opentelemetry/sdk/logs/ExtendedSdkReadWriteLogRecord.java b/sdk/logs/src/main/java/io/opentelemetry/sdk/logs/ExtendedSdkReadWriteLogRecord.java index 2d740be37f0..be8417b0bb5 100644 --- a/sdk/logs/src/main/java/io/opentelemetry/sdk/logs/ExtendedSdkReadWriteLogRecord.java +++ b/sdk/logs/src/main/java/io/opentelemetry/sdk/logs/ExtendedSdkReadWriteLogRecord.java @@ -8,6 +8,8 @@ import io.opentelemetry.api.common.AttributeKey; import io.opentelemetry.api.common.Attributes; import io.opentelemetry.api.common.Value; +import io.opentelemetry.api.incubator.common.ExtendedAttributeKey; +import io.opentelemetry.api.incubator.common.ExtendedAttributes; import io.opentelemetry.api.internal.GuardedBy; import io.opentelemetry.api.logs.Severity; import io.opentelemetry.api.trace.SpanContext; @@ -90,13 +92,11 @@ public ExtendedSdkReadWriteLogRecord setAttribute(AttributeKey key, T val if (key == null || key.getKey().isEmpty() || value == null) { return this; } - return setAttribute( - io.opentelemetry.api.incubator.common.ExtendedAttributeKey.fromAttributeKey(key), value); + return setAttribute(ExtendedAttributeKey.fromAttributeKey(key), value); } @Override - public ExtendedSdkReadWriteLogRecord setAttribute( - io.opentelemetry.api.incubator.common.ExtendedAttributeKey key, T value) { + public ExtendedSdkReadWriteLogRecord setAttribute(ExtendedAttributeKey key, T value) { if (key == null || key.getKey().isEmpty() || value == null) { return this; } @@ -111,11 +111,10 @@ public ExtendedSdkReadWriteLogRecord setAttribute( return this; } - private io.opentelemetry.api.incubator.common.ExtendedAttributes - getImmutableExtendedAttributes() { + private ExtendedAttributes getImmutableExtendedAttributes() { synchronized (lock) { if (extendedAttributes == null) { - return io.opentelemetry.api.incubator.common.ExtendedAttributes.empty(); + return ExtendedAttributes.empty(); } return extendedAttributes.immutableCopy(); } @@ -147,13 +146,12 @@ public Attributes getAttributes() { @Nullable @Override public T getAttribute(AttributeKey key) { - return getAttribute( - io.opentelemetry.api.incubator.common.ExtendedAttributeKey.fromAttributeKey(key)); + return getAttribute(ExtendedAttributeKey.fromAttributeKey(key)); } @Nullable @Override - public T getAttribute(io.opentelemetry.api.incubator.common.ExtendedAttributeKey key) { + public T getAttribute(ExtendedAttributeKey key) { synchronized (lock) { if (extendedAttributes == null || extendedAttributes.isEmpty()) { return null; @@ -163,7 +161,7 @@ public T getAttribute(io.opentelemetry.api.incubator.common.ExtendedAttribut } @Override - public io.opentelemetry.api.incubator.common.ExtendedAttributes getExtendedAttributes() { + public ExtendedAttributes getExtendedAttributes() { return getImmutableExtendedAttributes(); } } diff --git a/sdk/logs/src/main/java/io/opentelemetry/sdk/logs/data/internal/ExtendedLogRecordData.java b/sdk/logs/src/main/java/io/opentelemetry/sdk/logs/data/internal/ExtendedLogRecordData.java index 47642cc4c48..18e2c8f57a5 100644 --- a/sdk/logs/src/main/java/io/opentelemetry/sdk/logs/data/internal/ExtendedLogRecordData.java +++ b/sdk/logs/src/main/java/io/opentelemetry/sdk/logs/data/internal/ExtendedLogRecordData.java @@ -6,6 +6,7 @@ package io.opentelemetry.sdk.logs.data.internal; import io.opentelemetry.api.common.Attributes; +import io.opentelemetry.api.incubator.common.ExtendedAttributes; import io.opentelemetry.sdk.logs.data.LogRecordData; /** @@ -16,11 +17,8 @@ @SuppressWarnings("deprecation") public interface ExtendedLogRecordData extends LogRecordData { - /** - * Returns the attributes for this log, or {@link - * io.opentelemetry.api.incubator.common.ExtendedAttributes#empty()} if unset. - */ - io.opentelemetry.api.incubator.common.ExtendedAttributes getExtendedAttributes(); + /** Returns the attributes for this log, or {@link ExtendedAttributes#empty()} if unset. */ + ExtendedAttributes getExtendedAttributes(); /** * Returns the attributes for this log, or {@link Attributes#empty()} if unset. diff --git a/sdk/logs/src/main/java/io/opentelemetry/sdk/logs/internal/ExtendedReadWriteLogRecord.java b/sdk/logs/src/main/java/io/opentelemetry/sdk/logs/internal/ExtendedReadWriteLogRecord.java index c3137c76f19..130bbc1471d 100644 --- a/sdk/logs/src/main/java/io/opentelemetry/sdk/logs/internal/ExtendedReadWriteLogRecord.java +++ b/sdk/logs/src/main/java/io/opentelemetry/sdk/logs/internal/ExtendedReadWriteLogRecord.java @@ -5,6 +5,8 @@ package io.opentelemetry.sdk.logs.internal; +import io.opentelemetry.api.incubator.common.ExtendedAttributeKey; +import io.opentelemetry.api.incubator.common.ExtendedAttributes; import io.opentelemetry.sdk.logs.ReadWriteLogRecord; import io.opentelemetry.sdk.logs.data.internal.ExtendedLogRecordData; import javax.annotation.Nullable; @@ -26,8 +28,7 @@ public interface ExtendedReadWriteLogRecord extends ReadWriteLogRecord { * *

    Note: the behavior of null values is undefined, and hence strongly discouraged. */ - ExtendedReadWriteLogRecord setAttribute( - io.opentelemetry.api.incubator.common.ExtendedAttributeKey key, T value); + ExtendedReadWriteLogRecord setAttribute(ExtendedAttributeKey key, T value); /** * Sets attributes to the {@link ReadWriteLogRecord}. If the {@link ReadWriteLogRecord} previously @@ -37,16 +38,13 @@ ExtendedReadWriteLogRecord setAttribute( * @return this. */ @SuppressWarnings("unchecked") - default ExtendedReadWriteLogRecord setAllAttributes( - io.opentelemetry.api.incubator.common.ExtendedAttributes extendedAttributes) { + default ExtendedReadWriteLogRecord setAllAttributes(ExtendedAttributes extendedAttributes) { if (extendedAttributes == null || extendedAttributes.isEmpty()) { return this; } extendedAttributes.forEach( (attributeKey, value) -> - this.setAttribute( - (io.opentelemetry.api.incubator.common.ExtendedAttributeKey) attributeKey, - value)); + this.setAttribute((ExtendedAttributeKey) attributeKey, value)); return this; } @@ -59,11 +57,8 @@ default ExtendedReadWriteLogRecord setAllAttributes( * getAttributes().get(key) */ @Nullable - T getAttribute(io.opentelemetry.api.incubator.common.ExtendedAttributeKey key); + T getAttribute(ExtendedAttributeKey key); - /** - * Returns the attributes for this log, or {@link - * io.opentelemetry.api.incubator.common.ExtendedAttributes#empty()} if unset. - */ - io.opentelemetry.api.incubator.common.ExtendedAttributes getExtendedAttributes(); + /** Returns the attributes for this log, or {@link ExtendedAttributes#empty()} if unset. */ + ExtendedAttributes getExtendedAttributes(); } diff --git a/sdk/testing/src/main/java/io/opentelemetry/sdk/testing/logs/internal/TestExtendedLogRecordData.java b/sdk/testing/src/main/java/io/opentelemetry/sdk/testing/logs/internal/TestExtendedLogRecordData.java index 6bb4257e861..44fe6bf6bfa 100644 --- a/sdk/testing/src/main/java/io/opentelemetry/sdk/testing/logs/internal/TestExtendedLogRecordData.java +++ b/sdk/testing/src/main/java/io/opentelemetry/sdk/testing/logs/internal/TestExtendedLogRecordData.java @@ -8,6 +8,7 @@ import com.google.auto.value.AutoValue; import io.opentelemetry.api.common.Attributes; import io.opentelemetry.api.common.Value; +import io.opentelemetry.api.incubator.common.ExtendedAttributes; import io.opentelemetry.api.logs.Severity; import io.opentelemetry.api.trace.SpanContext; import io.opentelemetry.sdk.common.InstrumentationScopeInfo; @@ -187,17 +188,13 @@ public Builder setBody(Body body) { /** Set the attributes. */ public Builder setAttributes(Attributes attributes) { - return setExtendedAttributes( - io.opentelemetry.api.incubator.common.ExtendedAttributes.builder() - .putAll(attributes) - .build()); + return setExtendedAttributes(ExtendedAttributes.builder().putAll(attributes).build()); } /** Set the total attribute count. */ public abstract Builder setTotalAttributeCount(int totalAttributeCount); /** Set extended attributes. * */ - public abstract Builder setExtendedAttributes( - io.opentelemetry.api.incubator.common.ExtendedAttributes extendedAttributes); + public abstract Builder setExtendedAttributes(ExtendedAttributes extendedAttributes); } }