From 34beb4d71c2b30fa439a73f8cb0ec42e322c3d2f Mon Sep 17 00:00:00 2001 From: jack-berg <34418638+jack-berg@users.noreply.github.com> Date: Wed, 2 Nov 2022 12:16:46 -0500 Subject: [PATCH 01/68] Deprecate :extensions:aws (#4862) * Deprecate :extensions:aws * Add deprecation notice to README.md * Include link to new location opentelemetry-java-contrib --- README.md | 22 +++---- .../opentelemetry-extension-aws.txt | 7 ++- extensions/aws/README.md | 6 ++ .../aws/AwsConfigurablePropagator.java | 4 ++ .../extension/aws/AwsXrayPropagator.java | 4 ++ .../extension/aws/AwsXrayPropagatorTest.java | 57 ++++++++++--------- extensions/trace-propagators/build.gradle.kts | 2 - .../PropagatorContextExtractBenchmark.java | 48 ---------------- .../PropagatorContextInjectBenchmark.java | 12 ---- sdk-extensions/autoconfigure/build.gradle.kts | 3 +- .../sdk/autoconfigure/FullConfigTest.java | 2 - 11 files changed, 62 insertions(+), 105 deletions(-) diff --git a/README.md b/README.md index 4c4b791a433..cff5bfaa3d9 100644 --- a/README.md +++ b/README.md @@ -221,21 +221,21 @@ dependency as follows, replacing `{{artifact-id}}` with the value from the "Arti ### API -| Component | Description | Artifact ID | Version | -|-----------------------------------|----------------------------------------------------------------------------------------------------------------------------------------------------|--------------------------|----------------------------------------------------------------------------------| -| [API](./api/all) | OpenTelemetry API, including metrics, traces, baggage, context | `opentelemetry-api` | 1.19.0 | +| Component | Description | Artifact ID | Version | +|-----------------------------------|----------------------------------------------------------------------------------------------------------------------------------------------------|--------------------------|-------------------------------------------------------------| +| [API](./api/all) | OpenTelemetry API, including metrics, traces, baggage, context | `opentelemetry-api` | 1.19.0 | | [Logs API](./api/logs) | OpenTelemetry Log API for emitting events and bridging log frameworks (NOT a replacement for application logging frameworks like SLF4J, JUL, etc.) | `opentelemetry-api-logs` | 1.19.0-alpha | -| [Context API](./context) | OpenTelemetry context API | `opentelemetry-context` | 1.19.0 | -| [Semantic Conventions](./semconv) | Generated code for OpenTelemetry semantic conventions | `opentelemetry-semconv` | 1.19.0-alpha | +| [Context API](./context) | OpenTelemetry context API | `opentelemetry-context` | 1.19.0 | +| [Semantic Conventions](./semconv) | Generated code for OpenTelemetry semantic conventions | `opentelemetry-semconv` | 1.19.0-alpha | ### API Extensions -| Component | Description | Artifact ID | Version | -|---------------------------------------------------------------|---------------------------------------------------------------------------------------------|---------------------------------------------|-------------------------------------------------------------| -| [AWS Extension](./extensions/aws) | AWS Xray propagator | `opentelemetry-extension-aws` | 1.19.0 | -| [Kotlin Extension](./extensions/kotlin) | Context extension for coroutines | `opentelemetry-extension-kotlin` | 1.19.0 | -| [Trace Propagators Extension](./extensions/trace-propagators) | Trace propagators, including B3, Jaeger, OT Trace | `opentelemetry-extension-trace-propagators` | 1.19.0 | -| [Incubator Extension](./extensions/incubator) | API incubator, including pass through propagator, and extended tracer | `opentelemetry-extension-incubator` | 1.19.0-alpha | +| Component | Description | Artifact ID | Version | +|---------------------------------------------------------------|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|---------------------------------------------|-------------------------------------------------------------| +| [AWS Extension](./extensions/aws) | AWS Xray propagator (deprecated, moved to [opentelemetry-java-contrib/aws-xray-propagator](https://github.com/open-telemetry/opentelemetry-java-contrib/tree/main/aws-xray-propagator)) | `opentelemetry-extension-aws` | 1.19.0 | +| [Kotlin Extension](./extensions/kotlin) | Context extension for coroutines | `opentelemetry-extension-kotlin` | 1.19.0 | +| [Trace Propagators Extension](./extensions/trace-propagators) | Trace propagators, including B3, Jaeger, OT Trace | `opentelemetry-extension-trace-propagators` | 1.19.0 | +| [Incubator Extension](./extensions/incubator) | API incubator, including pass through propagator, and extended tracer | `opentelemetry-extension-incubator` | 1.19.0-alpha | ### SDK diff --git a/docs/apidiffs/current_vs_latest/opentelemetry-extension-aws.txt b/docs/apidiffs/current_vs_latest/opentelemetry-extension-aws.txt index df26146497b..979e67fbfcf 100644 --- a/docs/apidiffs/current_vs_latest/opentelemetry-extension-aws.txt +++ b/docs/apidiffs/current_vs_latest/opentelemetry-extension-aws.txt @@ -1,2 +1,7 @@ Comparing source compatibility of against -No changes. \ No newline at end of file +=== UNCHANGED CLASS: PUBLIC FINAL io.opentelemetry.extension.aws.AwsConfigurablePropagator (not serializable) + === CLASS FILE FORMAT VERSION: 52.0 <- 52.0 + +++ NEW ANNOTATION: java.lang.Deprecated +=== UNCHANGED CLASS: PUBLIC FINAL io.opentelemetry.extension.aws.AwsXrayPropagator (not serializable) + === CLASS FILE FORMAT VERSION: 52.0 <- 52.0 + +++ NEW ANNOTATION: java.lang.Deprecated diff --git a/extensions/aws/README.md b/extensions/aws/README.md index 00dea946cdf..7157e7df5d4 100644 --- a/extensions/aws/README.md +++ b/extensions/aws/README.md @@ -2,5 +2,11 @@ [![Javadocs][javadoc-image]][javadoc-url] +> **NOTICE**: This artifact is deprecated and its contents have been moved +> to [io.opentelemetry.contrib:opentelemetry-aws-xray-propagator](https://github.com/open-telemetry/opentelemetry-java-contrib/tree/main/aws-xray-propagator). +> Version 1.20.0 will be the last minor version published. However, it will continue to receive +> patches for security vulnerabilities, and `io.opentelemetry:opentelemetry-bom` will reference the +> last published version. + [javadoc-image]: https://www.javadoc.io/badge/io.opentelemetry/opentelemetry-extension-aws.svg [javadoc-url]: https://www.javadoc.io/doc/io.opentelemetry/opentelemetry-extension-aws diff --git a/extensions/aws/src/main/java/io/opentelemetry/extension/aws/AwsConfigurablePropagator.java b/extensions/aws/src/main/java/io/opentelemetry/extension/aws/AwsConfigurablePropagator.java index 18d4ef77d9a..1682f16ec3a 100644 --- a/extensions/aws/src/main/java/io/opentelemetry/extension/aws/AwsConfigurablePropagator.java +++ b/extensions/aws/src/main/java/io/opentelemetry/extension/aws/AwsConfigurablePropagator.java @@ -12,7 +12,11 @@ /** * A {@link ConfigurablePropagatorProvider} which allows enabling the {@link AwsXrayPropagator} with * the propagator name {@code xray}. + * + * @deprecated Moved to io.opentelemetry.contrib:opentelemetry-aws-xray-propagator. */ +@Deprecated public final class AwsConfigurablePropagator implements ConfigurablePropagatorProvider { @Override public TextMapPropagator getPropagator(ConfigProperties config) { diff --git a/extensions/aws/src/main/java/io/opentelemetry/extension/aws/AwsXrayPropagator.java b/extensions/aws/src/main/java/io/opentelemetry/extension/aws/AwsXrayPropagator.java index f342d035a15..d483f339462 100644 --- a/extensions/aws/src/main/java/io/opentelemetry/extension/aws/AwsXrayPropagator.java +++ b/extensions/aws/src/main/java/io/opentelemetry/extension/aws/AwsXrayPropagator.java @@ -41,7 +41,11 @@ * AWSXrayPropagator.getInstance()))) * .build(); * } + * + * @deprecated Moved to io.opentelemetry.contrib:opentelemetry-aws-xray-propagator. */ +@Deprecated public final class AwsXrayPropagator implements TextMapPropagator { // Visible for testing diff --git a/extensions/aws/src/test/java/io/opentelemetry/extension/aws/AwsXrayPropagatorTest.java b/extensions/aws/src/test/java/io/opentelemetry/extension/aws/AwsXrayPropagatorTest.java index c1f9637690e..3ad4a957f81 100644 --- a/extensions/aws/src/test/java/io/opentelemetry/extension/aws/AwsXrayPropagatorTest.java +++ b/extensions/aws/src/test/java/io/opentelemetry/extension/aws/AwsXrayPropagatorTest.java @@ -5,7 +5,6 @@ package io.opentelemetry.extension.aws; -import static io.opentelemetry.extension.aws.AwsXrayPropagator.TRACE_HEADER_KEY; import static org.assertj.core.api.Assertions.assertThat; import io.opentelemetry.api.baggage.Baggage; @@ -24,6 +23,7 @@ import javax.annotation.Nullable; import org.junit.jupiter.api.Test; +@SuppressWarnings("deprecation") // Moved to contrib class AwsXrayPropagatorTest { private static final String TRACE_ID = "8a3c60f7d188f8fa79d48a391a778fa6"; @@ -57,7 +57,7 @@ void inject_SampledContext() { assertThat(carrier) .containsEntry( - TRACE_HEADER_KEY, + AwsXrayPropagator.TRACE_HEADER_KEY, "Root=1-8a3c60f7-d188f8fa79d48a391a778fa6;Parent=53995c3f42cd8ad8;Sampled=1"); } @@ -73,7 +73,7 @@ void inject_NotSampledContext() { assertThat(carrier) .containsEntry( - TRACE_HEADER_KEY, + AwsXrayPropagator.TRACE_HEADER_KEY, "Root=1-8a3c60f7-d188f8fa79d48a391a778fa6;Parent=53995c3f42cd8ad8;Sampled=0"); } @@ -98,7 +98,7 @@ void inject_WithBaggage() { assertThat(carrier) .containsEntry( - TRACE_HEADER_KEY, + AwsXrayPropagator.TRACE_HEADER_KEY, "Root=1-8a3c60f7-d188f8fa79d48a391a778fa6;Parent=53995c3f42cd8ad8;Sampled=0;" + "cat=meow;dog=bark"); } @@ -127,7 +127,7 @@ void inject_WithBaggage_LimitTruncates() { assertThat(carrier) .containsEntry( - TRACE_HEADER_KEY, + AwsXrayPropagator.TRACE_HEADER_KEY, "Root=1-8a3c60f7-d188f8fa79d48a391a778fa6;Parent=53995c3f42cd8ad8;Sampled=0;" + key1 + '=' @@ -152,7 +152,7 @@ void inject_WithTraceState() { // mapping with baggage. assertThat(carrier) .containsEntry( - TRACE_HEADER_KEY, + AwsXrayPropagator.TRACE_HEADER_KEY, "Root=1-8a3c60f7-d188f8fa79d48a391a778fa6;Parent=53995c3f42cd8ad8;Sampled=0"); } @@ -187,7 +187,7 @@ void extract_Nothing() { void extract_SampledContext() { Map carrier = new LinkedHashMap<>(); carrier.put( - TRACE_HEADER_KEY, + AwsXrayPropagator.TRACE_HEADER_KEY, "Root=1-8a3c60f7-d188f8fa79d48a391a778fa6;Parent=53995c3f42cd8ad8;Sampled=1"); assertThat(getSpanContext(xrayPropagator.extract(Context.current(), carrier, getter))) @@ -200,7 +200,7 @@ void extract_SampledContext() { void extract_NotSampledContext() { Map carrier = new LinkedHashMap<>(); carrier.put( - TRACE_HEADER_KEY, + AwsXrayPropagator.TRACE_HEADER_KEY, "Root=1-8a3c60f7-d188f8fa79d48a391a778fa6;Parent=53995c3f42cd8ad8;Sampled=0"); assertThat(getSpanContext(xrayPropagator.extract(Context.current(), carrier, getter))) @@ -213,7 +213,7 @@ void extract_NotSampledContext() { void extract_DifferentPartOrder() { Map carrier = new LinkedHashMap<>(); carrier.put( - TRACE_HEADER_KEY, + AwsXrayPropagator.TRACE_HEADER_KEY, "Parent=53995c3f42cd8ad8;Sampled=1;Root=1-8a3c60f7-d188f8fa79d48a391a778fa6"); assertThat(getSpanContext(xrayPropagator.extract(Context.current(), carrier, getter))) @@ -226,7 +226,7 @@ void extract_DifferentPartOrder() { void extract_AdditionalFields() { Map carrier = new LinkedHashMap<>(); carrier.put( - TRACE_HEADER_KEY, + AwsXrayPropagator.TRACE_HEADER_KEY, "Root=1-8a3c60f7-d188f8fa79d48a391a778fa6;Parent=53995c3f42cd8ad8;Sampled=1;Foo=Bar"); Context context = xrayPropagator.extract(Context.current(), carrier, getter); @@ -249,7 +249,7 @@ void extract_Baggage_LimitTruncates() { Map carrier = new LinkedHashMap<>(); carrier.put( - TRACE_HEADER_KEY, + AwsXrayPropagator.TRACE_HEADER_KEY, "Root=1-8a3c60f7-d188f8fa79d48a391a778fa6;Parent=53995c3f42cd8ad8;Sampled=1;" + key1 + '=' @@ -271,7 +271,7 @@ void extract_Baggage_LimitTruncates() { @Test void extract_EmptyHeaderValue() { Map invalidHeaders = new LinkedHashMap<>(); - invalidHeaders.put(TRACE_HEADER_KEY, ""); + invalidHeaders.put(AwsXrayPropagator.TRACE_HEADER_KEY, ""); verifyInvalidBehavior(invalidHeaders); } @@ -280,7 +280,7 @@ void extract_EmptyHeaderValue() { void extract_InvalidTraceId() { Map invalidHeaders = new LinkedHashMap<>(); invalidHeaders.put( - TRACE_HEADER_KEY, + AwsXrayPropagator.TRACE_HEADER_KEY, "Root=abcdefghijklmnopabcdefghijklmnop;Parent=53995c3f42cd8ad8;Sampled=0"); verifyInvalidBehavior(invalidHeaders); @@ -290,7 +290,7 @@ void extract_InvalidTraceId() { void extract_InvalidTraceId_Size() { Map invalidHeaders = new LinkedHashMap<>(); invalidHeaders.put( - TRACE_HEADER_KEY, + AwsXrayPropagator.TRACE_HEADER_KEY, "Root=1-8a3c60f7-d188f8fa79d48a391a778fa600;Parent=53995c3f42cd8ad8;Sampled=0"); verifyInvalidBehavior(invalidHeaders); @@ -300,7 +300,7 @@ void extract_InvalidTraceId_Size() { void extract_InvalidSpanId() { Map invalidHeaders = new LinkedHashMap<>(); invalidHeaders.put( - TRACE_HEADER_KEY, + AwsXrayPropagator.TRACE_HEADER_KEY, "Root=1-8a3c60f7-d188f8fa79d48a391a778fa6;Parent=abcdefghijklmnop;Sampled=0"); verifyInvalidBehavior(invalidHeaders); @@ -310,7 +310,7 @@ void extract_InvalidSpanId() { void extract_InvalidSpanId_Size() { Map invalidHeaders = new LinkedHashMap<>(); invalidHeaders.put( - TRACE_HEADER_KEY, + AwsXrayPropagator.TRACE_HEADER_KEY, "Root=1-8a3c60f7-d188f8fa79d48a391a778fa6;Parent=53995c3f42cd8ad800;Sampled=0"); verifyInvalidBehavior(invalidHeaders); @@ -320,7 +320,7 @@ void extract_InvalidSpanId_Size() { void extract_InvalidFlags() { Map invalidHeaders = new LinkedHashMap<>(); invalidHeaders.put( - TRACE_HEADER_KEY, + AwsXrayPropagator.TRACE_HEADER_KEY, "Root=1-8a3c60f7-d188f8fa79d48a391a778fa6;Parent=53995c3f42cd8ad8;Sampled="); verifyInvalidBehavior(invalidHeaders); @@ -330,7 +330,7 @@ void extract_InvalidFlags() { void extract_InvalidFlags_Size() { Map invalidHeaders = new LinkedHashMap<>(); invalidHeaders.put( - TRACE_HEADER_KEY, + AwsXrayPropagator.TRACE_HEADER_KEY, "Root=1-8a3c60f7-d188f8fa79d48a391a778fa6;Parent=53995c3f42cd8ad8;Sampled=10220"); verifyInvalidBehavior(invalidHeaders); @@ -340,7 +340,7 @@ void extract_InvalidFlags_Size() { void extract_InvalidFlags_NonNumeric() { Map invalidHeaders = new LinkedHashMap<>(); invalidHeaders.put( - TRACE_HEADER_KEY, + AwsXrayPropagator.TRACE_HEADER_KEY, "Root=1-8a3c60f7-d188f8fa79d48a391a778fa6;Parent=53995c3f42cd8ad8;Sampled=a"); verifyInvalidBehavior(invalidHeaders); @@ -349,7 +349,8 @@ void extract_InvalidFlags_NonNumeric() { @Test void extract_Invalid_NoSpanId() { Map invalidHeaders = new LinkedHashMap<>(1); - invalidHeaders.put(TRACE_HEADER_KEY, "Root=1-622422bf-59625fe25708d4660735d8ef"); + invalidHeaders.put( + AwsXrayPropagator.TRACE_HEADER_KEY, "Root=1-622422bf-59625fe25708d4660735d8ef"); verifyInvalidBehavior(invalidHeaders); } @@ -380,7 +381,7 @@ void extract_nullGetter() { void extract_EpochPart_ZeroedSingleDigit() { Map carrier = new LinkedHashMap<>(); carrier.put( - TRACE_HEADER_KEY, + AwsXrayPropagator.TRACE_HEADER_KEY, "Root=1-0-d188f8fa79d48a391a778fa6;Parent=53995c3f42cd8ad8;Sampled=1;Foo=Bar"); assertThat(getSpanContext(xrayPropagator.extract(Context.current(), carrier, getter))) @@ -396,7 +397,7 @@ void extract_EpochPart_ZeroedSingleDigit() { void extract_EpochPart_TwoChars() { Map carrier = new LinkedHashMap<>(); carrier.put( - TRACE_HEADER_KEY, + AwsXrayPropagator.TRACE_HEADER_KEY, "Root=1-1a-d188f8fa79d48a391a778fa6;Parent=53995c3f42cd8ad8;Sampled=1;Foo=Bar"); assertThat(getSpanContext(xrayPropagator.extract(Context.current(), carrier, getter))) @@ -412,7 +413,7 @@ void extract_EpochPart_TwoChars() { void extract_EpochPart_Zeroed() { Map carrier = new LinkedHashMap<>(); carrier.put( - TRACE_HEADER_KEY, + AwsXrayPropagator.TRACE_HEADER_KEY, "Root=1-00000000-d188f8fa79d48a391a778fa6;Parent=53995c3f42cd8ad8;Sampled=1;Foo=Bar"); assertThat(getSpanContext(xrayPropagator.extract(Context.current(), carrier, getter))) @@ -428,7 +429,7 @@ void extract_EpochPart_Zeroed() { void extract_InvalidTraceId_EpochPart_TooLong() { Map invalidHeaders = new LinkedHashMap<>(); invalidHeaders.put( - TRACE_HEADER_KEY, + AwsXrayPropagator.TRACE_HEADER_KEY, "Root=1-8a3c60f711-d188f8fa79d48a391a778fa6;Parent=53995c3f42cd8ad8;Sampled=0"); assertThat(getSpanContext(xrayPropagator.extract(Context.current(), invalidHeaders, getter))) @@ -439,7 +440,8 @@ void extract_InvalidTraceId_EpochPart_TooLong() { void extract_InvalidTraceId_EpochPart_Empty() { Map invalidHeaders = new LinkedHashMap<>(); invalidHeaders.put( - TRACE_HEADER_KEY, "Root=1--d188f8fa79d48a391a778fa6;Parent=53995c3f42cd8ad8;Sampled=0"); + AwsXrayPropagator.TRACE_HEADER_KEY, + "Root=1--d188f8fa79d48a391a778fa6;Parent=53995c3f42cd8ad8;Sampled=0"); assertThat(getSpanContext(xrayPropagator.extract(Context.current(), invalidHeaders, getter))) .isSameAs(SpanContext.getInvalid()); @@ -449,7 +451,8 @@ void extract_InvalidTraceId_EpochPart_Empty() { void extract_InvalidTraceId_EpochPart_Missing() { Map invalidHeaders = new LinkedHashMap<>(); invalidHeaders.put( - TRACE_HEADER_KEY, "Root=1-d188f8fa79d48a391a778fa6;Parent=53995c3f42cd8ad8;Sampled=0"); + AwsXrayPropagator.TRACE_HEADER_KEY, + "Root=1-d188f8fa79d48a391a778fa6;Parent=53995c3f42cd8ad8;Sampled=0"); assertThat(getSpanContext(xrayPropagator.extract(Context.current(), invalidHeaders, getter))) .isSameAs(SpanContext.getInvalid()); @@ -459,7 +462,7 @@ void extract_InvalidTraceId_EpochPart_Missing() { void extract_InvalidTraceId_WrongVersion() { Map carrier = new LinkedHashMap<>(); carrier.put( - TRACE_HEADER_KEY, + AwsXrayPropagator.TRACE_HEADER_KEY, "Root=2-1a2a3a4a-d188f8fa79d48a391a778fa6;Parent=53995c3f42cd8ad8;Sampled=1;Foo=Bar"); assertThat(getSpanContext(xrayPropagator.extract(Context.current(), carrier, getter))) diff --git a/extensions/trace-propagators/build.gradle.kts b/extensions/trace-propagators/build.gradle.kts index 485e8ee35a5..5e4d8e0bec2 100644 --- a/extensions/trace-propagators/build.gradle.kts +++ b/extensions/trace-propagators/build.gradle.kts @@ -16,6 +16,4 @@ dependencies { testImplementation("io.jaegertracing:jaeger-client") testImplementation("com.google.guava:guava") - - jmhImplementation(project(":extensions:aws")) } diff --git a/extensions/trace-propagators/src/jmh/java/io/opentelemetry/extension/trace/propagation/PropagatorContextExtractBenchmark.java b/extensions/trace-propagators/src/jmh/java/io/opentelemetry/extension/trace/propagation/PropagatorContextExtractBenchmark.java index 295239f99bf..69c0ab11e74 100644 --- a/extensions/trace-propagators/src/jmh/java/io/opentelemetry/extension/trace/propagation/PropagatorContextExtractBenchmark.java +++ b/extensions/trace-propagators/src/jmh/java/io/opentelemetry/extension/trace/propagation/PropagatorContextExtractBenchmark.java @@ -8,7 +8,6 @@ import io.opentelemetry.api.trace.Span; import io.opentelemetry.context.Context; import io.opentelemetry.context.propagation.TextMapGetter; -import io.opentelemetry.extension.aws.AwsXrayPropagator; import java.util.Arrays; import java.util.Collections; import java.util.HashMap; @@ -265,51 +264,4 @@ protected List> getHeaders() { return traceHeaders; } } - - /** Benchmark for extracting context from AWS X-Ray trace header. */ - public static class AwsXrayHeaderContextExtractBenchmark extends AbstractContextExtractBenchmark { - - private static final List> traceHeaders = - Arrays.asList( - Collections.singletonMap( - "X-Amzn-Trace-Id", - "Root=1-8a3c60f7-d188f8fa79d48a391a778fa6;Parent=53995c3f42cd8ad8;Sampled=1"), - Collections.singletonMap( - "X-Amzn-Trace-Id", - "Root=1-8a3c60f7-d188f8fa79d48a391a778fa6;Parent=53995c3f42cd8ad8;Sampled=0"), - Collections.singletonMap( - "X-Amzn-Trace-Id", - "Parent=53995c3f42cd8ad8;Sampled=1;Root=1-8a3c60f7-d188f8fa79d48a391a778fa6"), - Collections.singletonMap( - "X-Amzn-Trace-Id", - "Root=1-57ff426a-80c11c39b0c928905eb0828d;Parent=53995c3f42cd8ad8;Sampled=1"), - Collections.singletonMap( - "X-Amzn-Trace-Id", - "Root=1-57ff426a-80c11c39b0c928905eb0828d;Parent=12345c3f42cd8ad8;Sampled=0")); - - private final TextMapGetter> getter = - new TextMapGetter>() { - @Override - public Iterable keys(Map carrier) { - return carrier.keySet(); - } - - @Override - public String get(Map carrier, String key) { - return carrier.get(key); - } - }; - - private final AwsXrayPropagator xrayPropagator = AwsXrayPropagator.getInstance(); - - @Override - protected Context doExtract() { - return xrayPropagator.extract(Context.current(), getCarrier(), getter); - } - - @Override - protected List> getHeaders() { - return traceHeaders; - } - } } diff --git a/extensions/trace-propagators/src/jmh/java/io/opentelemetry/extension/trace/propagation/PropagatorContextInjectBenchmark.java b/extensions/trace-propagators/src/jmh/java/io/opentelemetry/extension/trace/propagation/PropagatorContextInjectBenchmark.java index e5fa961a120..4b4bbaa9fb5 100644 --- a/extensions/trace-propagators/src/jmh/java/io/opentelemetry/extension/trace/propagation/PropagatorContextInjectBenchmark.java +++ b/extensions/trace-propagators/src/jmh/java/io/opentelemetry/extension/trace/propagation/PropagatorContextInjectBenchmark.java @@ -11,7 +11,6 @@ import io.opentelemetry.api.trace.TraceState; import io.opentelemetry.context.Context; import io.opentelemetry.context.propagation.TextMapSetter; -import io.opentelemetry.extension.aws.AwsXrayPropagator; import java.util.Arrays; import java.util.HashMap; import java.util.List; @@ -115,15 +114,4 @@ protected void doInject(Context context, Map carrier) { b3Propagator.inject(context, carrier, setter); } } - - /** Benchmark for injecting trace context into AWS X-Ray headers. */ - public static class AwsXrayPropagatorInjectBenchmark extends AbstractContextInjectBenchmark { - private final AwsXrayPropagator xrayPropagator = AwsXrayPropagator.getInstance(); - private final TextMapSetter> setter = Map::put; - - @Override - protected void doInject(Context context, Map carrier) { - xrayPropagator.inject(context, carrier, setter); - } - } } diff --git a/sdk-extensions/autoconfigure/build.gradle.kts b/sdk-extensions/autoconfigure/build.gradle.kts index 3b61f0a64f1..182e6389c92 100644 --- a/sdk-extensions/autoconfigure/build.gradle.kts +++ b/sdk-extensions/autoconfigure/build.gradle.kts @@ -76,7 +76,6 @@ testing { } val testFullConfig by registering(JvmTestSuite::class) { dependencies { - implementation(project(":extensions:aws")) implementation(project(":extensions:trace-propagators")) implementation(project(":exporters:jaeger")) implementation(project(":exporters:logging")) @@ -101,7 +100,7 @@ testing { testTask { environment("OTEL_LOGS_EXPORTER", "otlp") environment("OTEL_RESOURCE_ATTRIBUTES", "service.name=test,cat=meow") - environment("OTEL_PROPAGATORS", "tracecontext,baggage,b3,b3multi,jaeger,ottrace,xray,test") + environment("OTEL_PROPAGATORS", "tracecontext,baggage,b3,b3multi,jaeger,ottrace,test") environment("OTEL_BSP_SCHEDULE_DELAY", "10") environment("OTEL_METRIC_EXPORT_INTERVAL", "10") environment("OTEL_EXPORTER_OTLP_HEADERS", "cat=meow,dog=bark") 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 e1146893749..e2a797c940b 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 @@ -22,7 +22,6 @@ import io.opentelemetry.api.logs.Severity; import io.opentelemetry.api.metrics.Meter; import io.opentelemetry.api.trace.propagation.W3CTraceContextPropagator; -import io.opentelemetry.extension.aws.AwsXrayPropagator; import io.opentelemetry.extension.trace.propagation.B3Propagator; import io.opentelemetry.extension.trace.propagation.JaegerPropagator; import io.opentelemetry.extension.trace.propagation.OtTracePropagator; @@ -189,7 +188,6 @@ void configures() throws Exception { keys.addAll(B3Propagator.injectingMultiHeaders().fields()); keys.addAll(JaegerPropagator.getInstance().fields()); keys.addAll(OtTracePropagator.getInstance().fields()); - keys.addAll(AwsXrayPropagator.getInstance().fields()); // Added by TestPropagatorProvider keys.add("test"); assertThat(fields).containsExactlyInAnyOrderElementsOf(keys); From 85bae88e1c365e733c1ede1de06eba7cf4f3d98a Mon Sep 17 00:00:00 2001 From: jack-berg <34418638+jack-berg@users.noreply.github.com> Date: Wed, 2 Nov 2022 13:10:46 -0500 Subject: [PATCH 02/68] Add benchmark for log sdk (#4891) --- sdk/logs/build.gradle.kts | 1 + .../sdk/logs/LogsBenchmarks.java | 81 +++++++++++++++++++ 2 files changed, 82 insertions(+) create mode 100644 sdk/logs/src/jmh/java/io/opentelemetry/sdk/logs/LogsBenchmarks.java diff --git a/sdk/logs/build.gradle.kts b/sdk/logs/build.gradle.kts index ce4c851a3dc..f9d5d2a3e48 100644 --- a/sdk/logs/build.gradle.kts +++ b/sdk/logs/build.gradle.kts @@ -2,6 +2,7 @@ plugins { id("otel.java-conventions") id("otel.publish-conventions") + id("otel.jmh-conventions") id("otel.animalsniffer-conventions") } diff --git a/sdk/logs/src/jmh/java/io/opentelemetry/sdk/logs/LogsBenchmarks.java b/sdk/logs/src/jmh/java/io/opentelemetry/sdk/logs/LogsBenchmarks.java new file mode 100644 index 00000000000..b04baebab59 --- /dev/null +++ b/sdk/logs/src/jmh/java/io/opentelemetry/sdk/logs/LogsBenchmarks.java @@ -0,0 +1,81 @@ +/* + * Copyright The OpenTelemetry Authors + * SPDX-License-Identifier: Apache-2.0 + */ + +package io.opentelemetry.sdk.logs; + +import static java.util.stream.Collectors.joining; + +import io.opentelemetry.api.logs.Severity; +import java.util.ArrayList; +import java.util.List; +import java.util.Random; +import java.util.concurrent.TimeUnit; +import java.util.stream.IntStream; +import org.openjdk.jmh.annotations.Benchmark; +import org.openjdk.jmh.annotations.BenchmarkMode; +import org.openjdk.jmh.annotations.Fork; +import org.openjdk.jmh.annotations.Measurement; +import org.openjdk.jmh.annotations.Mode; +import org.openjdk.jmh.annotations.OutputTimeUnit; +import org.openjdk.jmh.annotations.Scope; +import org.openjdk.jmh.annotations.Setup; +import org.openjdk.jmh.annotations.State; +import org.openjdk.jmh.annotations.Threads; +import org.openjdk.jmh.annotations.Warmup; + +@BenchmarkMode({Mode.AverageTime}) +@OutputTimeUnit(TimeUnit.NANOSECONDS) +@Warmup(iterations = 5, time = 1) +@Measurement(iterations = 10, time = 1) +@Fork(1) +public class LogsBenchmarks { + + private static final Random RANDOM = new Random(); + + @State(Scope.Benchmark) + public static class BenchmarkState { + + private final SdkLoggerProvider sdk = + SdkLoggerProvider.builder() + .addLogRecordProcessor( + logRecord -> { + // Do nothing + }) + .build(); + + private List loggerNames; + + @Setup + public void setup() { + int numLoggers = 100; + loggerNames = new ArrayList<>(numLoggers); + for (int i = 0; i < numLoggers; i++) { + loggerNames.add( + IntStream.range(0, 50) + .mapToObj(unused -> String.valueOf((char) RANDOM.nextInt(26))) + .collect(joining())); + } + } + } + + /** + * Simulates the behavior of a log appender implementation, which has to bridge logs from logging + * frameworks (Log4j, Logback, etc). The name of the logger being bridged is used as the + * OpenTelemetry logger name. Therefore, each log processed has to obtain a logger. + */ + @Benchmark + @Threads(1) + public void emitSimpleLog(BenchmarkState benchmarkState) { + String loggerName = + benchmarkState.loggerNames.get(RANDOM.nextInt(benchmarkState.loggerNames.size())); + benchmarkState + .sdk + .get(loggerName) + .logRecordBuilder() + .setBody("log message body") + .setSeverity(Severity.DEBUG) + .emit(); + } +} From 435411b7da2000b6d660afd5d672029d11a64714 Mon Sep 17 00:00:00 2001 From: Carlos Alberto Cortez Date: Wed, 2 Nov 2022 21:05:59 +0100 Subject: [PATCH 03/68] Use opentracing-shim as instrumentation scope name. (#4890) --- .../io/opentelemetry/opentracingshim/OpenTracingShim.java | 2 +- .../io/opentelemetry/opentracingshim/OpenTracingShimTest.java | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) 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 db8152aa1d3..bbcab7d7447 100644 --- a/opentracing-shim/src/main/java/io/opentelemetry/opentracingshim/OpenTracingShim.java +++ b/opentracing-shim/src/main/java/io/opentelemetry/opentracingshim/OpenTracingShim.java @@ -65,6 +65,6 @@ public static io.opentracing.Tracer createTracerShim(OpenTelemetry openTelemetry } private static Tracer getTracer(TracerProvider tracerProvider) { - return tracerProvider.get("opentracingshim"); + return tracerProvider.get("opentracing-shim"); } } diff --git a/opentracing-shim/src/test/java/io/opentelemetry/opentracingshim/OpenTracingShimTest.java b/opentracing-shim/src/test/java/io/opentelemetry/opentracingshim/OpenTracingShimTest.java index 901977fb40e..00604c90289 100644 --- a/opentracing-shim/src/test/java/io/opentelemetry/opentracingshim/OpenTracingShimTest.java +++ b/opentracing-shim/src/test/java/io/opentelemetry/opentracingshim/OpenTracingShimTest.java @@ -28,7 +28,7 @@ void tearDown() { @Test void createTracerShim_default() { TracerShim tracerShim = (TracerShim) OpenTracingShim.createTracerShim(); - assertThat(tracerShim.tracer()).isEqualTo(GlobalOpenTelemetry.getTracer("opentracingshim")); + assertThat(tracerShim.tracer()).isEqualTo(GlobalOpenTelemetry.getTracer("opentracing-shim")); } @Test @@ -41,7 +41,7 @@ void createTracerShim_fromOpenTelemetryInstance() { when(openTelemetry.getPropagators()).thenReturn(contextPropagators); TracerShim tracerShim = (TracerShim) OpenTracingShim.createTracerShim(openTelemetry); - assertThat(tracerShim.tracer()).isEqualTo(sdk.get("opentracingshim")); + assertThat(tracerShim.tracer()).isEqualTo(sdk.get("opentracing-shim")); } @Test From fedcbbe889dbbd901ef24f14b43cbc3cd44643af Mon Sep 17 00:00:00 2001 From: jason plumb <75337021+breedx-splk@users.noreply.github.com> Date: Wed, 2 Nov 2022 18:13:28 -0700 Subject: [PATCH 04/68] Add missing javadoc param to ImmutableSpanContext.create() (#4903) * add missing param * change wording to indicate optimization * Update api/all/src/main/java/io/opentelemetry/api/internal/ImmutableSpanContext.java Co-authored-by: Mateusz Rzeszutek Co-authored-by: Mateusz Rzeszutek --- .../io/opentelemetry/api/internal/ImmutableSpanContext.java | 2 ++ 1 file changed, 2 insertions(+) diff --git a/api/all/src/main/java/io/opentelemetry/api/internal/ImmutableSpanContext.java b/api/all/src/main/java/io/opentelemetry/api/internal/ImmutableSpanContext.java index 886d67107de..13bfff66d99 100644 --- a/api/all/src/main/java/io/opentelemetry/api/internal/ImmutableSpanContext.java +++ b/api/all/src/main/java/io/opentelemetry/api/internal/ImmutableSpanContext.java @@ -54,6 +54,8 @@ private static AutoValue_ImmutableSpanContext createInternal( * @param traceFlags the trace flags of the {@code SpanContext}. * @param traceState the trace state for the {@code SpanContext}. * @param remote the remote flag for the {@code SpanContext}. + * @param skipIdValidation pass true to skip validation of trace ID and span ID as an optimization + * in cases where they are known to have been already validated. * @return a new {@code SpanContext} with the given identifiers and options. */ public static SpanContext create( From 329d342830a579428d2c59921bfadbbc801f20c0 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Thu, 3 Nov 2022 10:18:30 -0500 Subject: [PATCH 05/68] Bump equalsverifier from 3.10.1 to 3.11 (#4915) Bumps [equalsverifier](https://github.com/jqno/equalsverifier) from 3.10.1 to 3.11. - [Release notes](https://github.com/jqno/equalsverifier/releases) - [Changelog](https://github.com/jqno/equalsverifier/blob/main/CHANGELOG.md) - [Commits](https://github.com/jqno/equalsverifier/compare/equalsverifier-3.10.1...equalsverifier-3.11) --- updated-dependencies: - dependency-name: nl.jqno.equalsverifier:equalsverifier dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> --- dependencyManagement/build.gradle.kts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/dependencyManagement/build.gradle.kts b/dependencyManagement/build.gradle.kts index ff29a517c02..8ef30a22002 100644 --- a/dependencyManagement/build.gradle.kts +++ b/dependencyManagement/build.gradle.kts @@ -91,7 +91,7 @@ val DEPENDENCIES = listOf( "io.opentelemetry.proto:opentelemetry-proto:0.19.0-alpha", "io.opentracing:opentracing-api:0.33.0", "junit:junit:4.13.2", - "nl.jqno.equalsverifier:equalsverifier:3.10.1", + "nl.jqno.equalsverifier:equalsverifier:3.11", "org.assertj:assertj-core:3.23.1", "org.awaitility:awaitility:4.2.0", "org.bouncycastle:bcpkix-jdk15on:1.70", From 51ff803eb3d47d9b1fbe5e7de1aae004e9f52b40 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Thu, 3 Nov 2022 09:58:28 -0700 Subject: [PATCH 06/68] Bump nullaway from 0.10.3 to 0.10.4 (#4914) Bumps [nullaway](https://github.com/uber/NullAway) from 0.10.3 to 0.10.4. - [Release notes](https://github.com/uber/NullAway/releases) - [Changelog](https://github.com/uber/NullAway/blob/master/CHANGELOG.md) - [Commits](https://github.com/uber/NullAway/compare/v0.10.3...v0.10.4) --- updated-dependencies: - dependency-name: com.uber.nullaway:nullaway dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> --- dependencyManagement/build.gradle.kts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/dependencyManagement/build.gradle.kts b/dependencyManagement/build.gradle.kts index 8ef30a22002..baa6312cbc1 100644 --- a/dependencyManagement/build.gradle.kts +++ b/dependencyManagement/build.gradle.kts @@ -82,7 +82,7 @@ val DEPENDENCIES = listOf( "com.lmax:disruptor:3.4.4", "com.sun.net.httpserver:http:20070405", "com.tngtech.archunit:archunit-junit5:1.0.0", - "com.uber.nullaway:nullaway:0.10.3", + "com.uber.nullaway:nullaway:0.10.4", // TODO(anuraaga): Skip 1.8 because of https://github.com/rohanpadhye/JQF/issues/172 "edu.berkeley.cs.jqf:jqf-fuzz:1.7", "eu.rekawek.toxiproxy:toxiproxy-java:2.1.7", From 4c384627cfdc7e1e9afa18e1740e1aa5dce07a88 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Tue, 8 Nov 2022 10:53:10 -0600 Subject: [PATCH 07/68] Bump jackson-bom from 2.13.4.20221013 to 2.14.0 (#4921) Bumps [jackson-bom](https://github.com/FasterXML/jackson-bom) from 2.13.4.20221013 to 2.14.0. - [Release notes](https://github.com/FasterXML/jackson-bom/releases) - [Commits](https://github.com/FasterXML/jackson-bom/compare/jackson-bom-2.13.4.20221013...jackson-bom-2.14.0) --- updated-dependencies: - dependency-name: com.fasterxml.jackson:jackson-bom dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> --- dependencyManagement/build.gradle.kts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/dependencyManagement/build.gradle.kts b/dependencyManagement/build.gradle.kts index baa6312cbc1..ba244ee1bbb 100644 --- a/dependencyManagement/build.gradle.kts +++ b/dependencyManagement/build.gradle.kts @@ -12,7 +12,7 @@ val dependencyVersions = hashMapOf() rootProject.extra["versions"] = dependencyVersions val DEPENDENCY_BOMS = listOf( - "com.fasterxml.jackson:jackson-bom:2.13.4.20221013", + "com.fasterxml.jackson:jackson-bom:2.14.0", "com.google.guava:guava-bom:31.1-jre", "com.google.protobuf:protobuf-bom:3.21.9", "com.linecorp.armeria:armeria-bom:1.20.1", From 148638981cf0d3fe89534aa7a862e673529409ae Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Tue, 8 Nov 2022 10:53:32 -0600 Subject: [PATCH 08/68] Bump org.graalvm.buildtools.native from 0.9.16 to 0.9.17 (#4922) Bumps [org.graalvm.buildtools.native](https://github.com/graalvm/native-build-tools) from 0.9.16 to 0.9.17. - [Release notes](https://github.com/graalvm/native-build-tools/releases) - [Commits](https://github.com/graalvm/native-build-tools/compare/0.9.16...0.9.17) --- updated-dependencies: - dependency-name: org.graalvm.buildtools.native dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> --- settings.gradle.kts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/settings.gradle.kts b/settings.gradle.kts index 8d1081c96e2..bbd7c950d30 100644 --- a/settings.gradle.kts +++ b/settings.gradle.kts @@ -5,7 +5,7 @@ pluginManagement { id("com.gradle.enterprise") version "3.11.3" id("io.github.gradle-nexus.publish-plugin") version "1.1.0" id("org.jetbrains.kotlin.jvm") version "1.7.20" - id("org.graalvm.buildtools.native") version "0.9.16" + id("org.graalvm.buildtools.native") version "0.9.17" } } From 18bc8b84383ef1d803e3cd0b26165672e7271a2a Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Tue, 8 Nov 2022 10:54:03 -0600 Subject: [PATCH 09/68] Bump proto-google-common-protos from 2.9.6 to 2.10.0 (#4923) Bumps [proto-google-common-protos](https://github.com/googleapis/java-iam) from 2.9.6 to 2.10.0. - [Release notes](https://github.com/googleapis/java-iam/releases) - [Changelog](https://github.com/googleapis/java-iam/blob/main/CHANGELOG.md) - [Commits](https://github.com/googleapis/java-iam/commits) --- updated-dependencies: - dependency-name: com.google.api.grpc:proto-google-common-protos dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> --- dependencyManagement/build.gradle.kts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/dependencyManagement/build.gradle.kts b/dependencyManagement/build.gradle.kts index ba244ee1bbb..60539fd5a6f 100644 --- a/dependencyManagement/build.gradle.kts +++ b/dependencyManagement/build.gradle.kts @@ -76,7 +76,7 @@ val DEPENDENCY_SETS = listOf( val DEPENDENCIES = listOf( "com.github.stefanbirkner:system-rules:1.19.0", - "com.google.api.grpc:proto-google-common-protos:2.9.6", + "com.google.api.grpc:proto-google-common-protos:2.10.0", "com.google.code.findbugs:jsr305:3.0.2", "com.google.guava:guava-beta-checker:1.0", "com.lmax:disruptor:3.4.4", From 68ab2f68400777357a85ef03dc78c6fa1e34d264 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Tue, 8 Nov 2022 13:27:52 -0600 Subject: [PATCH 10/68] Bump armeria-bom from 1.20.1 to 1.20.2 (#4924) Bumps [armeria-bom](https://github.com/line/armeria) from 1.20.1 to 1.20.2. - [Release notes](https://github.com/line/armeria/releases) - [Changelog](https://github.com/line/armeria/blob/master/.post-release-msg) - [Commits](https://github.com/line/armeria/compare/armeria-1.20.1...armeria-1.20.2) --- updated-dependencies: - dependency-name: com.linecorp.armeria:armeria-bom dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> --- dependencyManagement/build.gradle.kts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/dependencyManagement/build.gradle.kts b/dependencyManagement/build.gradle.kts index 60539fd5a6f..56106bf865a 100644 --- a/dependencyManagement/build.gradle.kts +++ b/dependencyManagement/build.gradle.kts @@ -15,7 +15,7 @@ val DEPENDENCY_BOMS = listOf( "com.fasterxml.jackson:jackson-bom:2.14.0", "com.google.guava:guava-bom:31.1-jre", "com.google.protobuf:protobuf-bom:3.21.9", - "com.linecorp.armeria:armeria-bom:1.20.1", + "com.linecorp.armeria:armeria-bom:1.20.2", "com.squareup.okhttp3:okhttp-bom:4.10.0", "io.grpc:grpc-bom:1.50.2", "io.zipkin.brave:brave-bom:5.14.1", From 112b891602744bbac52115c411c11298e7f0bc6a Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Tue, 8 Nov 2022 13:45:19 -0600 Subject: [PATCH 11/68] Bump gradle-nullaway-plugin from 1.4.0 to 1.5.0 (#4925) Bumps gradle-nullaway-plugin from 1.4.0 to 1.5.0. --- updated-dependencies: - dependency-name: net.ltgt.gradle:gradle-nullaway-plugin dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> --- buildSrc/build.gradle.kts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/buildSrc/build.gradle.kts b/buildSrc/build.gradle.kts index 8fe99cd4f7e..63d43ef97d2 100644 --- a/buildSrc/build.gradle.kts +++ b/buildSrc/build.gradle.kts @@ -25,7 +25,7 @@ dependencies { implementation("me.champeau.gradle:japicmp-gradle-plugin:0.4.1") implementation("me.champeau.jmh:jmh-gradle-plugin:0.6.8") implementation("net.ltgt.gradle:gradle-errorprone-plugin:3.0.1") - implementation("net.ltgt.gradle:gradle-nullaway-plugin:1.4.0") + implementation("net.ltgt.gradle:gradle-nullaway-plugin:1.5.0") implementation("ru.vyarus:gradle-animalsniffer-plugin:1.6.0") } From f8a4d81e2415f7052543f32f5b2a6a8bc33cf0ed Mon Sep 17 00:00:00 2001 From: jack-berg <34418638+jack-berg@users.noreply.github.com> Date: Tue, 8 Nov 2022 17:05:00 -0600 Subject: [PATCH 12/68] Optimize log hot path (#4913) * ComponentRegistry accepts name, version, schemaUrl instead of InstrumentationScopeInfo * Fix comment --- .../sdk/internal/ComponentRegistry.java | 94 ++++++++++++++++--- .../sdk/internal/ComponentRegistryTest.java | 93 +++++------------- .../sdk/logs/SdkLoggerBuilder.java | 17 ++-- .../sdk/logs/SdkLoggerProvider.java | 14 ++- .../sdk/metrics/SdkMeterBuilder.java | 17 ++-- .../sdk/trace/SdkTracerBuilder.java | 17 ++-- 6 files changed, 143 insertions(+), 109 deletions(-) diff --git a/sdk/common/src/main/java/io/opentelemetry/sdk/internal/ComponentRegistry.java b/sdk/common/src/main/java/io/opentelemetry/sdk/internal/ComponentRegistry.java index 952451df410..93215cf2bf4 100644 --- a/sdk/common/src/main/java/io/opentelemetry/sdk/internal/ComponentRegistry.java +++ b/sdk/common/src/main/java/io/opentelemetry/sdk/internal/ComponentRegistry.java @@ -5,18 +5,32 @@ package io.opentelemetry.sdk.internal; +import io.opentelemetry.api.common.Attributes; import io.opentelemetry.sdk.common.InstrumentationScopeInfo; -import java.util.ArrayList; import java.util.Collection; import java.util.Collections; +import java.util.IdentityHashMap; +import java.util.Map; +import java.util.Set; import java.util.concurrent.ConcurrentHashMap; -import java.util.concurrent.ConcurrentMap; import java.util.function.Function; +import javax.annotation.Nullable; /** * Component (tracer, meter, etc) registry class for all the provider classes (TracerProvider, * MeterProvider, etc.). * + *

Components are identified by name, version, and schema. Name is required, but version and + * schema are optional. Therefore, we have 4 possible scenarios for component keys: + * + *

    + *
  1. Only name is provided, represented by {@link #componentByName} + *
  2. Name and version are provided, represented by {@link #componentByNameAndVersion} + *
  3. Name and schema are provided, represented by {@link #componentByNameAndSchema} + *
  4. Name, version and schema are provided, represented by {@link + * #componentByNameVersionAndSchema} + *
+ * *

This class is internal and is hence not for public use. Its APIs are unstable and can change * at any time. * @@ -24,7 +38,14 @@ */ public final class ComponentRegistry { - private final ConcurrentMap registry = new ConcurrentHashMap<>(); + private final Map componentByName = new ConcurrentHashMap<>(); + private final Map> componentByNameAndVersion = new ConcurrentHashMap<>(); + private final Map> componentByNameAndSchema = new ConcurrentHashMap<>(); + private final Map>> componentByNameVersionAndSchema = + new ConcurrentHashMap<>(); + + private final Set allComponents = Collections.newSetFromMap(new IdentityHashMap<>()); + private final Function factory; public ComponentRegistry(Function factory) { @@ -32,19 +53,64 @@ public ComponentRegistry(Function factory) { } /** - * Returns the registered value associated with this {@link InstrumentationScopeInfo scope} if - * any, otherwise creates a new instance and associates it with the given scope. + * Returns the component associated with the {@code name}, {@code version}, and {@code schemaUrl}. + * {@link Attributes} are not part of component identity. Behavior is undefined when different + * {@link Attributes} are provided where {@code name}, {@code version}, and {@code schemaUrl} are + * identical. */ - public V get(InstrumentationScopeInfo instrumentationScopeInfo) { - // Optimistic lookup, before creating the new component. - V component = registry.get(instrumentationScopeInfo); - if (component != null) { - return component; + public V get( + String name, @Nullable String version, @Nullable String schemaUrl, Attributes attributes) { + if (version != null && schemaUrl != null) { + Map> componentByVersionAndSchema = + componentByNameVersionAndSchema.computeIfAbsent( + name, unused -> new ConcurrentHashMap<>()); + Map componentBySchema = + componentByVersionAndSchema.computeIfAbsent(version, unused -> new ConcurrentHashMap<>()); + return componentBySchema.computeIfAbsent( + schemaUrl, + schemaUrl1 -> + buildComponent( + InstrumentationScopeInfo.builder(name) + .setVersion(version) + .setSchemaUrl(schemaUrl1) + .setAttributes(attributes) + .build())); + } else if (version != null) { // schemaUrl == null + Map componentByVersion = + componentByNameAndVersion.computeIfAbsent(name, unused -> new ConcurrentHashMap<>()); + return componentByVersion.computeIfAbsent( + version, + version1 -> + buildComponent( + InstrumentationScopeInfo.builder(name) + .setVersion(version1) + .setAttributes(attributes) + .build())); + } + if (schemaUrl != null) { // version == null + Map componentBySchema = + componentByNameAndSchema.computeIfAbsent(name, unused -> new ConcurrentHashMap<>()); + return componentBySchema.computeIfAbsent( + schemaUrl, + schemaUrl1 -> + buildComponent( + InstrumentationScopeInfo.builder(name) + .setSchemaUrl(schemaUrl1) + .setAttributes(attributes) + .build())); + } else { // schemaUrl == null && version == null + return componentByName.computeIfAbsent( + name, + name1 -> + buildComponent( + InstrumentationScopeInfo.builder(name1).setAttributes(attributes).build())); } + } - V newComponent = factory.apply(instrumentationScopeInfo); - V oldComponent = registry.putIfAbsent(instrumentationScopeInfo, newComponent); - return oldComponent != null ? oldComponent : newComponent; + private V buildComponent(InstrumentationScopeInfo instrumentationScopeInfo) { + V component = factory.apply(instrumentationScopeInfo); + allComponents.add(component); + return component; } /** @@ -53,6 +119,6 @@ public V get(InstrumentationScopeInfo instrumentationScopeInfo) { * @return a {@code Collection} view of the registered components. */ public Collection getComponents() { - return Collections.unmodifiableCollection(new ArrayList<>(registry.values())); + return Collections.unmodifiableCollection(allComponents); } } diff --git a/sdk/common/src/test/java/io/opentelemetry/sdk/internal/ComponentRegistryTest.java b/sdk/common/src/test/java/io/opentelemetry/sdk/internal/ComponentRegistryTest.java index db52d7c71d1..1e566b28972 100644 --- a/sdk/common/src/test/java/io/opentelemetry/sdk/internal/ComponentRegistryTest.java +++ b/sdk/common/src/test/java/io/opentelemetry/sdk/internal/ComponentRegistryTest.java @@ -8,7 +8,6 @@ import static org.assertj.core.api.Assertions.assertThat; import io.opentelemetry.api.common.Attributes; -import io.opentelemetry.sdk.common.InstrumentationScopeInfo; import org.junit.jupiter.api.Test; class ComponentRegistryTest { @@ -22,83 +21,35 @@ class ComponentRegistryTest { @Test void get_SameInstance() { - assertThat(registry.get(InstrumentationScopeInfo.builder(NAME).build())) - .isSameAs(registry.get(InstrumentationScopeInfo.builder(NAME).build())); - assertThat(registry.get(InstrumentationScopeInfo.builder(NAME).setVersion(VERSION).build())) - .isSameAs(registry.get(InstrumentationScopeInfo.builder(NAME).setVersion(VERSION).build())); - assertThat( - registry.get(InstrumentationScopeInfo.builder(NAME).setSchemaUrl(SCHEMA_URL).build())) + assertThat(registry.get(NAME, null, null, Attributes.empty())) + .isSameAs(registry.get(NAME, null, null, Attributes.empty())) + .isSameAs(registry.get(NAME, null, null, Attributes.builder().put("k1", "v2").build())); + + assertThat(registry.get(NAME, VERSION, null, Attributes.empty())) + .isSameAs(registry.get(NAME, VERSION, null, Attributes.empty())) + .isSameAs(registry.get(NAME, VERSION, null, Attributes.builder().put("k1", "v2").build())); + assertThat(registry.get(NAME, null, SCHEMA_URL, Attributes.empty())) + .isSameAs(registry.get(NAME, null, SCHEMA_URL, Attributes.empty())) .isSameAs( - registry.get(InstrumentationScopeInfo.builder(NAME).setSchemaUrl(SCHEMA_URL).build())); - assertThat( - registry.get(InstrumentationScopeInfo.builder(NAME).setAttributes(ATTRIBUTES).build())) + registry.get(NAME, null, SCHEMA_URL, Attributes.builder().put("k1", "v2").build())); + assertThat(registry.get(NAME, VERSION, SCHEMA_URL, Attributes.empty())) + .isSameAs(registry.get(NAME, VERSION, SCHEMA_URL, Attributes.empty())) .isSameAs( - registry.get(InstrumentationScopeInfo.builder(NAME).setAttributes(ATTRIBUTES).build())); - assertThat( - registry.get( - InstrumentationScopeInfo.builder(NAME) - .setVersion(VERSION) - .setSchemaUrl(SCHEMA_URL) - .setAttributes(ATTRIBUTES) - .build())) - .isSameAs( - registry.get( - InstrumentationScopeInfo.builder(NAME) - .setVersion(VERSION) - .setSchemaUrl(SCHEMA_URL) - .setAttributes(ATTRIBUTES) - .build())); + registry.get(NAME, VERSION, SCHEMA_URL, Attributes.builder().put("k1", "v2").build())); } @Test void get_DifferentInstance() { - InstrumentationScopeInfo allFields = - InstrumentationScopeInfo.builder(NAME) - .setVersion(VERSION) - .setSchemaUrl(SCHEMA_URL) - .setAttributes(ATTRIBUTES) - .build(); + assertThat(registry.get(NAME, VERSION, SCHEMA_URL, ATTRIBUTES)) + .isNotSameAs(registry.get(NAME + "_1", VERSION, SCHEMA_URL, ATTRIBUTES)) + .isNotSameAs(registry.get(NAME, VERSION + "_1", SCHEMA_URL, ATTRIBUTES)) + .isNotSameAs(registry.get(NAME, VERSION, SCHEMA_URL + "_1", ATTRIBUTES)); + + assertThat(registry.get(NAME, VERSION, null, Attributes.empty())) + .isNotSameAs(registry.get(NAME, null, null, Attributes.empty())); - assertThat(registry.get(allFields)) - .isNotSameAs( - registry.get( - InstrumentationScopeInfo.builder(NAME + "_1") - .setVersion(VERSION) - .setSchemaUrl(SCHEMA_URL) - .setAttributes(ATTRIBUTES) - .build())); - assertThat(registry.get(allFields)) - .isNotSameAs( - registry.get( - InstrumentationScopeInfo.builder(NAME) - .setVersion(VERSION + "_1") - .setSchemaUrl(SCHEMA_URL) - .setAttributes(ATTRIBUTES) - .build())); - assertThat(registry.get(allFields)) - .isNotSameAs( - registry.get( - InstrumentationScopeInfo.builder(NAME) - .setVersion(VERSION) - .setSchemaUrl(SCHEMA_URL + "_1") - .setAttributes(ATTRIBUTES) - .build())); - assertThat(registry.get(allFields)) - .isNotSameAs( - registry.get( - InstrumentationScopeInfo.builder(NAME) - .setVersion(VERSION) - .setSchemaUrl(SCHEMA_URL) - .setAttributes(Attributes.builder().put("k1", "v2").build()) - .build())); - assertThat(registry.get(InstrumentationScopeInfo.builder(NAME).setVersion(VERSION).build())) - .isNotSameAs(registry.get(InstrumentationScopeInfo.builder(NAME).build())); - assertThat( - registry.get(InstrumentationScopeInfo.builder(NAME).setSchemaUrl(SCHEMA_URL).build())) - .isNotSameAs(registry.get(InstrumentationScopeInfo.builder(NAME).build())); - assertThat( - registry.get(InstrumentationScopeInfo.builder(NAME).setAttributes(ATTRIBUTES).build())) - .isNotSameAs(registry.get(InstrumentationScopeInfo.builder(NAME).build())); + assertThat(registry.get(NAME, null, SCHEMA_URL, Attributes.empty())) + .isNotSameAs(registry.get(NAME, null, null, Attributes.empty())); } private static final class TestComponent {} diff --git a/sdk/logs/src/main/java/io/opentelemetry/sdk/logs/SdkLoggerBuilder.java b/sdk/logs/src/main/java/io/opentelemetry/sdk/logs/SdkLoggerBuilder.java index 8d3eeaeb7c1..d497e25f7cd 100644 --- a/sdk/logs/src/main/java/io/opentelemetry/sdk/logs/SdkLoggerBuilder.java +++ b/sdk/logs/src/main/java/io/opentelemetry/sdk/logs/SdkLoggerBuilder.java @@ -5,21 +5,22 @@ package io.opentelemetry.sdk.logs; +import io.opentelemetry.api.common.Attributes; import io.opentelemetry.api.logs.LoggerBuilder; -import io.opentelemetry.sdk.common.InstrumentationScopeInfo; -import io.opentelemetry.sdk.common.InstrumentationScopeInfoBuilder; import io.opentelemetry.sdk.internal.ComponentRegistry; import javax.annotation.Nullable; final class SdkLoggerBuilder implements LoggerBuilder { private final ComponentRegistry registry; - private final InstrumentationScopeInfoBuilder scopeBuilder; + private final String instrumentationScopeName; + @Nullable private String instrumentationScopeVersion; + @Nullable private String schemaUrl; @Nullable private String eventDomain; SdkLoggerBuilder(ComponentRegistry registry, String instrumentationScopeName) { this.registry = registry; - this.scopeBuilder = InstrumentationScopeInfo.builder(instrumentationScopeName); + this.instrumentationScopeName = instrumentationScopeName; } @Override @@ -30,19 +31,21 @@ public LoggerBuilder setEventDomain(String eventDomain) { @Override public SdkLoggerBuilder setSchemaUrl(String schemaUrl) { - scopeBuilder.setSchemaUrl(schemaUrl); + this.schemaUrl = schemaUrl; return this; } @Override public SdkLoggerBuilder setInstrumentationVersion(String instrumentationScopeVersion) { - scopeBuilder.setVersion(instrumentationScopeVersion); + this.instrumentationScopeVersion = instrumentationScopeVersion; return this; } @Override public SdkLogger build() { - SdkLogger logger = registry.get(scopeBuilder.build()); + SdkLogger logger = + registry.get( + instrumentationScopeName, instrumentationScopeVersion, schemaUrl, Attributes.empty()); return eventDomain == null ? logger : logger.withEventDomain(eventDomain); } } diff --git a/sdk/logs/src/main/java/io/opentelemetry/sdk/logs/SdkLoggerProvider.java b/sdk/logs/src/main/java/io/opentelemetry/sdk/logs/SdkLoggerProvider.java index e64190d4d94..478700742d6 100644 --- a/sdk/logs/src/main/java/io/opentelemetry/sdk/logs/SdkLoggerProvider.java +++ b/sdk/logs/src/main/java/io/opentelemetry/sdk/logs/SdkLoggerProvider.java @@ -5,6 +5,7 @@ package io.opentelemetry.sdk.logs; +import io.opentelemetry.api.common.Attributes; import io.opentelemetry.api.logs.Logger; import io.opentelemetry.api.logs.LoggerBuilder; import io.opentelemetry.api.logs.LoggerProvider; @@ -17,6 +18,7 @@ import java.util.concurrent.TimeUnit; import java.util.function.Supplier; import java.util.logging.Level; +import javax.annotation.Nullable; /** SDK implementation for {@link LoggerProvider}. */ public final class SdkLoggerProvider implements LoggerProvider, Closeable { @@ -61,7 +63,8 @@ public static SdkLoggerProviderBuilder builder() { */ @Override public Logger get(String instrumentationScopeName) { - return loggerBuilder(instrumentationScopeName).build(); + return loggerComponentRegistry.get( + instrumentationNameOrDefault(instrumentationScopeName), null, null, Attributes.empty()); } /** @@ -75,11 +78,16 @@ public LoggerBuilder loggerBuilder(String instrumentationScopeName) { if (isNoopLogRecordProcessor) { return LoggerProvider.noop().loggerBuilder(instrumentationScopeName); } + return new SdkLoggerBuilder( + loggerComponentRegistry, instrumentationNameOrDefault(instrumentationScopeName)); + } + + private static String instrumentationNameOrDefault(@Nullable String instrumentationScopeName) { if (instrumentationScopeName == null || instrumentationScopeName.isEmpty()) { LOGGER.fine("Logger requested without instrumentation scope name."); - instrumentationScopeName = DEFAULT_LOGGER_NAME; + return DEFAULT_LOGGER_NAME; } - return new SdkLoggerBuilder(loggerComponentRegistry, instrumentationScopeName); + return instrumentationScopeName; } /** diff --git a/sdk/metrics/src/main/java/io/opentelemetry/sdk/metrics/SdkMeterBuilder.java b/sdk/metrics/src/main/java/io/opentelemetry/sdk/metrics/SdkMeterBuilder.java index 317b140c033..fde47070f29 100644 --- a/sdk/metrics/src/main/java/io/opentelemetry/sdk/metrics/SdkMeterBuilder.java +++ b/sdk/metrics/src/main/java/io/opentelemetry/sdk/metrics/SdkMeterBuilder.java @@ -5,36 +5,39 @@ package io.opentelemetry.sdk.metrics; +import io.opentelemetry.api.common.Attributes; import io.opentelemetry.api.metrics.Meter; import io.opentelemetry.api.metrics.MeterBuilder; -import io.opentelemetry.sdk.common.InstrumentationScopeInfo; -import io.opentelemetry.sdk.common.InstrumentationScopeInfoBuilder; import io.opentelemetry.sdk.internal.ComponentRegistry; +import javax.annotation.Nullable; class SdkMeterBuilder implements MeterBuilder { private final ComponentRegistry registry; - private final InstrumentationScopeInfoBuilder scopeBuilder; + private final String instrumentationScopeName; + @Nullable private String instrumentationScopeVersion; + @Nullable private String schemaUrl; SdkMeterBuilder(ComponentRegistry registry, String instrumentationScopeName) { this.registry = registry; - this.scopeBuilder = InstrumentationScopeInfo.builder(instrumentationScopeName); + this.instrumentationScopeName = instrumentationScopeName; } @Override public MeterBuilder setSchemaUrl(String schemaUrl) { - scopeBuilder.setSchemaUrl(schemaUrl); + this.schemaUrl = schemaUrl; return this; } @Override public MeterBuilder setInstrumentationVersion(String instrumentationScopeVersion) { - scopeBuilder.setVersion(instrumentationScopeVersion); + this.instrumentationScopeVersion = instrumentationScopeVersion; return this; } @Override public Meter build() { - return registry.get(scopeBuilder.build()); + return registry.get( + instrumentationScopeName, instrumentationScopeVersion, schemaUrl, Attributes.empty()); } } diff --git a/sdk/trace/src/main/java/io/opentelemetry/sdk/trace/SdkTracerBuilder.java b/sdk/trace/src/main/java/io/opentelemetry/sdk/trace/SdkTracerBuilder.java index 6e9e4db321a..6c6976a7d52 100644 --- a/sdk/trace/src/main/java/io/opentelemetry/sdk/trace/SdkTracerBuilder.java +++ b/sdk/trace/src/main/java/io/opentelemetry/sdk/trace/SdkTracerBuilder.java @@ -5,36 +5,39 @@ package io.opentelemetry.sdk.trace; +import io.opentelemetry.api.common.Attributes; import io.opentelemetry.api.trace.Tracer; import io.opentelemetry.api.trace.TracerBuilder; -import io.opentelemetry.sdk.common.InstrumentationScopeInfo; -import io.opentelemetry.sdk.common.InstrumentationScopeInfoBuilder; import io.opentelemetry.sdk.internal.ComponentRegistry; +import javax.annotation.Nullable; class SdkTracerBuilder implements TracerBuilder { private final ComponentRegistry registry; - private final InstrumentationScopeInfoBuilder scopeBuilder; + private final String instrumentationScopeName; + @Nullable private String instrumentationScopeVersion; + @Nullable private String schemaUrl; SdkTracerBuilder(ComponentRegistry registry, String instrumentationScopeName) { this.registry = registry; - this.scopeBuilder = InstrumentationScopeInfo.builder(instrumentationScopeName); + this.instrumentationScopeName = instrumentationScopeName; } @Override public TracerBuilder setSchemaUrl(String schemaUrl) { - scopeBuilder.setSchemaUrl(schemaUrl); + this.schemaUrl = schemaUrl; return this; } @Override public TracerBuilder setInstrumentationVersion(String instrumentationScopeVersion) { - scopeBuilder.setVersion(instrumentationScopeVersion); + this.instrumentationScopeVersion = instrumentationScopeVersion; return this; } @Override public Tracer build() { - return registry.get(scopeBuilder.build()); + return registry.get( + instrumentationScopeName, instrumentationScopeVersion, schemaUrl, Attributes.empty()); } } From 2e9deb480a0ac669989b7ffa8a66cda54fd3ff97 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Wed, 9 Nov 2022 09:20:14 -0800 Subject: [PATCH 13/68] Bump com.gradle.enterprise from 3.11.3 to 3.11.4 (#4928) Bumps com.gradle.enterprise from 3.11.3 to 3.11.4. --- updated-dependencies: - dependency-name: com.gradle.enterprise dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> --- settings.gradle.kts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/settings.gradle.kts b/settings.gradle.kts index bbd7c950d30..aa92f6f6e1a 100644 --- a/settings.gradle.kts +++ b/settings.gradle.kts @@ -2,7 +2,7 @@ pluginManagement { plugins { id("com.github.ben-manes.versions") version "0.43.0" id("com.github.johnrengelman.shadow") version "7.1.2" - id("com.gradle.enterprise") version "3.11.3" + id("com.gradle.enterprise") version "3.11.4" id("io.github.gradle-nexus.publish-plugin") version "1.1.0" id("org.jetbrains.kotlin.jvm") version "1.7.20" id("org.graalvm.buildtools.native") version "0.9.17" From b60f4e20b8ac5c4251a3dfbfe242e5e221ebd4b1 Mon Sep 17 00:00:00 2001 From: jack-berg <34418638+jack-berg@users.noreply.github.com> Date: Wed, 9 Nov 2022 11:59:06 -0600 Subject: [PATCH 14/68] Add context argument to LogRecordProcessor#onEmit (#4889) * Add context argument to LogRecordProcessor#onEmit * Change argument order --- .../sdk/logs/LogRecordProcessor.java | 5 +- .../sdk/logs/MultiLogRecordProcessor.java | 5 +- .../sdk/logs/NoopLogRecordProcessor.java | 4 +- .../sdk/logs/SdkLogRecordBuilder.java | 9 ++-- .../sdk/logs/SdkLoggerProviderBuilder.java | 6 ++- .../logs/export/BatchLogRecordProcessor.java | 3 +- .../logs/export/SimpleLogRecordProcessor.java | 3 +- .../sdk/logs/MultiLogRecordProcessorTest.java | 10 ++-- .../sdk/logs/NoopLogRecordProcessorTest.java | 3 +- .../sdk/logs/SdkLogRecordBuilderTest.java | 3 +- .../sdk/logs/SdkLoggerProviderTest.java | 52 ++++++++++++++++++- .../opentelemetry/sdk/logs/SdkLoggerTest.java | 12 +++-- .../export/BatchLogRecordProcessorTest.java | 2 +- .../export/SimpleLogRecordProcessorTest.java | 15 +++--- 14 files changed, 99 insertions(+), 33 deletions(-) diff --git a/sdk/logs/src/main/java/io/opentelemetry/sdk/logs/LogRecordProcessor.java b/sdk/logs/src/main/java/io/opentelemetry/sdk/logs/LogRecordProcessor.java index 6dcdf279fc6..df46275ba58 100644 --- a/sdk/logs/src/main/java/io/opentelemetry/sdk/logs/LogRecordProcessor.java +++ b/sdk/logs/src/main/java/io/opentelemetry/sdk/logs/LogRecordProcessor.java @@ -7,6 +7,7 @@ import io.opentelemetry.api.logs.LogRecordBuilder; import io.opentelemetry.api.logs.Logger; +import io.opentelemetry.context.Context; import io.opentelemetry.sdk.common.CompletableResultCode; import java.io.Closeable; import java.util.ArrayList; @@ -51,9 +52,11 @@ static LogRecordProcessor composite(Iterable processors) { /** * Called when a {@link Logger} {@link LogRecordBuilder#emit()}s a log record. * + * @param context the context set via {@link LogRecordBuilder#setContext(Context)}, or {@link + * Context#current()} if not explicitly set * @param logRecord the log record */ - void onEmit(ReadWriteLogRecord logRecord); + void onEmit(Context context, ReadWriteLogRecord logRecord); /** * Shutdown the log processor. diff --git a/sdk/logs/src/main/java/io/opentelemetry/sdk/logs/MultiLogRecordProcessor.java b/sdk/logs/src/main/java/io/opentelemetry/sdk/logs/MultiLogRecordProcessor.java index 25fe6a5049d..e84b38c86b6 100644 --- a/sdk/logs/src/main/java/io/opentelemetry/sdk/logs/MultiLogRecordProcessor.java +++ b/sdk/logs/src/main/java/io/opentelemetry/sdk/logs/MultiLogRecordProcessor.java @@ -5,6 +5,7 @@ package io.opentelemetry.sdk.logs; +import io.opentelemetry.context.Context; import io.opentelemetry.sdk.common.CompletableResultCode; import java.util.ArrayList; import java.util.List; @@ -33,9 +34,9 @@ static LogRecordProcessor create(List logRecordProcessorsLis } @Override - public void onEmit(ReadWriteLogRecord logRecord) { + public void onEmit(Context context, ReadWriteLogRecord logRecord) { for (LogRecordProcessor logRecordProcessor : logRecordProcessors) { - logRecordProcessor.onEmit(logRecord); + logRecordProcessor.onEmit(context, logRecord); } } diff --git a/sdk/logs/src/main/java/io/opentelemetry/sdk/logs/NoopLogRecordProcessor.java b/sdk/logs/src/main/java/io/opentelemetry/sdk/logs/NoopLogRecordProcessor.java index 24af6885a69..518cdfa785a 100644 --- a/sdk/logs/src/main/java/io/opentelemetry/sdk/logs/NoopLogRecordProcessor.java +++ b/sdk/logs/src/main/java/io/opentelemetry/sdk/logs/NoopLogRecordProcessor.java @@ -5,6 +5,8 @@ package io.opentelemetry.sdk.logs; +import io.opentelemetry.context.Context; + final class NoopLogRecordProcessor implements LogRecordProcessor { private static final NoopLogRecordProcessor INSTANCE = new NoopLogRecordProcessor(); @@ -15,5 +17,5 @@ static LogRecordProcessor getInstance() { private NoopLogRecordProcessor() {} @Override - public void onEmit(ReadWriteLogRecord logRecord) {} + public void onEmit(Context context, ReadWriteLogRecord logRecord) {} } diff --git a/sdk/logs/src/main/java/io/opentelemetry/sdk/logs/SdkLogRecordBuilder.java b/sdk/logs/src/main/java/io/opentelemetry/sdk/logs/SdkLogRecordBuilder.java index 0c333cc6fc3..e1f159aff3d 100644 --- a/sdk/logs/src/main/java/io/opentelemetry/sdk/logs/SdkLogRecordBuilder.java +++ b/sdk/logs/src/main/java/io/opentelemetry/sdk/logs/SdkLogRecordBuilder.java @@ -10,7 +10,6 @@ import io.opentelemetry.api.logs.LogRecordBuilder; import io.opentelemetry.api.logs.Severity; import io.opentelemetry.api.trace.Span; -import io.opentelemetry.api.trace.SpanContext; import io.opentelemetry.context.Context; import io.opentelemetry.sdk.common.InstrumentationScopeInfo; import io.opentelemetry.sdk.internal.AttributesMap; @@ -27,7 +26,7 @@ final class SdkLogRecordBuilder implements EventBuilder { private final InstrumentationScopeInfo instrumentationScopeInfo; private long epochNanos; - private SpanContext spanContext = SpanContext.getInvalid(); + @Nullable private Context context; private Severity severity = Severity.UNDEFINED_SEVERITY_NUMBER; @Nullable private String severityText; private Body body = Body.empty(); @@ -54,7 +53,7 @@ public SdkLogRecordBuilder setEpoch(Instant instant) { @Override public SdkLogRecordBuilder setContext(Context context) { - this.spanContext = Span.fromContext(context).getSpanContext(); + this.context = context; return this; } @@ -95,15 +94,17 @@ public void emit() { if (loggerSharedState.hasBeenShutdown()) { return; } + Context context = this.context == null ? Context.current() : this.context; loggerSharedState .getLogRecordProcessor() .onEmit( + context, SdkReadWriteLogRecord.create( loggerSharedState.getLogLimits(), loggerSharedState.getResource(), instrumentationScopeInfo, this.epochNanos == 0 ? this.loggerSharedState.getClock().now() : this.epochNanos, - spanContext, + Span.fromContext(context).getSpanContext(), severity, severityText, body, diff --git a/sdk/logs/src/main/java/io/opentelemetry/sdk/logs/SdkLoggerProviderBuilder.java b/sdk/logs/src/main/java/io/opentelemetry/sdk/logs/SdkLoggerProviderBuilder.java index 6f99640cf18..0b2ed52a753 100644 --- a/sdk/logs/src/main/java/io/opentelemetry/sdk/logs/SdkLoggerProviderBuilder.java +++ b/sdk/logs/src/main/java/io/opentelemetry/sdk/logs/SdkLoggerProviderBuilder.java @@ -9,6 +9,7 @@ import io.opentelemetry.api.logs.LogRecordBuilder; import io.opentelemetry.api.logs.Logger; +import io.opentelemetry.context.Context; import io.opentelemetry.sdk.common.Clock; import io.opentelemetry.sdk.logs.data.LogRecordData; import io.opentelemetry.sdk.resources.Resource; @@ -57,8 +58,9 @@ public SdkLoggerProviderBuilder setLogLimits(Supplier logLimitsSuppli } /** - * Add a log processor. {@link LogRecordProcessor#onEmit(ReadWriteLogRecord)} will be called each - * time a log is emitted by {@link Logger} instances obtained from the {@link SdkLoggerProvider}. + * Add a log processor. {@link LogRecordProcessor#onEmit(Context, ReadWriteLogRecord)} will be + * called each time a log is emitted by {@link Logger} instances obtained from the {@link + * SdkLoggerProvider}. * * @param processor the log processor * @return this diff --git a/sdk/logs/src/main/java/io/opentelemetry/sdk/logs/export/BatchLogRecordProcessor.java b/sdk/logs/src/main/java/io/opentelemetry/sdk/logs/export/BatchLogRecordProcessor.java index 1c92cad0af5..f327b3b4acc 100644 --- a/sdk/logs/src/main/java/io/opentelemetry/sdk/logs/export/BatchLogRecordProcessor.java +++ b/sdk/logs/src/main/java/io/opentelemetry/sdk/logs/export/BatchLogRecordProcessor.java @@ -10,6 +10,7 @@ import io.opentelemetry.api.metrics.LongCounter; import io.opentelemetry.api.metrics.Meter; import io.opentelemetry.api.metrics.MeterProvider; +import io.opentelemetry.context.Context; import io.opentelemetry.sdk.common.CompletableResultCode; import io.opentelemetry.sdk.internal.DaemonThreadFactory; import io.opentelemetry.sdk.logs.LogRecordProcessor; @@ -81,7 +82,7 @@ public static BatchLogRecordProcessorBuilder builder(LogRecordExporter logRecord } @Override - public void onEmit(ReadWriteLogRecord logRecord) { + public void onEmit(Context context, ReadWriteLogRecord logRecord) { if (logRecord == null) { return; } diff --git a/sdk/logs/src/main/java/io/opentelemetry/sdk/logs/export/SimpleLogRecordProcessor.java b/sdk/logs/src/main/java/io/opentelemetry/sdk/logs/export/SimpleLogRecordProcessor.java index b7703d4cde1..3bb510718aa 100644 --- a/sdk/logs/src/main/java/io/opentelemetry/sdk/logs/export/SimpleLogRecordProcessor.java +++ b/sdk/logs/src/main/java/io/opentelemetry/sdk/logs/export/SimpleLogRecordProcessor.java @@ -7,6 +7,7 @@ import static java.util.Objects.requireNonNull; +import io.opentelemetry.context.Context; import io.opentelemetry.sdk.common.CompletableResultCode; import io.opentelemetry.sdk.logs.LogRecordProcessor; import io.opentelemetry.sdk.logs.ReadWriteLogRecord; @@ -58,7 +59,7 @@ public static LogRecordProcessor create(LogRecordExporter exporter) { } @Override - public void onEmit(ReadWriteLogRecord logRecord) { + public void onEmit(Context context, ReadWriteLogRecord logRecord) { try { List logs = Collections.singletonList(logRecord.toLogRecordData()); CompletableResultCode result = logRecordExporter.export(logs); diff --git a/sdk/logs/src/test/java/io/opentelemetry/sdk/logs/MultiLogRecordProcessorTest.java b/sdk/logs/src/test/java/io/opentelemetry/sdk/logs/MultiLogRecordProcessorTest.java index 8a5a32e72b0..57aaa61fc32 100644 --- a/sdk/logs/src/test/java/io/opentelemetry/sdk/logs/MultiLogRecordProcessorTest.java +++ b/sdk/logs/src/test/java/io/opentelemetry/sdk/logs/MultiLogRecordProcessorTest.java @@ -10,6 +10,7 @@ import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; +import io.opentelemetry.context.Context; import io.opentelemetry.sdk.common.CompletableResultCode; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; @@ -39,7 +40,7 @@ void setup() { void empty() { LogRecordProcessor multiLogRecordProcessor = LogRecordProcessor.composite(); assertThat(multiLogRecordProcessor).isInstanceOf(NoopLogRecordProcessor.class); - multiLogRecordProcessor.onEmit(logRecord); + multiLogRecordProcessor.onEmit(Context.current(), logRecord); multiLogRecordProcessor.shutdown(); } @@ -53,9 +54,10 @@ void oneLogRecordProcessor() { void twoLogRecordProcessor() { LogRecordProcessor multiLogRecordProcessor = LogRecordProcessor.composite(logRecordProcessor1, logRecordProcessor2); - multiLogRecordProcessor.onEmit(logRecord); - verify(logRecordProcessor1).onEmit(same(logRecord)); - verify(logRecordProcessor2).onEmit(same(logRecord)); + Context context = Context.current(); + multiLogRecordProcessor.onEmit(context, logRecord); + verify(logRecordProcessor1).onEmit(same(context), same(logRecord)); + verify(logRecordProcessor2).onEmit(same(context), same(logRecord)); multiLogRecordProcessor.forceFlush(); verify(logRecordProcessor1).forceFlush(); diff --git a/sdk/logs/src/test/java/io/opentelemetry/sdk/logs/NoopLogRecordProcessorTest.java b/sdk/logs/src/test/java/io/opentelemetry/sdk/logs/NoopLogRecordProcessorTest.java index c80cb15cbcf..3a209e02041 100644 --- a/sdk/logs/src/test/java/io/opentelemetry/sdk/logs/NoopLogRecordProcessorTest.java +++ b/sdk/logs/src/test/java/io/opentelemetry/sdk/logs/NoopLogRecordProcessorTest.java @@ -7,6 +7,7 @@ import static org.assertj.core.api.AssertionsForClassTypes.assertThat; +import io.opentelemetry.context.Context; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; import org.mockito.Mock; @@ -20,7 +21,7 @@ class NoopLogRecordProcessorTest { @Test void noCrash() { LogRecordProcessor logRecordProcessor = NoopLogRecordProcessor.getInstance(); - logRecordProcessor.onEmit(logRecord); + logRecordProcessor.onEmit(Context.current(), logRecord); assertThat(logRecordProcessor.forceFlush().isSuccess()).isEqualTo(true); assertThat(logRecordProcessor.shutdown().isSuccess()).isEqualTo(true); } diff --git a/sdk/logs/src/test/java/io/opentelemetry/sdk/logs/SdkLogRecordBuilderTest.java b/sdk/logs/src/test/java/io/opentelemetry/sdk/logs/SdkLogRecordBuilderTest.java index 9775f2f4900..3f530d6057d 100644 --- a/sdk/logs/src/test/java/io/opentelemetry/sdk/logs/SdkLogRecordBuilderTest.java +++ b/sdk/logs/src/test/java/io/opentelemetry/sdk/logs/SdkLogRecordBuilderTest.java @@ -47,7 +47,8 @@ class SdkLogRecordBuilderTest { @BeforeEach void setup() { when(loggerSharedState.getLogLimits()).thenReturn(LogLimits.getDefault()); - when(loggerSharedState.getLogRecordProcessor()).thenReturn(emittedLog::set); + when(loggerSharedState.getLogRecordProcessor()) + .thenReturn((context, logRecord) -> emittedLog.set(logRecord)); when(loggerSharedState.getResource()).thenReturn(RESOURCE); when(loggerSharedState.getClock()).thenReturn(Clock.getDefault()); diff --git a/sdk/logs/src/test/java/io/opentelemetry/sdk/logs/SdkLoggerProviderTest.java b/sdk/logs/src/test/java/io/opentelemetry/sdk/logs/SdkLoggerProviderTest.java index 2eaf70bc32a..7408fdfc8dc 100644 --- a/sdk/logs/src/test/java/io/opentelemetry/sdk/logs/SdkLoggerProviderTest.java +++ b/sdk/logs/src/test/java/io/opentelemetry/sdk/logs/SdkLoggerProviderTest.java @@ -7,6 +7,7 @@ import static io.opentelemetry.sdk.testing.assertj.LogAssertions.assertThat; import static org.assertj.core.api.Assertions.as; +import static org.assertj.core.api.Assertions.entry; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.times; import static org.mockito.Mockito.verify; @@ -21,6 +22,8 @@ import io.opentelemetry.api.trace.TraceFlags; import io.opentelemetry.api.trace.TraceState; import io.opentelemetry.context.Context; +import io.opentelemetry.context.ContextKey; +import io.opentelemetry.context.Scope; import io.opentelemetry.internal.testing.slf4j.SuppressLogger; import io.opentelemetry.sdk.common.Clock; import io.opentelemetry.sdk.common.CompletableResultCode; @@ -29,6 +32,7 @@ import io.opentelemetry.sdk.resources.Resource; import java.util.ArrayList; import java.util.List; +import java.util.Optional; import java.util.concurrent.TimeUnit; import java.util.concurrent.atomic.AtomicReference; import org.assertj.core.api.InstanceOfAssertFactories; @@ -222,7 +226,7 @@ void loggerBuilder_WithLogRecordProcessor() { SdkLoggerProvider.builder() .setResource(resource) .addLogRecordProcessor( - logRecord -> { + (unused, logRecord) -> { logRecord.setAttribute(null, null); // Overwrite k1 logRecord.setAttribute(AttributeKey.stringKey("k1"), "new-v1"); @@ -262,6 +266,50 @@ void loggerBuilder_WithLogRecordProcessor() { Attributes.builder().put("k1", "new-v1").put("k2", "v2").put("k3", "v3").build()); } + @Test + void loggerBuilder_ProcessorWithContext() { + ContextKey contextKey = ContextKey.named("my-context-key"); + AtomicReference logRecordData = new AtomicReference<>(); + + sdkLoggerProvider = + SdkLoggerProvider.builder() + .addLogRecordProcessor( + (context, logRecord) -> + logRecord.setAttribute( + AttributeKey.stringKey("my-context-key"), + Optional.ofNullable(context.get(contextKey)).orElse(""))) + .addLogRecordProcessor( + (unused, logRecord) -> logRecordData.set(logRecord.toLogRecordData())) + .build(); + + // With implicit context + try (Scope unused = Context.current().with(contextKey, "context-value1").makeCurrent()) { + sdkLoggerProvider + .loggerBuilder("test") + .build() + .logRecordBuilder() + .setBody("log message1") + .emit(); + } + assertThat(logRecordData.get()) + .hasBody("log message1") + .hasAttributes(entry(AttributeKey.stringKey("my-context-key"), "context-value1")); + + // With explicit context + try (Scope unused = Context.current().with(contextKey, "context-value2").makeCurrent()) { + sdkLoggerProvider + .loggerBuilder("test") + .build() + .logRecordBuilder() + .setContext(Context.current()) + .setBody("log message2") + .emit(); + } + assertThat(logRecordData.get()) + .hasBody("log message2") + .hasAttributes(entry(AttributeKey.stringKey("my-context-key"), "context-value2")); + } + @Test void forceFlush() { sdkLoggerProvider.forceFlush(); @@ -288,7 +336,7 @@ void canSetClock() { Clock clock = mock(Clock.class); when(clock.now()).thenReturn(now); List seenLogs = new ArrayList<>(); - logRecordProcessor = seenLogs::add; + logRecordProcessor = (context, logRecord) -> seenLogs.add(logRecord); sdkLoggerProvider = SdkLoggerProvider.builder() .setClock(clock) diff --git a/sdk/logs/src/test/java/io/opentelemetry/sdk/logs/SdkLoggerTest.java b/sdk/logs/src/test/java/io/opentelemetry/sdk/logs/SdkLoggerTest.java index b35b6b926a3..e96820132e4 100644 --- a/sdk/logs/src/test/java/io/opentelemetry/sdk/logs/SdkLoggerTest.java +++ b/sdk/logs/src/test/java/io/opentelemetry/sdk/logs/SdkLoggerTest.java @@ -46,7 +46,7 @@ void logRecordBuilder() { LoggerSharedState state = mock(LoggerSharedState.class); InstrumentationScopeInfo info = InstrumentationScopeInfo.create("foo"); AtomicReference seenLog = new AtomicReference<>(); - LogRecordProcessor logRecordProcessor = seenLog::set; + LogRecordProcessor logRecordProcessor = (context, logRecord) -> seenLog.set(logRecord); Clock clock = mock(Clock.class); when(clock.now()).thenReturn(5L); @@ -69,7 +69,7 @@ void logRecordBuilder_maxAttributeLength() { AtomicReference seenLog = new AtomicReference<>(); SdkLoggerProvider loggerProvider = SdkLoggerProvider.builder() - .addLogRecordProcessor(seenLog::set) + .addLogRecordProcessor((context, logRecord) -> seenLog.set(logRecord)) .setLogLimits(() -> LogLimits.builder().setMaxAttributeValueLength(maxLength).build()) .build(); LogRecordBuilder logRecordBuilder = loggerProvider.get("test").logRecordBuilder(); @@ -109,7 +109,7 @@ void logRecordBuilder_maxAttributes() { AtomicReference seenLog = new AtomicReference<>(); SdkLoggerProvider loggerProvider = SdkLoggerProvider.builder() - .addLogRecordProcessor(seenLog::set) + .addLogRecordProcessor((context, logRecord) -> seenLog.set(logRecord)) .setLogLimits( () -> LogLimits.builder().setMaxNumberOfAttributes(maxNumberOfAttrs).build()) .build(); @@ -140,7 +140,7 @@ void logRecordBuilder_AfterShutdown() { loggerProvider.shutdown().join(10, TimeUnit.SECONDS); loggerProvider.get("test").logRecordBuilder().emit(); - verify(logRecordProcessor, never()).onEmit(any()); + verify(logRecordProcessor, never()).onEmit(any(), any()); } @Test @@ -148,7 +148,9 @@ void logRecordBuilder_AfterShutdown() { void eventBuilder() { AtomicReference seenLog = new AtomicReference<>(); SdkLoggerProvider loggerProvider = - SdkLoggerProvider.builder().addLogRecordProcessor(seenLog::set).build(); + SdkLoggerProvider.builder() + .addLogRecordProcessor((context, logRecord) -> seenLog.set(logRecord)) + .build(); // Emit event from logger with name and add event domain loggerProvider diff --git a/sdk/logs/src/test/java/io/opentelemetry/sdk/logs/export/BatchLogRecordProcessorTest.java b/sdk/logs/src/test/java/io/opentelemetry/sdk/logs/export/BatchLogRecordProcessorTest.java index 32cfecbed17..1039b7e34bc 100644 --- a/sdk/logs/src/test/java/io/opentelemetry/sdk/logs/export/BatchLogRecordProcessorTest.java +++ b/sdk/logs/src/test/java/io/opentelemetry/sdk/logs/export/BatchLogRecordProcessorTest.java @@ -291,7 +291,7 @@ void ignoresNullLogs() { BatchLogRecordProcessor processor = BatchLogRecordProcessor.builder(mockLogRecordExporter).build(); try { - assertThatCode(() -> processor.onEmit(null)).doesNotThrowAnyException(); + assertThatCode(() -> processor.onEmit(null, null)).doesNotThrowAnyException(); } finally { processor.shutdown(); } diff --git a/sdk/logs/src/test/java/io/opentelemetry/sdk/logs/export/SimpleLogRecordProcessorTest.java b/sdk/logs/src/test/java/io/opentelemetry/sdk/logs/export/SimpleLogRecordProcessorTest.java index 3ce15654092..1550c68b3ef 100644 --- a/sdk/logs/src/test/java/io/opentelemetry/sdk/logs/export/SimpleLogRecordProcessorTest.java +++ b/sdk/logs/src/test/java/io/opentelemetry/sdk/logs/export/SimpleLogRecordProcessorTest.java @@ -15,6 +15,7 @@ import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; +import io.opentelemetry.context.Context; import io.opentelemetry.internal.testing.slf4j.SuppressLogger; import io.opentelemetry.sdk.common.CompletableResultCode; import io.opentelemetry.sdk.logs.LogRecordProcessor; @@ -58,7 +59,7 @@ void create_NullExporter() { @Test void onEmit() { - logRecordProcessor.onEmit(readWriteLogRecord); + logRecordProcessor.onEmit(Context.current(), readWriteLogRecord); verify(logRecordExporter).export(Collections.singletonList(LOG_RECORD_DATA)); } @@ -66,8 +67,8 @@ void onEmit() { @SuppressLogger(SimpleLogRecordProcessor.class) void onEmit_ExporterError() { when(logRecordExporter.export(any())).thenThrow(new RuntimeException("Exporter error!")); - logRecordProcessor.onEmit(readWriteLogRecord); - logRecordProcessor.onEmit(readWriteLogRecord); + logRecordProcessor.onEmit(Context.current(), readWriteLogRecord); + logRecordProcessor.onEmit(Context.current(), readWriteLogRecord); verify(logRecordExporter, times(2)).export(anyList()); } @@ -78,8 +79,8 @@ void forceFlush() { when(logRecordExporter.export(any())).thenReturn(export1, export2); - logRecordProcessor.onEmit(readWriteLogRecord); - logRecordProcessor.onEmit(readWriteLogRecord); + logRecordProcessor.onEmit(Context.current(), readWriteLogRecord); + logRecordProcessor.onEmit(Context.current(), readWriteLogRecord); verify(logRecordExporter, times(2)).export(Collections.singletonList(LOG_RECORD_DATA)); @@ -101,8 +102,8 @@ void shutdown() { when(logRecordExporter.export(any())).thenReturn(export1, export2); - logRecordProcessor.onEmit(readWriteLogRecord); - logRecordProcessor.onEmit(readWriteLogRecord); + logRecordProcessor.onEmit(Context.current(), readWriteLogRecord); + logRecordProcessor.onEmit(Context.current(), readWriteLogRecord); verify(logRecordExporter, times(2)).export(Collections.singletonList(LOG_RECORD_DATA)); From 4b601ade98656ddf85c9ce4a3b62e2cb4efbe0d6 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Wed, 9 Nov 2022 11:59:33 -0600 Subject: [PATCH 15/68] Bump org.jetbrains.kotlin.jvm from 1.7.20 to 1.7.21 (#4927) Bumps org.jetbrains.kotlin.jvm from 1.7.20 to 1.7.21. --- updated-dependencies: - dependency-name: org.jetbrains.kotlin.jvm dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> --- settings.gradle.kts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/settings.gradle.kts b/settings.gradle.kts index aa92f6f6e1a..8f1df84b63a 100644 --- a/settings.gradle.kts +++ b/settings.gradle.kts @@ -4,7 +4,7 @@ pluginManagement { id("com.github.johnrengelman.shadow") version "7.1.2" id("com.gradle.enterprise") version "3.11.4" id("io.github.gradle-nexus.publish-plugin") version "1.1.0" - id("org.jetbrains.kotlin.jvm") version "1.7.20" + id("org.jetbrains.kotlin.jvm") version "1.7.21" id("org.graalvm.buildtools.native") version "0.9.17" } } From ef076c2880d5df9eb5f1460837743278a37476ea Mon Sep 17 00:00:00 2001 From: jack-berg <34418638+jack-berg@users.noreply.github.com> Date: Wed, 9 Nov 2022 16:54:18 -0600 Subject: [PATCH 16/68] Fix LogsBenchmarks (#4929) --- .../src/jmh/java/io/opentelemetry/sdk/logs/LogsBenchmarks.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sdk/logs/src/jmh/java/io/opentelemetry/sdk/logs/LogsBenchmarks.java b/sdk/logs/src/jmh/java/io/opentelemetry/sdk/logs/LogsBenchmarks.java index b04baebab59..5d0cfd05f68 100644 --- a/sdk/logs/src/jmh/java/io/opentelemetry/sdk/logs/LogsBenchmarks.java +++ b/sdk/logs/src/jmh/java/io/opentelemetry/sdk/logs/LogsBenchmarks.java @@ -40,7 +40,7 @@ public static class BenchmarkState { private final SdkLoggerProvider sdk = SdkLoggerProvider.builder() .addLogRecordProcessor( - logRecord -> { + (context, logRecord) -> { // Do nothing }) .build(); From f83def7a4f32656c62638d34e2a45ef4440ec86c Mon Sep 17 00:00:00 2001 From: Carlos Alberto Cortez Date: Thu, 10 Nov 2022 00:02:28 +0100 Subject: [PATCH 17/68] OpenTracing Shim: Full multiple parent support. (#4916) * Full multiple parent support. This includes: * The Baggage union of ALL parents is used. * All parents are added as Links, in order to preserve the OpenTracing reference type as an attribute (either CHILD_OF or FOLLOWS_FROM). * Update opentracing-shim/src/main/java/io/opentelemetry/opentracingshim/SpanBuilderShim.java Co-authored-by: jack-berg <34418638+jack-berg@users.noreply.github.com> * Update opentracing-shim/src/main/java/io/opentelemetry/opentracingshim/SpanBuilderShim.java Co-authored-by: jack-berg <34418638+jack-berg@users.noreply.github.com> * Update opentracing-shim/src/main/java/io/opentelemetry/opentracingshim/SpanBuilderShim.java Co-authored-by: jack-berg <34418638+jack-berg@users.noreply.github.com> * Apply feedback. * More feedback. Co-authored-by: jack-berg <34418638+jack-berg@users.noreply.github.com> --- opentracing-shim/build.gradle.kts | 2 + .../opentracingshim/SpanBuilderShim.java | 142 +++++++++++---- .../opentracingshim/SpanBuilderShimTest.java | 165 ++++++++++++++++++ 3 files changed, 278 insertions(+), 31 deletions(-) diff --git a/opentracing-shim/build.gradle.kts b/opentracing-shim/build.gradle.kts index 9947bc7f5c5..98129994fbc 100644 --- a/opentracing-shim/build.gradle.kts +++ b/opentracing-shim/build.gradle.kts @@ -12,6 +12,8 @@ dependencies { api("io.opentracing:opentracing-api") implementation(project(":semconv")) + annotationProcessor("com.google.auto.value:auto-value") + testImplementation(project(":sdk:testing")) } diff --git a/opentracing-shim/src/main/java/io/opentelemetry/opentracingshim/SpanBuilderShim.java b/opentracing-shim/src/main/java/io/opentelemetry/opentracingshim/SpanBuilderShim.java index 5ed3baa8bf1..9c3f8db4946 100644 --- a/opentracing-shim/src/main/java/io/opentelemetry/opentracingshim/SpanBuilderShim.java +++ b/opentracing-shim/src/main/java/io/opentelemetry/opentracingshim/SpanBuilderShim.java @@ -10,32 +10,35 @@ import static io.opentelemetry.api.common.AttributeKey.longKey; import static io.opentelemetry.api.common.AttributeKey.stringKey; +import com.google.auto.value.AutoValue; import io.opentelemetry.api.baggage.Baggage; +import io.opentelemetry.api.baggage.BaggageBuilder; import io.opentelemetry.api.common.AttributeKey; +import io.opentelemetry.api.common.Attributes; import io.opentelemetry.api.trace.SpanKind; import io.opentelemetry.api.trace.StatusCode; import io.opentelemetry.context.Context; +import io.opentelemetry.semconv.trace.attributes.SemanticAttributes; +import io.opentracing.References; import io.opentracing.Span; import io.opentracing.SpanContext; import io.opentracing.Tracer.SpanBuilder; import io.opentracing.tag.Tag; import io.opentracing.tag.Tags; import java.util.ArrayList; +import java.util.Collections; import java.util.List; import java.util.concurrent.TimeUnit; import javax.annotation.Nullable; +import javax.annotation.concurrent.Immutable; final class SpanBuilderShim extends BaseShimObject implements SpanBuilder { private final String spanName; - // The parent will be either a Span or a SpanContext. - // Inherited baggage is supported only for the main parent. - @Nullable private SpanShim parentSpan; - @Nullable private SpanContextShim parentSpanContext; + // *All* parents are saved in this list. + private List allParents = Collections.emptyList(); private boolean ignoreActiveSpan; - private final List parentLinks = new ArrayList<>(); - @SuppressWarnings("rawtypes") private final List spanBuilderAttributeKeys = new ArrayList<>(); @@ -44,6 +47,15 @@ final class SpanBuilderShim extends BaseShimObject implements SpanBuilder { private boolean error; private long startTimestampMicros; + private static final Attributes CHILD_OF_ATTR = + Attributes.of( + SemanticAttributes.OPENTRACING_REF_TYPE, + SemanticAttributes.OpentracingRefTypeValues.CHILD_OF); + private static final Attributes FOLLOWS_FROM_ATTR = + Attributes.of( + SemanticAttributes.OPENTRACING_REF_TYPE, + SemanticAttributes.OpentracingRefTypeValues.FOLLOWS_FROM); + public SpanBuilderShim(TelemetryInfo telemetryInfo, String spanName) { super(telemetryInfo); this.spanName = spanName; @@ -57,19 +69,12 @@ public SpanBuilder asChildOf(Span parent) { // TODO - Verify we handle a no-op Span SpanShim spanShim = ShimUtil.getSpanShim(parent); - - if (parentSpan == null && parentSpanContext == null) { - parentSpan = spanShim; - } else { - parentLinks.add(spanShim.getSpan().getSpanContext()); - } - - return this; + return addReference(References.CHILD_OF, spanShim.context()); } @Override public SpanBuilder asChildOf(SpanContext parent) { - return addReference(null, parent); + return addReference(References.CHILD_OF, parent); } @Override @@ -78,13 +83,30 @@ public SpanBuilder addReference(@Nullable String referenceType, SpanContext refe return this; } - // TODO - Use referenceType + ReferenceType refType; + if (References.CHILD_OF.equals(referenceType)) { + refType = ReferenceType.CHILD_OF; + } else if (References.FOLLOWS_FROM.equals(referenceType)) { + refType = ReferenceType.FOLLOWS_FROM; + } else { + // Discard references with unrecognized type. + return this; + } + SpanContextShim contextShim = ShimUtil.getContextShim(referencedContext); - if (parentSpan == null && parentSpanContext == null) { - parentSpanContext = contextShim; + // Optimization for 99% situations, when there is only one parent. + if (allParents.size() == 0) { + allParents = + Collections.singletonList( + SpanParentInfo.create( + contextShim.getSpanContext(), contextShim.getBaggage(), refType)); } else { - parentLinks.add(contextShim.getSpanContext()); + if (allParents.size() == 1) { + allParents = new ArrayList<>(allParents); + } + allParents.add( + SpanParentInfo.create(contextShim.getSpanContext(), contextShim.getBaggage(), refType)); } return this; @@ -186,26 +208,26 @@ public SpanBuilder withStartTimestamp(long microseconds) { @SuppressWarnings({"rawtypes", "unchecked"}) @Override public Span start() { - Baggage baggage = Baggage.empty(); + Baggage baggage; io.opentelemetry.api.trace.SpanBuilder builder = tracer().spanBuilder(spanName); + io.opentelemetry.api.trace.SpanContext mainParent = getMainParent(allParents); - if (ignoreActiveSpan && parentSpan == null && parentSpanContext == null) { + if (ignoreActiveSpan && mainParent == null) { builder.setNoParent(); - } else if (parentSpan != null) { - builder.setParent(Context.root().with(parentSpan.getSpan())); - baggage = ((SpanContextShim) parentSpan.context()).getBaggage(); - } else if (parentSpanContext != null) { - builder.setParent( - Context.root() - .with(io.opentelemetry.api.trace.Span.wrap(parentSpanContext.getSpanContext()))); - baggage = parentSpanContext.getBaggage(); + baggage = Baggage.empty(); + } else if (mainParent != null) { + builder.setParent(Context.root().with(io.opentelemetry.api.trace.Span.wrap(mainParent))); + baggage = getAllBaggage(allParents); } else { // No explicit parent Span, but extracted baggage may be available. baggage = Baggage.current(); } - for (io.opentelemetry.api.trace.SpanContext link : parentLinks) { - builder.addLink(link); + // *All* parents are processed as Links, in order to keep the reference type value. + for (SpanParentInfo parentInfo : allParents) { + builder.addLink( + parentInfo.getSpanContext(), + parentInfo.getRefType() == ReferenceType.CHILD_OF ? CHILD_OF_ATTR : FOLLOWS_FROM_ATTR); } if (spanKind != null) { @@ -232,4 +254,62 @@ public Span start() { return new SpanShim(telemetryInfo(), span, baggage); } + + // The first SpanContext with Child Of type in the entire list is used as parent, + // else the first SpanContext is used as parent. + @Nullable + static io.opentelemetry.api.trace.SpanContext getMainParent(List parents) { + if (parents.size() == 0) { + return null; + } + + SpanParentInfo mainParent = parents.get(0); + for (SpanParentInfo parentInfo : parents) { + if (parentInfo.getRefType() == ReferenceType.CHILD_OF) { + mainParent = parentInfo; + break; + } + } + + return mainParent.getSpanContext(); + } + + static Baggage getAllBaggage(List parents) { + if (parents.size() == 0) { + return Baggage.empty(); + } + + if (parents.size() == 1) { + return parents.get(0).getBaggage(); + } + + BaggageBuilder builder = Baggage.builder(); + for (SpanParentInfo parent : parents) { + parent.getBaggage().forEach((key, entry) -> builder.put(key, entry.getValue())); + } + + return builder.build(); + } + + @AutoValue + @Immutable + abstract static class SpanParentInfo { + private static SpanParentInfo create( + io.opentelemetry.api.trace.SpanContext spanContext, + Baggage baggage, + ReferenceType refType) { + return new AutoValue_SpanBuilderShim_SpanParentInfo(spanContext, baggage, refType); + } + + abstract io.opentelemetry.api.trace.SpanContext getSpanContext(); + + abstract Baggage getBaggage(); + + abstract ReferenceType getRefType(); + } + + enum ReferenceType { + CHILD_OF, + FOLLOWS_FROM + } } 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 06fc3891d8c..05a412478c3 100644 --- a/opentracing-shim/src/test/java/io/opentelemetry/opentracingshim/SpanBuilderShimTest.java +++ b/opentracing-shim/src/test/java/io/opentelemetry/opentracingshim/SpanBuilderShimTest.java @@ -20,6 +20,8 @@ import io.opentelemetry.sdk.trace.data.SpanData; import io.opentelemetry.sdk.trace.samplers.Sampler; import io.opentelemetry.sdk.trace.samplers.SamplingResult; +import io.opentelemetry.semconv.trace.attributes.SemanticAttributes; +import io.opentracing.References; import java.util.List; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; @@ -38,6 +40,143 @@ void setUp() { GlobalOpenTelemetry.resetForTest(); } + @Test + void parent_single() { + SpanShim parentSpan = (SpanShim) new SpanBuilderShim(telemetryInfo, SPAN_NAME).start(); + try { + SpanShim childSpan = + (SpanShim) new SpanBuilderShim(telemetryInfo, SPAN_NAME).asChildOf(parentSpan).start(); + + try { + SpanData spanData = ((ReadableSpan) childSpan.getSpan()).toSpanData(); + assertThat(parentSpan.context().toSpanId()).isEqualTo(spanData.getParentSpanId()); + } finally { + childSpan.finish(); + } + } finally { + parentSpan.finish(); + } + } + + @Test + void parent_multipleFollowsFrom() { + SpanShim parentSpan1 = (SpanShim) new SpanBuilderShim(telemetryInfo, SPAN_NAME).start(); + SpanShim parentSpan2 = (SpanShim) new SpanBuilderShim(telemetryInfo, SPAN_NAME).start(); + + try { + SpanShim childSpan = + (SpanShim) + new SpanBuilderShim(telemetryInfo, SPAN_NAME) + .addReference(References.FOLLOWS_FROM, parentSpan1.context()) + .addReference(References.FOLLOWS_FROM, parentSpan2.context()) + .start(); + + try { + // If no parent of CHILD_OF type exists, use the first value as main parent. + SpanData spanData = ((ReadableSpan) childSpan.getSpan()).toSpanData(); + assertThat(parentSpan1.context().toSpanId()).isEqualTo(spanData.getParentSpanId()); + } finally { + childSpan.finish(); + } + } finally { + parentSpan1.finish(); + parentSpan2.finish(); + } + } + + @Test + void parent_multipleDifferentRefType() { + SpanShim parentSpan1 = (SpanShim) new SpanBuilderShim(telemetryInfo, SPAN_NAME).start(); + SpanShim parentSpan2 = (SpanShim) new SpanBuilderShim(telemetryInfo, SPAN_NAME).start(); + SpanShim parentSpan3 = (SpanShim) new SpanBuilderShim(telemetryInfo, SPAN_NAME).start(); + + try { + SpanShim childSpan = + (SpanShim) + new SpanBuilderShim(telemetryInfo, SPAN_NAME) + .addReference(References.FOLLOWS_FROM, parentSpan1.context()) + .addReference(References.CHILD_OF, parentSpan2.context()) + .addReference(References.CHILD_OF, parentSpan3.context()) + .start(); + + try { + // The first parent with CHILD_OF becomes the direct parent (if any). + SpanData spanData = ((ReadableSpan) childSpan.getSpan()).toSpanData(); + assertThat(parentSpan2.context().toSpanId()).isEqualTo(spanData.getParentSpanId()); + } finally { + childSpan.finish(); + } + } finally { + parentSpan1.finish(); + parentSpan2.finish(); + parentSpan3.finish(); + } + } + + @Test + void parent_multipleLinks() { + SpanShim parentSpan1 = (SpanShim) new SpanBuilderShim(telemetryInfo, SPAN_NAME).start(); + SpanShim parentSpan2 = (SpanShim) new SpanBuilderShim(telemetryInfo, SPAN_NAME).start(); + SpanShim parentSpan3 = (SpanShim) new SpanBuilderShim(telemetryInfo, SPAN_NAME).start(); + + try { + SpanShim childSpan = + (SpanShim) + new SpanBuilderShim(telemetryInfo, SPAN_NAME) + .addReference(References.FOLLOWS_FROM, parentSpan1.context()) + .addReference(References.CHILD_OF, parentSpan2.context()) + .addReference(References.FOLLOWS_FROM, parentSpan3.context()) + .start(); + + try { + SpanData spanData = ((ReadableSpan) childSpan.getSpan()).toSpanData(); + List links = spanData.getLinks(); + assertThat(links).hasSize(3); + + assertThat(links.get(0).getSpanContext()).isEqualTo(parentSpan1.getSpan().getSpanContext()); + assertThat(links.get(1).getSpanContext()).isEqualTo(parentSpan2.getSpan().getSpanContext()); + assertThat(links.get(2).getSpanContext()).isEqualTo(parentSpan3.getSpan().getSpanContext()); + assertThat(links.get(0).getAttributes().get(SemanticAttributes.OPENTRACING_REF_TYPE)) + .isEqualTo(SemanticAttributes.OpentracingRefTypeValues.FOLLOWS_FROM); + assertThat(links.get(1).getAttributes().get(SemanticAttributes.OPENTRACING_REF_TYPE)) + .isEqualTo(SemanticAttributes.OpentracingRefTypeValues.CHILD_OF); + assertThat(links.get(2).getAttributes().get(SemanticAttributes.OPENTRACING_REF_TYPE)) + .isEqualTo(SemanticAttributes.OpentracingRefTypeValues.FOLLOWS_FROM); + + } finally { + childSpan.finish(); + } + } finally { + parentSpan1.finish(); + parentSpan2.finish(); + parentSpan3.finish(); + } + } + + @Test + void parent_wrongRefType() { + SpanShim parentSpan = (SpanShim) new SpanBuilderShim(telemetryInfo, SPAN_NAME).start(); + try { + SpanShim childSpan = + (SpanShim) + new SpanBuilderShim(telemetryInfo, SPAN_NAME) + .addReference("wrongreftype-value", parentSpan.context()) + .start(); + + try { + // Incorrect typeref values get discarded. + SpanData spanData = ((ReadableSpan) childSpan.getSpan()).toSpanData(); + assertThat(spanData.getParentSpanContext()) + .isEqualTo(io.opentelemetry.api.trace.SpanContext.getInvalid()); + assertThat(spanData.getLinks()).isEmpty(); + } finally { + childSpan.finish(); + } + } finally { + parentSpan.finish(); + } + } + @Test void baggage_parent() { SpanShim parentSpan = (SpanShim) new SpanBuilderShim(telemetryInfo, SPAN_NAME).start(); @@ -79,6 +218,32 @@ void baggage_parentContext() { } } + @Test + void baggage_multipleParents() { + SpanShim parentSpan1 = (SpanShim) new SpanBuilderShim(telemetryInfo, SPAN_NAME).start(); + SpanShim parentSpan2 = (SpanShim) new SpanBuilderShim(telemetryInfo, SPAN_NAME).start(); + try { + parentSpan1.setBaggageItem("key1", "value1"); + parentSpan2.setBaggageItem("key2", "value2"); + + SpanShim childSpan = + (SpanShim) + new SpanBuilderShim(telemetryInfo, SPAN_NAME) + .addReference(References.FOLLOWS_FROM, parentSpan1.context()) + .addReference(References.CHILD_OF, parentSpan2.context()) + .start(); + try { + assertThat(childSpan.getBaggageItem("key1")).isEqualTo("value1"); + assertThat(childSpan.getBaggageItem("key2")).isEqualTo("value2"); + } finally { + childSpan.finish(); + } + } finally { + parentSpan1.finish(); + parentSpan2.finish(); + } + } + @Test void baggage_spanWithInvalidSpan() { io.opentelemetry.api.baggage.Baggage baggage = From 36adb27cf8c10b013dfeca01d89fe17443a4f3d3 Mon Sep 17 00:00:00 2001 From: Ragnar Rova Date: Thu, 10 Nov 2022 00:35:33 +0100 Subject: [PATCH 18/68] Allow SDK to run in environments prohibiting use of sun.misc.Unsafe (#4902) Some applications run under strict java.security permissions which do not allow access to sun.misc.Unsafe. BatchSpanProcessor uses Unsafe via jctools, but has a fallback to ArrayBlockingQueue. Extending that fallback rule to cover java security exceptions as well. Co-authored-by: Jack Berg --- sdk/trace-shaded-deps/build.gradle.kts | 5 + .../sdk/trace/internal/JcTools.java | 18 ++- .../internal/JcToolsSecurityManagerTest.java | 38 ++++++ .../SunMiscProhibitedSecurityManager.java | 111 ++++++++++++++++++ .../SunMiscProhibitedSecurityManagerTest.java | 41 +++++++ 5 files changed, 211 insertions(+), 2 deletions(-) create mode 100644 sdk/trace-shaded-deps/src/test/java/io/opentelemetry/sdk/trace/internal/JcToolsSecurityManagerTest.java create mode 100644 sdk/trace-shaded-deps/src/test/java/io/opentelemetry/sdk/trace/internal/SunMiscProhibitedSecurityManager.java create mode 100644 sdk/trace-shaded-deps/src/test/java/io/opentelemetry/sdk/trace/internal/SunMiscProhibitedSecurityManagerTest.java diff --git a/sdk/trace-shaded-deps/build.gradle.kts b/sdk/trace-shaded-deps/build.gradle.kts index 14f73ca4b79..c4573c976b7 100644 --- a/sdk/trace-shaded-deps/build.gradle.kts +++ b/sdk/trace-shaded-deps/build.gradle.kts @@ -26,3 +26,8 @@ tasks { into("build/extracted/shadow") } } + +tasks.withType().configureEach { + // JcToolsSecurityManagerTest interferes with JcToolsTest + setForkEvery(1) +} diff --git a/sdk/trace-shaded-deps/src/main/java/io/opentelemetry/sdk/trace/internal/JcTools.java b/sdk/trace-shaded-deps/src/main/java/io/opentelemetry/sdk/trace/internal/JcTools.java index a293c437aff..06976ad13d5 100644 --- a/sdk/trace-shaded-deps/src/main/java/io/opentelemetry/sdk/trace/internal/JcTools.java +++ b/sdk/trace-shaded-deps/src/main/java/io/opentelemetry/sdk/trace/internal/JcTools.java @@ -5,9 +5,13 @@ package io.opentelemetry.sdk.trace.internal; +import java.util.Objects; import java.util.Queue; import java.util.concurrent.ArrayBlockingQueue; +import java.util.concurrent.atomic.AtomicBoolean; import java.util.function.Consumer; +import java.util.logging.Level; +import java.util.logging.Logger; import org.jctools.queues.MessagePassingQueue; import org.jctools.queues.MpscArrayQueue; @@ -19,14 +23,24 @@ */ public final class JcTools { + private static final AtomicBoolean queueCreationWarningLogged = new AtomicBoolean(); + private static final Logger logger = Logger.getLogger(JcTools.class.getName()); + /** * Returns a new {@link Queue} appropriate for use with multiple producers and a single consumer. */ public static Queue newFixedSizeQueue(int capacity) { try { return new MpscArrayQueue<>(capacity); - } catch (java.lang.NoClassDefFoundError e) { - // Happens when modules such as jdk.unsupported are disabled in a custom JRE distribution + } catch (java.lang.NoClassDefFoundError | java.lang.ExceptionInInitializerError e) { + if (!queueCreationWarningLogged.getAndSet(true)) { + logger.log( + Level.WARNING, + "Cannot create high-performance queue, reverting to ArrayBlockingQueue ({0})", + Objects.toString(e, "unknown cause")); + } + // Happens when modules such as jdk.unsupported are disabled in a custom JRE distribution, + // or a security manager preventing access to Unsafe is installed. return new ArrayBlockingQueue<>(capacity); } } diff --git a/sdk/trace-shaded-deps/src/test/java/io/opentelemetry/sdk/trace/internal/JcToolsSecurityManagerTest.java b/sdk/trace-shaded-deps/src/test/java/io/opentelemetry/sdk/trace/internal/JcToolsSecurityManagerTest.java new file mode 100644 index 00000000000..eb2bd9199e3 --- /dev/null +++ b/sdk/trace-shaded-deps/src/test/java/io/opentelemetry/sdk/trace/internal/JcToolsSecurityManagerTest.java @@ -0,0 +1,38 @@ +/* + * Copyright The OpenTelemetry Authors + * SPDX-License-Identifier: Apache-2.0 + */ + +package io.opentelemetry.sdk.trace.internal; + +import static org.assertj.core.api.Assertions.assertThat; + +import io.opentelemetry.internal.testing.slf4j.SuppressLogger; +import java.security.AccessController; +import java.security.PrivilegedAction; +import java.util.Queue; +import java.util.concurrent.ArrayBlockingQueue; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.condition.EnabledOnJre; +import org.junit.jupiter.api.condition.JRE; + +public class JcToolsSecurityManagerTest { + + @Test + @EnabledOnJre({JRE.JAVA_8, JRE.JAVA_11, JRE.JAVA_17}) + @SuppressLogger(JcTools.class) + void newFixedSizeQueue_SunMiscProhibited() { + assertThat(System.getSecurityManager()).isNull(); + SunMiscProhibitedSecurityManager testingSecurityManager = + new SunMiscProhibitedSecurityManager(); + try { + System.setSecurityManager(testingSecurityManager); + Queue queue = + AccessController.doPrivileged( + (PrivilegedAction>) () -> JcTools.newFixedSizeQueue(10)); + assertThat(queue).isInstanceOf(ArrayBlockingQueue.class); + } finally { + System.setSecurityManager(null); + } + } +} diff --git a/sdk/trace-shaded-deps/src/test/java/io/opentelemetry/sdk/trace/internal/SunMiscProhibitedSecurityManager.java b/sdk/trace-shaded-deps/src/test/java/io/opentelemetry/sdk/trace/internal/SunMiscProhibitedSecurityManager.java new file mode 100644 index 00000000000..a158cc02ec9 --- /dev/null +++ b/sdk/trace-shaded-deps/src/test/java/io/opentelemetry/sdk/trace/internal/SunMiscProhibitedSecurityManager.java @@ -0,0 +1,111 @@ +/* + * Copyright The OpenTelemetry Authors + * SPDX-License-Identifier: Apache-2.0 + */ + +package io.opentelemetry.sdk.trace.internal; + +import java.io.FileDescriptor; +import java.net.InetAddress; +import java.security.AccessControlException; +import java.security.Permission; + +/** + * A security manager which disallows access to classes in sun.misc. Running the tests with a + * standard security manager is too invasive. + */ +public class SunMiscProhibitedSecurityManager extends SecurityManager { + + public SunMiscProhibitedSecurityManager() {} + + @Override + protected Class[] getClassContext() { + return super.getClassContext(); + } + + @Override + public void checkPermission(Permission perm) { + if (perm.getName().equals("accessClassInPackage.sun.misc")) { + throw new AccessControlException("access denied " + perm, perm); + } + } + + @Override + public void checkPermission(Permission perm, Object context) {} + + @Override + public void checkCreateClassLoader() {} + + @Override + public void checkAccess(Thread t) {} + + @Override + public void checkAccess(ThreadGroup g) {} + + @Override + public void checkExit(int status) {} + + @Override + public void checkExec(String cmd) {} + + @Override + public void checkLink(String lib) {} + + @Override + public void checkRead(FileDescriptor fd) {} + + @Override + public void checkRead(String file) {} + + @Override + public void checkRead(String file, Object context) {} + + @Override + public void checkWrite(FileDescriptor fd) {} + + @Override + public void checkWrite(String file) {} + + @Override + public void checkDelete(String file) {} + + @Override + public void checkConnect(String host, int port) {} + + @Override + public void checkConnect(String host, int port, Object context) {} + + @Override + public void checkListen(int port) {} + + @Override + public void checkAccept(String host, int port) {} + + @Override + public void checkMulticast(InetAddress maddr) {} + + @Override + public void checkPropertiesAccess() {} + + @Override + public void checkPropertyAccess(String key) {} + + @Override + public void checkPrintJobAccess() {} + + @Override + public void checkPackageAccess(String pkg) { + if (pkg.equals("sun.misc")) { + super.checkPackageAccess(pkg); + } + } + + @Override + public void checkPackageDefinition(String pkg) {} + + @Override + public void checkSetFactory() {} + + @Override + public void checkSecurityAccess(String target) {} +} diff --git a/sdk/trace-shaded-deps/src/test/java/io/opentelemetry/sdk/trace/internal/SunMiscProhibitedSecurityManagerTest.java b/sdk/trace-shaded-deps/src/test/java/io/opentelemetry/sdk/trace/internal/SunMiscProhibitedSecurityManagerTest.java new file mode 100644 index 00000000000..928d97410c3 --- /dev/null +++ b/sdk/trace-shaded-deps/src/test/java/io/opentelemetry/sdk/trace/internal/SunMiscProhibitedSecurityManagerTest.java @@ -0,0 +1,41 @@ +/* + * Copyright The OpenTelemetry Authors + * SPDX-License-Identifier: Apache-2.0 + */ + +package io.opentelemetry.sdk.trace.internal; + +import static org.assertj.core.api.Assertions.assertThatNoException; +import static org.assertj.core.api.Assertions.assertThatThrownBy; + +import java.security.AccessControlException; +import org.junit.jupiter.api.Test; + +class SunMiscProhibitedSecurityManagerTest { + + @Test + public void checkPackageAccess_ProhibitsSunMisc() { + SunMiscProhibitedSecurityManager sm = new SunMiscProhibitedSecurityManager(); + assertThatThrownBy(() -> sm.checkPackageAccess("sun.misc")) + .isInstanceOf(AccessControlException.class) + .hasMessage( + "access denied (\"java.lang.RuntimePermission\" \"accessClassInPackage.sun.misc\")"); + } + + @Test + public void checkPackageAccess_ProhibitsSunMiscRuntimePermission() { + SunMiscProhibitedSecurityManager sm = new SunMiscProhibitedSecurityManager(); + + assertThatThrownBy( + () -> sm.checkPermission(new RuntimePermission("accessClassInPackage.sun.misc"))) + .isInstanceOf(AccessControlException.class) + .hasMessage( + "access denied (\"java.lang.RuntimePermission\" \"accessClassInPackage.sun.misc\")"); + } + + @Test + public void checkPackageAccess_AllowsOtherPackage() { + SunMiscProhibitedSecurityManager sm = new SunMiscProhibitedSecurityManager(); + assertThatNoException().isThrownBy(() -> sm.checkPackageAccess("io.opentelemetry.sdk")); + } +} From 4b6df42f5c60f8c5cdd7260438437c7a6509520e Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Thu, 10 Nov 2022 07:56:26 -0800 Subject: [PATCH 19/68] Bump junit-pioneer from 1.7.1 to 1.7.2 (#4930) Bumps [junit-pioneer](https://github.com/junit-pioneer/junit-pioneer) from 1.7.1 to 1.7.2. - [Release notes](https://github.com/junit-pioneer/junit-pioneer/releases) - [Commits](https://github.com/junit-pioneer/junit-pioneer/compare/v1.7.1...v1.7.2) --- updated-dependencies: - dependency-name: org.junit-pioneer:junit-pioneer dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> --- dependencyManagement/build.gradle.kts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/dependencyManagement/build.gradle.kts b/dependencyManagement/build.gradle.kts index 56106bf865a..0027a78242d 100644 --- a/dependencyManagement/build.gradle.kts +++ b/dependencyManagement/build.gradle.kts @@ -97,7 +97,7 @@ val DEPENDENCIES = listOf( "org.bouncycastle:bcpkix-jdk15on:1.70", "org.codehaus.mojo:animal-sniffer-annotations:1.22", "org.jctools:jctools-core:4.0.1", - "org.junit-pioneer:junit-pioneer:1.7.1", + "org.junit-pioneer:junit-pioneer:1.7.2", "org.skyscreamer:jsonassert:1.5.1", ) From e8146020ccc02f240156790937ddb211475122aa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=81ukasz=20Monkiewicz?= Date: Thu, 10 Nov 2022 19:13:31 +0100 Subject: [PATCH 20/68] Adds '+' character to allowed characters in baggage value (#4898) * Adds '+' character to allowed characters in baggade value * Formatting fix * Adda BaggageCodec implementation * Additional cleanup * Removal of Nullable method parameters. * Additional tests for baggage decoding --- .../api/baggage/propagation/BaggageCodec.java | 88 +++++++++++++++++++ .../api/baggage/propagation/Parser.java | 10 +-- .../baggage/propagation/BaggageCodecTest.java | 42 +++++++++ .../W3CBaggagePropagatorFuzzTest.java | 45 +++++++++- 4 files changed, 176 insertions(+), 9 deletions(-) create mode 100644 api/all/src/main/java/io/opentelemetry/api/baggage/propagation/BaggageCodec.java create mode 100644 api/all/src/test/java/io/opentelemetry/api/baggage/propagation/BaggageCodecTest.java diff --git a/api/all/src/main/java/io/opentelemetry/api/baggage/propagation/BaggageCodec.java b/api/all/src/main/java/io/opentelemetry/api/baggage/propagation/BaggageCodec.java new file mode 100644 index 00000000000..ab2a66becc3 --- /dev/null +++ b/api/all/src/main/java/io/opentelemetry/api/baggage/propagation/BaggageCodec.java @@ -0,0 +1,88 @@ +/* + * Copyright The OpenTelemetry Authors + * SPDX-License-Identifier: Apache-2.0 + */ + +package io.opentelemetry.api.baggage.propagation; + +import java.io.ByteArrayOutputStream; +import java.nio.charset.Charset; +import java.nio.charset.StandardCharsets; + +/** + * Note: This class is based on code from Apache Commons Codec. It is comprised of code from these + * classes: + * + * + * + *

Implements baggage-octet decoding in accordance with th Baggage header content specification. All + * US-ASCII characters excluding CTLs, whitespace, DQUOTE, comma, semicolon and backslash are + * encoded in `www-form-urlencoded` encoding scheme. + */ +class BaggageCodec { + + private static final byte ESCAPE_CHAR = '%'; + private static final int RADIX = 16; + + private BaggageCodec() {} + + /** + * Decodes an array of URL safe 7-bit characters into an array of original bytes. Escaped + * characters are converted back to their original representation. + * + * @param bytes array of URL safe characters + * @return array of original bytes + */ + private static byte[] decode(byte[] bytes) { + ByteArrayOutputStream buffer = new ByteArrayOutputStream(); + for (int i = 0; i < bytes.length; i++) { + int b = bytes[i]; + if (b == ESCAPE_CHAR) { + try { + int u = digit16(bytes[++i]); + int l = digit16(bytes[++i]); + buffer.write((char) ((u << 4) + l)); + } catch (ArrayIndexOutOfBoundsException e) { // FIXME + throw new IllegalArgumentException("Invalid URL encoding: ", e); + } + } else { + buffer.write(b); + } + } + return buffer.toByteArray(); + } + + /** + * Decodes an array of URL safe 7-bit characters into an array of original bytes. Escaped + * characters are converted back to their original representation. + * + * @param value string of URL safe characters + * @param charset encoding of given string + * @return decoded value + */ + static String decode(String value, Charset charset) { + byte[] bytes = decode(value.getBytes(StandardCharsets.US_ASCII)); + return new String(bytes, charset); + } + + /** + * Returns the numeric value of the character {@code b} in radix 16. + * + * @param b The byte to be converted. + * @return The numeric value represented by the character in radix 16. + */ + private static int digit16(byte b) { + int i = Character.digit((char) b, RADIX); + if (i == -1) { + throw new IllegalArgumentException( // FIXME + "Invalid URL encoding: not a valid digit (radix " + RADIX + "): " + b); + } + return i; + } +} diff --git a/api/all/src/main/java/io/opentelemetry/api/baggage/propagation/Parser.java b/api/all/src/main/java/io/opentelemetry/api/baggage/propagation/Parser.java index 345fb177a5c..d6c26fcef27 100644 --- a/api/all/src/main/java/io/opentelemetry/api/baggage/propagation/Parser.java +++ b/api/all/src/main/java/io/opentelemetry/api/baggage/propagation/Parser.java @@ -7,8 +7,6 @@ import io.opentelemetry.api.baggage.BaggageBuilder; import io.opentelemetry.api.baggage.BaggageEntryMetadata; -import java.io.UnsupportedEncodingException; -import java.net.URLDecoder; import java.nio.charset.StandardCharsets; import javax.annotation.Nullable; @@ -64,6 +62,8 @@ void parseInto(BaggageBuilder baggageBuilder) { } else { skipToNext = true; } + } else if (state == State.VALUE) { + skipToNext = !value.tryNextChar(current, i); } break; } @@ -146,11 +146,7 @@ private static String decodeValue(@Nullable String value) { if (value == null) { return null; } - try { - return URLDecoder.decode(value, StandardCharsets.UTF_8.name()); - } catch (UnsupportedEncodingException e) { - return null; - } + return BaggageCodec.decode(value, StandardCharsets.UTF_8); } /** diff --git a/api/all/src/test/java/io/opentelemetry/api/baggage/propagation/BaggageCodecTest.java b/api/all/src/test/java/io/opentelemetry/api/baggage/propagation/BaggageCodecTest.java new file mode 100644 index 00000000000..5de8fe67638 --- /dev/null +++ b/api/all/src/test/java/io/opentelemetry/api/baggage/propagation/BaggageCodecTest.java @@ -0,0 +1,42 @@ +/* + * Copyright The OpenTelemetry Authors + * SPDX-License-Identifier: Apache-2.0 + */ + +package io.opentelemetry.api.baggage.propagation; + +import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.assertThatThrownBy; + +import java.nio.charset.StandardCharsets; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.CsvSource; + +class BaggageCodecTest { + + @ParameterizedTest + @CsvSource( + quoteCharacter = ';', // default is a quote character "'", which collides with %27 character. + value = { + "%21,!", "%23,#", "%24,$", "%25,%", "%26,&", "%27,'", "%28,(", "%29,)", "%2A,*", "%2B,+", + "%2D,-", "%2E,.", "%2F,/", "%30,0", "%31,1", "%32,2", "%33,3", "%34,4", "%35,5", "%36,6", + "%37,7", "%38,8", "%39,9", "%3A,:", "%3C,<", "%3D,=", "%3E,>", "%3F,?", "%40,@", "%41,A", + "%42,B", "%43,C", "%44,D", "%45,E", "%46,F", "%47,G", "%48,H", "%49,I", "%4A,J", "%4B,K", + "%4C,L", "%4D,M", "%4E,N", "%4F,O", "%50,P", "%51,Q", "%52,R", "%53,S", "%54,T", "%55,U", + "%56,V", "%57,W", "%58,X", "%59,Y", "%5A,Z", "%5B,[", "%5D,]", "%5E,^", "%5F,_", "%60,`", + "%61,a", "%62,b", "%63,c", "%64,d", "%65,e", "%66,f", "%67,g", "%68,h", "%69,i", "%6A,j", + "%6B,k", "%6C,l", "%6D,m", "%6E,n", "%6F,o", "%70,p", "%71,q", "%72,r", "%73,s", "%74,t", + "%75,u", "%76,v", "%77,w", "%78,x", "%79,y", "%7A,z", "%7B,{", "%7C,|", "%7D,}", "%7E,~", + }) + void shouldDecodePercentEncodedValues(String percentEncoded, String expectedDecoded) { + assertThat(BaggageCodec.decode(percentEncoded, StandardCharsets.UTF_8)) + .isEqualTo(expectedDecoded); + } + + @Test + void shouldThrowIfMalformedData() { + assertThatThrownBy(() -> BaggageCodec.decode("%1", StandardCharsets.UTF_8)) + .isInstanceOf(IllegalArgumentException.class); + } +} diff --git a/api/all/src/test/java/io/opentelemetry/api/baggage/propagation/W3CBaggagePropagatorFuzzTest.java b/api/all/src/test/java/io/opentelemetry/api/baggage/propagation/W3CBaggagePropagatorFuzzTest.java index 83e78ca0ec7..0a95e27e83c 100644 --- a/api/all/src/test/java/io/opentelemetry/api/baggage/propagation/W3CBaggagePropagatorFuzzTest.java +++ b/api/all/src/test/java/io/opentelemetry/api/baggage/propagation/W3CBaggagePropagatorFuzzTest.java @@ -18,8 +18,11 @@ import io.opentelemetry.api.baggage.BaggageEntryMetadata; import io.opentelemetry.context.Context; import io.opentelemetry.context.propagation.TextMapGetter; +import java.util.Arrays; import java.util.HashMap; +import java.util.HashSet; import java.util.Map; +import java.util.Set; import javax.annotation.Nullable; import org.junit.jupiter.api.Test; import org.junit.runner.Result; @@ -62,6 +65,17 @@ public void roundTripAsciiValues( Baggage extractedBaggage = Baggage.fromContext(extractedContext); assertThat(extractedBaggage).isEqualTo(baggage); } + + @Fuzz + public void baggageOctet(@From(BaggageOctetGenerator.class) String baggageValue) { + Map carrier = new HashMap<>(); + carrier.put("baggage", "key=" + baggageValue); + Context context = + baggagePropagator.extract(Context.current(), carrier, new MapTextMapGetter()); + Baggage baggage = Baggage.fromContext(context); + String value = baggage.getEntryValue("key"); + assertThat(value).isEqualTo(baggageValue); + } } // driver methods to avoid having to use the vintage junit engine, and to enable increasing the @@ -79,9 +93,15 @@ void roundTripFuzzing() { assertThat(result.wasSuccessful()).isTrue(); } - private static Result runTestCase(String roundTripRandomValues) { + @Test + void baggageOctetFuzzing() { + Result result = runTestCase("baggageOctet"); + assertThat(result.wasSuccessful()).isTrue(); + } + + private static Result runTestCase(String testCaseName) { return GuidedFuzzing.run( - TestCases.class, roundTripRandomValues, new NoGuidance(10000, System.out), System.out); + TestCases.class, testCaseName, new NoGuidance(10000, System.out), System.out); } public static class AsciiGenerator extends AbstractStringGenerator { @@ -109,4 +129,25 @@ public String get(Map carrier, String key) { return carrier.get(key); } } + + public static class BaggageOctetGenerator extends AbstractStringGenerator { + + private static final Set excluded = + new HashSet<>(Arrays.asList(' ', '"', ',', ';', '\\', '%')); + + @Override + protected int nextCodePoint(SourceOfRandomness random) { + while (true) { + char c = random.nextChar(' ', '~'); + if (!excluded.contains(c)) { + return c; + } + } + } + + @Override + protected boolean codePointInRange(int codePoint) { + return !excluded.contains((char) codePoint); + } + } } From 8f2c0d231ffc4c63ec23be1dad497d98a8e10927 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Thu, 10 Nov 2022 20:53:42 -0800 Subject: [PATCH 21/68] Bump armeria-bom from 1.20.2 to 1.20.3 (#4936) Bumps [armeria-bom](https://github.com/line/armeria) from 1.20.2 to 1.20.3. - [Release notes](https://github.com/line/armeria/releases) - [Changelog](https://github.com/line/armeria/blob/master/.post-release-msg) - [Commits](https://github.com/line/armeria/compare/armeria-1.20.2...armeria-1.20.3) --- updated-dependencies: - dependency-name: com.linecorp.armeria:armeria-bom dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> --- dependencyManagement/build.gradle.kts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/dependencyManagement/build.gradle.kts b/dependencyManagement/build.gradle.kts index 0027a78242d..8b7f25228f3 100644 --- a/dependencyManagement/build.gradle.kts +++ b/dependencyManagement/build.gradle.kts @@ -15,7 +15,7 @@ val DEPENDENCY_BOMS = listOf( "com.fasterxml.jackson:jackson-bom:2.14.0", "com.google.guava:guava-bom:31.1-jre", "com.google.protobuf:protobuf-bom:3.21.9", - "com.linecorp.armeria:armeria-bom:1.20.2", + "com.linecorp.armeria:armeria-bom:1.20.3", "com.squareup.okhttp3:okhttp-bom:4.10.0", "io.grpc:grpc-bom:1.50.2", "io.zipkin.brave:brave-bom:5.14.1", From 362bc0ae918049144955664bf8ff1d25c316c1c1 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Thu, 10 Nov 2022 20:54:17 -0800 Subject: [PATCH 22/68] Bump junit-pioneer from 1.7.2 to 1.8.0 (#4937) Bumps [junit-pioneer](https://github.com/junit-pioneer/junit-pioneer) from 1.7.2 to 1.8.0. - [Release notes](https://github.com/junit-pioneer/junit-pioneer/releases) - [Commits](https://github.com/junit-pioneer/junit-pioneer/compare/v1.7.2...v1.8.0) --- updated-dependencies: - dependency-name: org.junit-pioneer:junit-pioneer dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> --- dependencyManagement/build.gradle.kts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/dependencyManagement/build.gradle.kts b/dependencyManagement/build.gradle.kts index 8b7f25228f3..8f93bc51859 100644 --- a/dependencyManagement/build.gradle.kts +++ b/dependencyManagement/build.gradle.kts @@ -97,7 +97,7 @@ val DEPENDENCIES = listOf( "org.bouncycastle:bcpkix-jdk15on:1.70", "org.codehaus.mojo:animal-sniffer-annotations:1.22", "org.jctools:jctools-core:4.0.1", - "org.junit-pioneer:junit-pioneer:1.7.2", + "org.junit-pioneer:junit-pioneer:1.8.0", "org.skyscreamer:jsonassert:1.5.1", ) From c252fdfc7b46b3c51bc4744840ce6bb121956ecc Mon Sep 17 00:00:00 2001 From: jack-berg <34418638+jack-berg@users.noreply.github.com> Date: Fri, 11 Nov 2022 12:55:30 -0600 Subject: [PATCH 23/68] Prepare release 1.20.0 (#4931) * Add changelog for 1.20.0 * Add missing since annotations --- CHANGELOG.md | 85 +++++++++++++++++++ .../jaeger/JaegerGrpcSpanExporterBuilder.java | 2 + .../zipkin/ZipkinSpanExporterBuilder.java | 1 + 3 files changed, 88 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 0917c8252de..45eed04ad8a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,91 @@ ## Unreleased +### API + +- Fix bug in `W3CBaggagePropagator` that caused `+` characters to be decoded as whitespace ` `. + [(#4898)](https://github.com/open-telemetry/opentelemetry-java/pull/4898) + +#### API Extensions + +* DEPRECATION: the `opentelemetry-extension-aws` module containing + various `AwsXrayPropagator` implementations has been deprecated for removal in next major version. + A copy of the code will instead be maintained + in [opentelemetry-java-contrib/aws-xray-propagator](https://github.com/open-telemetry/opentelemetry-java-contrib/tree/main/aws-xray-propagator) + and published under + coordinates `io.opentelemetry.contrib:opentelemetry-aws-xray-propagator:{version}`. + [(#4862)](https://github.com/open-telemetry/opentelemetry-java/pull/4862) + +### SDK + +#### Traces + +* Add graal hints for shaded dependencies, allowing `JcTools` queue to be used in graal environment. + [(#4832)](https://github.com/open-telemetry/opentelemetry-java/pull/4832) +* `Sampler#getDescription()` implementations are now locale independent. + [(#4877)](https://github.com/open-telemetry/opentelemetry-java/pull/4887) +* Allow SDK to run in environments prohibiting use of `sun.misc.Unsafe`. + [(#4902)](https://github.com/open-telemetry/opentelemetry-java/pull/4902) + +#### Metrics + +* Add `toString` to `AbstractInstrument`. + [(#4833)](https://github.com/open-telemetry/opentelemetry-java/pull/4883) +* Add zero bucket boundary to default explicit bucket histogram aggregation. + [(#4819)](https://github.com/open-telemetry/opentelemetry-java/pull/4819) + +#### Logs + +* Optimize log hot path, reducing allocations significantly. + [(#4913)](https://github.com/open-telemetry/opentelemetry-java/pull/4913) +* BREAKING: Add `Context` argument to `LogRecordProcessor#onEmit`. + [(#4889)](https://github.com/open-telemetry/opentelemetry-java/pull/4889) + +#### Exporter + +* `OtlpLogging{Signal}Exporter`s encode enums as numbers. + [(#4783)](https://github.com/open-telemetry/opentelemetry-java/pull/4783) +* Add `User-Agent` header of `OTel OTLP Exporter Java/{version}` to OTLP export requests. + [(#4784)](https://github.com/open-telemetry/opentelemetry-java/pull/4784) + +#### SDK Extensions + +* WARNING: `opentelemetry-sdk-extension-aws` has been removed following its relocation + to [opentelemetry-java-contrib/instrumentation-aws-xray](https://github.com/open-telemetry/opentelemetry-java-contrib/tree/main/aws-xray), + which is published under + coordinates `io.opentelemetry.contrib:opentelemetry-aws-resources:{version}`. + We will push security patches to `1.19.x` as needed. The latest `opentelemetry-bom` will point + to the latest published version, currently `1.19.0`. + [(#4830)](https://github.com/open-telemetry/opentelemetry-java/pull/4830) +* WARNING: `opentelemetry-sdk-extension-resources` has been removed following its relocation + to [opentelemetry-java-instrumentation/instrumentation/resources/library](https://github.com/open-telemetry/opentelemetry-java-instrumentation/tree/main/instrumentation/resources/library), + which is published under + coordinates `io.opentelemetry.instrumentation:opentelemetry-resources:{version}`. + We will push security patches to `1.19.x` as needed. The latest `opentelemetry-bom` will point + to the latest published version, currently `1.19.0`. + [(#4828)](https://github.com/open-telemetry/opentelemetry-java/pull/4828) +* Add autoconfigure support for `BatchLogRecordProcessor`. + [(#4811)](https://github.com/open-telemetry/opentelemetry-java/pull/4811) +* Autoconfigure performs percent decoding on `otel.resource.attributes` values. + [(#4653)](https://github.com/open-telemetry/opentelemetry-java/issues/4653) +* Unify compression configuration for exporters including + [(#4775)](https://github.com/open-telemetry/opentelemetry-java/issues/4775): + * Fix handling of `none` in OTLP exporters. + * Add `JaegerGrpcSpanExporterBuilder#setCompression(String)`. + * Add `ZipkinSpanExporterBuilder#setCompression(String)`. + +### Semantic Conventions + +* Add migration notes to deprecated attributes + [(#4840)](https://github.com/open-telemetry/opentelemetry-java/pull/4840) + +### OpenTracing Shim + +* Use `opentracing-shim` as instrumentation scope name. + [(#4890)](https://github.com/open-telemetry/opentelemetry-java/pull/4890) +* Add full support for multiple parents. + [(#4916)](https://github.com/open-telemetry/opentelemetry-java/pull/4916) + ## Version 1.19.0 (2022-10-07) This release contains a large number of changes to the log signal following a series of significant diff --git a/exporters/jaeger/src/main/java/io/opentelemetry/exporter/jaeger/JaegerGrpcSpanExporterBuilder.java b/exporters/jaeger/src/main/java/io/opentelemetry/exporter/jaeger/JaegerGrpcSpanExporterBuilder.java index 6c0efeaeea3..8d61b9590f3 100644 --- a/exporters/jaeger/src/main/java/io/opentelemetry/exporter/jaeger/JaegerGrpcSpanExporterBuilder.java +++ b/exporters/jaeger/src/main/java/io/opentelemetry/exporter/jaeger/JaegerGrpcSpanExporterBuilder.java @@ -69,6 +69,8 @@ public JaegerGrpcSpanExporterBuilder setEndpoint(String endpoint) { /** * Sets the method used to compress payloads. If unset, compression is disabled. Currently * supported compression methods include "gzip" and "none". + * + * @since 1.20.0 */ public JaegerGrpcSpanExporterBuilder setCompression(String compressionMethod) { requireNonNull(compressionMethod, "compressionMethod"); 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 3467202b31e..a1fbf06f64e 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 @@ -101,6 +101,7 @@ public ZipkinSpanExporterBuilder setEndpoint(String endpoint) { * @param compressionMethod The compression method, ex. "gzip". * @return this. * @see OkHttpSender + * @since 1.20.0 */ public ZipkinSpanExporterBuilder setCompression(String compressionMethod) { requireNonNull(compressionMethod, "compressionMethod"); From 02f35ad00472d42a850e18ecfba9cfd3b187930a Mon Sep 17 00:00:00 2001 From: OpenTelemetry Bot <107717825+opentelemetrybot@users.noreply.github.com> Date: Fri, 11 Nov 2022 11:15:52 -0800 Subject: [PATCH 24/68] Update version to 1.21.0 (#4941) --- CHANGELOG.md | 2 ++ version.gradle.kts | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 45eed04ad8a..da72d65fd54 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,8 @@ ## Unreleased +## Version 1.20.0 (2022-11-11) + ### API - Fix bug in `W3CBaggagePropagator` that caused `+` characters to be decoded as whitespace ` `. diff --git a/version.gradle.kts b/version.gradle.kts index 72c89c25d93..9f0ea4ac9b8 100644 --- a/version.gradle.kts +++ b/version.gradle.kts @@ -1,7 +1,7 @@ val snapshot = true allprojects { - var ver = "1.20.0" + var ver = "1.21.0" val release = findProperty("otel.release") if (release != null) { ver += "-" + release From 1cb71c1445234216f0edfaab938fccfa124be9ab Mon Sep 17 00:00:00 2001 From: jack-berg <34418638+jack-berg@users.noreply.github.com> Date: Fri, 11 Nov 2022 16:04:58 -0600 Subject: [PATCH 25/68] Post release 1.20.0 (#4944) * Update version in docs * Reset japicmp --- README.md | 78 +++++++++---------- .../1.20.0_vs_1.19.0/opentelemetry-api.txt | 2 + .../opentelemetry-context.txt | 2 + .../opentelemetry-exporter-common.txt | 2 + .../opentelemetry-exporter-jaeger-thrift.txt | 2 + .../opentelemetry-exporter-jaeger.txt | 4 + .../opentelemetry-exporter-logging-otlp.txt | 2 + .../opentelemetry-exporter-logging.txt | 2 + .../opentelemetry-exporter-otlp-common.txt | 2 + .../opentelemetry-exporter-otlp.txt | 2 + .../opentelemetry-exporter-zipkin.txt | 4 + .../opentelemetry-extension-aws.txt | 7 ++ .../opentelemetry-extension-kotlin.txt | 2 + ...ntelemetry-extension-trace-propagators.txt | 2 + .../opentelemetry-sdk-common.txt | 2 + ...emetry-sdk-extension-autoconfigure-spi.txt | 2 + ...ry-sdk-extension-jaeger-remote-sampler.txt | 2 + .../opentelemetry-sdk-metrics.txt | 2 + .../opentelemetry-sdk-testing.txt | 2 + .../opentelemetry-sdk-trace.txt | 2 + .../1.20.0_vs_1.19.0/opentelemetry-sdk.txt | 2 + .../opentelemetry-exporter-jaeger.txt | 4 +- .../opentelemetry-exporter-zipkin.txt | 4 +- .../opentelemetry-extension-aws.txt | 7 +- 24 files changed, 91 insertions(+), 51 deletions(-) create mode 100644 docs/apidiffs/1.20.0_vs_1.19.0/opentelemetry-api.txt create mode 100644 docs/apidiffs/1.20.0_vs_1.19.0/opentelemetry-context.txt create mode 100644 docs/apidiffs/1.20.0_vs_1.19.0/opentelemetry-exporter-common.txt create mode 100644 docs/apidiffs/1.20.0_vs_1.19.0/opentelemetry-exporter-jaeger-thrift.txt create mode 100644 docs/apidiffs/1.20.0_vs_1.19.0/opentelemetry-exporter-jaeger.txt create mode 100644 docs/apidiffs/1.20.0_vs_1.19.0/opentelemetry-exporter-logging-otlp.txt create mode 100644 docs/apidiffs/1.20.0_vs_1.19.0/opentelemetry-exporter-logging.txt create mode 100644 docs/apidiffs/1.20.0_vs_1.19.0/opentelemetry-exporter-otlp-common.txt create mode 100644 docs/apidiffs/1.20.0_vs_1.19.0/opentelemetry-exporter-otlp.txt create mode 100644 docs/apidiffs/1.20.0_vs_1.19.0/opentelemetry-exporter-zipkin.txt create mode 100644 docs/apidiffs/1.20.0_vs_1.19.0/opentelemetry-extension-aws.txt create mode 100644 docs/apidiffs/1.20.0_vs_1.19.0/opentelemetry-extension-kotlin.txt create mode 100644 docs/apidiffs/1.20.0_vs_1.19.0/opentelemetry-extension-trace-propagators.txt create mode 100644 docs/apidiffs/1.20.0_vs_1.19.0/opentelemetry-sdk-common.txt create mode 100644 docs/apidiffs/1.20.0_vs_1.19.0/opentelemetry-sdk-extension-autoconfigure-spi.txt create mode 100644 docs/apidiffs/1.20.0_vs_1.19.0/opentelemetry-sdk-extension-jaeger-remote-sampler.txt create mode 100644 docs/apidiffs/1.20.0_vs_1.19.0/opentelemetry-sdk-metrics.txt create mode 100644 docs/apidiffs/1.20.0_vs_1.19.0/opentelemetry-sdk-testing.txt create mode 100644 docs/apidiffs/1.20.0_vs_1.19.0/opentelemetry-sdk-trace.txt create mode 100644 docs/apidiffs/1.20.0_vs_1.19.0/opentelemetry-sdk.txt diff --git a/README.md b/README.md index cff5bfaa3d9..d99dccef173 100644 --- a/README.md +++ b/README.md @@ -91,7 +91,7 @@ dependency versions in sync. io.opentelemetry opentelemetry-bom - 1.19.0 + 1.20.0 pom import @@ -110,7 +110,7 @@ dependency versions in sync. ```groovy dependencies { - implementation platform("io.opentelemetry:opentelemetry-bom:1.19.0") + implementation platform("io.opentelemetry:opentelemetry-bom:1.20.0") implementation('io.opentelemetry:opentelemetry-api') } ``` @@ -119,8 +119,8 @@ Note that if you want to use any artifacts that have not fully stabilized yet (s ```groovy dependencies { - implementation platform("io.opentelemetry:opentelemetry-bom:1.19.0") - implementation platform('io.opentelemetry:opentelemetry-bom-alpha:1.19.0-alpha') + implementation platform("io.opentelemetry:opentelemetry-bom:1.20.0") + implementation platform('io.opentelemetry:opentelemetry-bom-alpha:1.20.0-alpha') implementation('io.opentelemetry:opentelemetry-api') implementation('io.opentelemetry:opentelemetry-semconv') @@ -148,7 +148,7 @@ We strongly recommend using our published BOM to keep all dependency versions in io.opentelemetry opentelemetry-bom - 1.20.0-SNAPSHOT + 1.21.0-SNAPSHOT pom import @@ -171,7 +171,7 @@ repositories { } dependencies { - implementation platform("io.opentelemetry:opentelemetry-bom:1.20.0-SNAPSHOT") + implementation platform("io.opentelemetry:opentelemetry-bom:1.21.0-SNAPSHOT") implementation('io.opentelemetry:opentelemetry-api') } ``` @@ -216,69 +216,69 @@ dependency as follows, replacing `{{artifact-id}}` with the value from the "Arti | Component | Description | Artifact ID | Version | |----------------------------------------------|----------------------------------------|---------------------------|-------------------------------------------------------------| -| [Bill of Materials (BOM)](./bom) | Bill of materials for stable artifacts | `opentelemetry-bom` | 1.19.0 | -| [Alpha Bill of Materials (BOM)](./bom-alpha) | Bill of materials for alpha artifacts | `opentelemetry-bom-alpha` | 1.19.0-alpha | +| [Bill of Materials (BOM)](./bom) | Bill of materials for stable artifacts | `opentelemetry-bom` | 1.20.0 | +| [Alpha Bill of Materials (BOM)](./bom-alpha) | Bill of materials for alpha artifacts | `opentelemetry-bom-alpha` | 1.20.0-alpha | ### API | Component | Description | Artifact ID | Version | |-----------------------------------|----------------------------------------------------------------------------------------------------------------------------------------------------|--------------------------|-------------------------------------------------------------| -| [API](./api/all) | OpenTelemetry API, including metrics, traces, baggage, context | `opentelemetry-api` | 1.19.0 | -| [Logs API](./api/logs) | OpenTelemetry Log API for emitting events and bridging log frameworks (NOT a replacement for application logging frameworks like SLF4J, JUL, etc.) | `opentelemetry-api-logs` | 1.19.0-alpha | -| [Context API](./context) | OpenTelemetry context API | `opentelemetry-context` | 1.19.0 | -| [Semantic Conventions](./semconv) | Generated code for OpenTelemetry semantic conventions | `opentelemetry-semconv` | 1.19.0-alpha | +| [API](./api/all) | OpenTelemetry API, including metrics, traces, baggage, context | `opentelemetry-api` | 1.20.0 | +| [Logs API](./api/logs) | OpenTelemetry Log API for emitting events and bridging log frameworks (NOT a replacement for application logging frameworks like SLF4J, JUL, etc.) | `opentelemetry-api-logs` | 1.20.0-alpha | +| [Context API](./context) | OpenTelemetry context API | `opentelemetry-context` | 1.20.0 | +| [Semantic Conventions](./semconv) | Generated code for OpenTelemetry semantic conventions | `opentelemetry-semconv` | 1.20.0-alpha | ### API Extensions | Component | Description | Artifact ID | Version | |---------------------------------------------------------------|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|---------------------------------------------|-------------------------------------------------------------| -| [AWS Extension](./extensions/aws) | AWS Xray propagator (deprecated, moved to [opentelemetry-java-contrib/aws-xray-propagator](https://github.com/open-telemetry/opentelemetry-java-contrib/tree/main/aws-xray-propagator)) | `opentelemetry-extension-aws` | 1.19.0 | -| [Kotlin Extension](./extensions/kotlin) | Context extension for coroutines | `opentelemetry-extension-kotlin` | 1.19.0 | -| [Trace Propagators Extension](./extensions/trace-propagators) | Trace propagators, including B3, Jaeger, OT Trace | `opentelemetry-extension-trace-propagators` | 1.19.0 | -| [Incubator Extension](./extensions/incubator) | API incubator, including pass through propagator, and extended tracer | `opentelemetry-extension-incubator` | 1.19.0-alpha | +| [AWS Extension](./extensions/aws) | AWS Xray propagator (deprecated, moved to [opentelemetry-java-contrib/aws-xray-propagator](https://github.com/open-telemetry/opentelemetry-java-contrib/tree/main/aws-xray-propagator)) | `opentelemetry-extension-aws` | 1.20.0 | +| [Kotlin Extension](./extensions/kotlin) | Context extension for coroutines | `opentelemetry-extension-kotlin` | 1.20.0 | +| [Trace Propagators Extension](./extensions/trace-propagators) | Trace propagators, including B3, Jaeger, OT Trace | `opentelemetry-extension-trace-propagators` | 1.20.0 | +| [Incubator Extension](./extensions/incubator) | API incubator, including pass through propagator, and extended tracer | `opentelemetry-extension-incubator` | 1.20.0-alpha | ### SDK | Component | Description | Artifact ID | Version | |----------------------------------------|--------------------------------------------------------|----------------------------------|-------------------------------------------------------------| -| [SDK](./sdk/all) | OpenTelemetry SDK, including metrics, traces, and logs | `opentelemetry-sdk` | 1.19.0 | -| [Metrics SDK](./sdk/metrics) | OpenTelemetry metrics SDK | `opentelemetry-sdk-metrics` | 1.19.0 | -| [Trace SDK](./sdk/trace) | OpenTelemetry trace SDK | `opentelemetry-sdk-trace` | 1.19.0 | -| [Log SDK](./sdk/logs) | OpenTelemetry log SDK | `opentelemetry-sdk-logs` | 1.19.0-alpha | -| [SDK Common](./sdk/common) | Shared SDK components | `opentelemetry-sdk-common` | 1.19.0 | -| [SDK Testing](./sdk/testing) | Components for testing OpenTelemetry instrumentation | `opentelemetry-sdk-testing` | 1.19.0 | -| [SDK Logs Testing](./sdk/logs-testing) | Components for testing OpenTelemetry logs | `opentelemetry-sdk-logs-testing` | 1.19.0-alpha | +| [SDK](./sdk/all) | OpenTelemetry SDK, including metrics, traces, and logs | `opentelemetry-sdk` | 1.20.0 | +| [Metrics SDK](./sdk/metrics) | OpenTelemetry metrics SDK | `opentelemetry-sdk-metrics` | 1.20.0 | +| [Trace SDK](./sdk/trace) | OpenTelemetry trace SDK | `opentelemetry-sdk-trace` | 1.20.0 | +| [Log SDK](./sdk/logs) | OpenTelemetry log SDK | `opentelemetry-sdk-logs` | 1.20.0-alpha | +| [SDK Common](./sdk/common) | Shared SDK components | `opentelemetry-sdk-common` | 1.20.0 | +| [SDK Testing](./sdk/testing) | Components for testing OpenTelemetry instrumentation | `opentelemetry-sdk-testing` | 1.20.0 | +| [SDK Logs Testing](./sdk/logs-testing) | Components for testing OpenTelemetry logs | `opentelemetry-sdk-logs-testing` | 1.20.0-alpha | ### SDK Exporters | Component | Description | Artifact ID | Version | |-----------------------------------------------------|-------------------------------------------------------------------------------------|---------------------------------------|-------------------------------------------------------------| -| [OTLP Exporters](./exporters/otlp/all) | OTLP gRPC & HTTP exporters, including metrics and trace | `opentelemetry-exporter-otlp` | 1.19.0 | -| [OTLP Log Exporters](./exporters/otlp/logs) | OTLP gRPC & HTTP log exporters | `opentelemetry-exporter-otlp-logs` | 1.19.0-alpha | -| [OTLP Common](./exporters/otlp/common) | Shared OTLP components (internal) | `opentelemetry-exporter-otlp-common` | 1.19.0 | -| [Jaeger gRPC Exporter](./exporters/jaeger) | Jaeger gRPC trace exporter | `opentelemetry-exporter-jaeger` | 1.19.0 | -| [Jaeger Thrift Exporter](./exporters/jaeger-thrift) | Jaeger thrift trace exporter | `opentelemetry-exporter-jaeger-thift` | 1.19.0 | -| [Logging Exporter](./exporters/logging) | Logging exporters, includings metrics, traces, and logs | `opentelemetry-exporter-logging` | 1.19.0 | -| [OTLP Logging Exporter](./exporters/logging-otlp) | Logging exporters in OTLP protobuf JSON format, including metrics, traces, and logs | `opentelemetry-exporter-logging-otlp` | 1.19.0 | -| [Zipkin Exporter](./exporters/zipkin) | Zipkin trace exporter | `opentelemetry-exporter-zipkin` | 1.19.0 | -| [Prometheus Exporter](./exporters/prometheus) | Prometheus metric exporter | `opentelemetry-exporter-prometheus` | 1.19.0-alpha | -| [Exporter Common](./exporters/common) | Shared exporter components (internal) | `opentelemetry-exporter-common` | 1.19.0 | +| [OTLP Exporters](./exporters/otlp/all) | OTLP gRPC & HTTP exporters, including metrics and trace | `opentelemetry-exporter-otlp` | 1.20.0 | +| [OTLP Log Exporters](./exporters/otlp/logs) | OTLP gRPC & HTTP log exporters | `opentelemetry-exporter-otlp-logs` | 1.20.0-alpha | +| [OTLP Common](./exporters/otlp/common) | Shared OTLP components (internal) | `opentelemetry-exporter-otlp-common` | 1.20.0 | +| [Jaeger gRPC Exporter](./exporters/jaeger) | Jaeger gRPC trace exporter | `opentelemetry-exporter-jaeger` | 1.20.0 | +| [Jaeger Thrift Exporter](./exporters/jaeger-thrift) | Jaeger thrift trace exporter | `opentelemetry-exporter-jaeger-thift` | 1.20.0 | +| [Logging Exporter](./exporters/logging) | Logging exporters, includings metrics, traces, and logs | `opentelemetry-exporter-logging` | 1.20.0 | +| [OTLP Logging Exporter](./exporters/logging-otlp) | Logging exporters in OTLP protobuf JSON format, including metrics, traces, and logs | `opentelemetry-exporter-logging-otlp` | 1.20.0 | +| [Zipkin Exporter](./exporters/zipkin) | Zipkin trace exporter | `opentelemetry-exporter-zipkin` | 1.20.0 | +| [Prometheus Exporter](./exporters/prometheus) | Prometheus metric exporter | `opentelemetry-exporter-prometheus` | 1.20.0-alpha | +| [Exporter Common](./exporters/common) | Shared exporter components (internal) | `opentelemetry-exporter-common` | 1.20.0 | ### SDK Extensions | Component | Description | Artifact ID | Version | |-------------------------------------------------------------------------------|------------------------------------------------------------------------------------------------|-----------------------------------------------------|-------------------------------------------------------------| -| [SDK Autoconfigure Extension](./sdk-extensions/autoconfigure) | Autoconfigure OpenTelemetry SDK from env vars, system properties, and SPI | `opentelemetry-sdk-extension-autoconfigure` | 1.19.0-alpha | -| [SDK Autoconfigure SPI](./sdk-extensions/autoconfigure-spi) | Service Provider Interface (SPI) definitions for autoconfigure | `opentelemetry-sdk-extension-autoconfigure-spi` | 1.19.0 | -| [SDK Jaeger Remote Sampler Extension](./sdk-extensions/jaeger-remote-sampler) | Sampler which obtains sampling configuration from remote Jaeger server | `opentelemetry-sdk-extension-jaeger-remote-sampler` | 1.19.0 | -| [SDK Incubator](./sdk-extensions/incubator) | SDK incubator, including YAML based view configuration, LeakDetectingSpanProcessor, and zPages | `opentelemetry-sdk-extension-incubator` | 1.19.0-alpha | +| [SDK Autoconfigure Extension](./sdk-extensions/autoconfigure) | Autoconfigure OpenTelemetry SDK from env vars, system properties, and SPI | `opentelemetry-sdk-extension-autoconfigure` | 1.20.0-alpha | +| [SDK Autoconfigure SPI](./sdk-extensions/autoconfigure-spi) | Service Provider Interface (SPI) definitions for autoconfigure | `opentelemetry-sdk-extension-autoconfigure-spi` | 1.20.0 | +| [SDK Jaeger Remote Sampler Extension](./sdk-extensions/jaeger-remote-sampler) | Sampler which obtains sampling configuration from remote Jaeger server | `opentelemetry-sdk-extension-jaeger-remote-sampler` | 1.20.0 | +| [SDK Incubator](./sdk-extensions/incubator) | SDK incubator, including YAML based view configuration, LeakDetectingSpanProcessor, and zPages | `opentelemetry-sdk-extension-incubator` | 1.20.0-alpha | ### Shims | Component | Description | Artifact ID | Version | |----------------------------------------|--------------------------------------------------------------|----------------------------------|-------------------------------------------------------------| -| [OpenCensus Shim](./opencensus-shim) | Bridge opencensus metrics into the OpenTelemetry metrics SDK | `opentelemetry-opencensus-shim` | 1.19.0-alpha | -| [OpenTracing Shim](./opentracing-shim) | Bridge opentracing spans into the OpenTelemetry trace API | `opentelemetry-opentracing-shim` | 1.19.0-alpha | +| [OpenCensus Shim](./opencensus-shim) | Bridge opencensus metrics into the OpenTelemetry metrics SDK | `opentelemetry-opencensus-shim` | 1.20.0-alpha | +| [OpenTracing Shim](./opentracing-shim) | Bridge opentracing spans into the OpenTelemetry trace API | `opentelemetry-opentracing-shim` | 1.20.0-alpha | ## Contributing diff --git a/docs/apidiffs/1.20.0_vs_1.19.0/opentelemetry-api.txt b/docs/apidiffs/1.20.0_vs_1.19.0/opentelemetry-api.txt new file mode 100644 index 00000000000..df26146497b --- /dev/null +++ b/docs/apidiffs/1.20.0_vs_1.19.0/opentelemetry-api.txt @@ -0,0 +1,2 @@ +Comparing source compatibility of against +No changes. \ No newline at end of file diff --git a/docs/apidiffs/1.20.0_vs_1.19.0/opentelemetry-context.txt b/docs/apidiffs/1.20.0_vs_1.19.0/opentelemetry-context.txt new file mode 100644 index 00000000000..df26146497b --- /dev/null +++ b/docs/apidiffs/1.20.0_vs_1.19.0/opentelemetry-context.txt @@ -0,0 +1,2 @@ +Comparing source compatibility of against +No changes. \ No newline at end of file diff --git a/docs/apidiffs/1.20.0_vs_1.19.0/opentelemetry-exporter-common.txt b/docs/apidiffs/1.20.0_vs_1.19.0/opentelemetry-exporter-common.txt new file mode 100644 index 00000000000..df26146497b --- /dev/null +++ b/docs/apidiffs/1.20.0_vs_1.19.0/opentelemetry-exporter-common.txt @@ -0,0 +1,2 @@ +Comparing source compatibility of against +No changes. \ No newline at end of file diff --git a/docs/apidiffs/1.20.0_vs_1.19.0/opentelemetry-exporter-jaeger-thrift.txt b/docs/apidiffs/1.20.0_vs_1.19.0/opentelemetry-exporter-jaeger-thrift.txt new file mode 100644 index 00000000000..df26146497b --- /dev/null +++ b/docs/apidiffs/1.20.0_vs_1.19.0/opentelemetry-exporter-jaeger-thrift.txt @@ -0,0 +1,2 @@ +Comparing source compatibility of against +No changes. \ No newline at end of file diff --git a/docs/apidiffs/1.20.0_vs_1.19.0/opentelemetry-exporter-jaeger.txt b/docs/apidiffs/1.20.0_vs_1.19.0/opentelemetry-exporter-jaeger.txt new file mode 100644 index 00000000000..f2e115c71f2 --- /dev/null +++ b/docs/apidiffs/1.20.0_vs_1.19.0/opentelemetry-exporter-jaeger.txt @@ -0,0 +1,4 @@ +Comparing source compatibility of against +*** MODIFIED CLASS: PUBLIC FINAL io.opentelemetry.exporter.jaeger.JaegerGrpcSpanExporterBuilder (not serializable) + === CLASS FILE FORMAT VERSION: 52.0 <- 52.0 + +++ NEW METHOD: PUBLIC(+) io.opentelemetry.exporter.jaeger.JaegerGrpcSpanExporterBuilder setCompression(java.lang.String) diff --git a/docs/apidiffs/1.20.0_vs_1.19.0/opentelemetry-exporter-logging-otlp.txt b/docs/apidiffs/1.20.0_vs_1.19.0/opentelemetry-exporter-logging-otlp.txt new file mode 100644 index 00000000000..df26146497b --- /dev/null +++ b/docs/apidiffs/1.20.0_vs_1.19.0/opentelemetry-exporter-logging-otlp.txt @@ -0,0 +1,2 @@ +Comparing source compatibility of against +No changes. \ No newline at end of file diff --git a/docs/apidiffs/1.20.0_vs_1.19.0/opentelemetry-exporter-logging.txt b/docs/apidiffs/1.20.0_vs_1.19.0/opentelemetry-exporter-logging.txt new file mode 100644 index 00000000000..df26146497b --- /dev/null +++ b/docs/apidiffs/1.20.0_vs_1.19.0/opentelemetry-exporter-logging.txt @@ -0,0 +1,2 @@ +Comparing source compatibility of against +No changes. \ No newline at end of file diff --git a/docs/apidiffs/1.20.0_vs_1.19.0/opentelemetry-exporter-otlp-common.txt b/docs/apidiffs/1.20.0_vs_1.19.0/opentelemetry-exporter-otlp-common.txt new file mode 100644 index 00000000000..df26146497b --- /dev/null +++ b/docs/apidiffs/1.20.0_vs_1.19.0/opentelemetry-exporter-otlp-common.txt @@ -0,0 +1,2 @@ +Comparing source compatibility of against +No changes. \ No newline at end of file diff --git a/docs/apidiffs/1.20.0_vs_1.19.0/opentelemetry-exporter-otlp.txt b/docs/apidiffs/1.20.0_vs_1.19.0/opentelemetry-exporter-otlp.txt new file mode 100644 index 00000000000..df26146497b --- /dev/null +++ b/docs/apidiffs/1.20.0_vs_1.19.0/opentelemetry-exporter-otlp.txt @@ -0,0 +1,2 @@ +Comparing source compatibility of against +No changes. \ No newline at end of file diff --git a/docs/apidiffs/1.20.0_vs_1.19.0/opentelemetry-exporter-zipkin.txt b/docs/apidiffs/1.20.0_vs_1.19.0/opentelemetry-exporter-zipkin.txt new file mode 100644 index 00000000000..535314c07b1 --- /dev/null +++ b/docs/apidiffs/1.20.0_vs_1.19.0/opentelemetry-exporter-zipkin.txt @@ -0,0 +1,4 @@ +Comparing source compatibility of against +*** MODIFIED CLASS: PUBLIC FINAL io.opentelemetry.exporter.zipkin.ZipkinSpanExporterBuilder (not serializable) + === CLASS FILE FORMAT VERSION: 52.0 <- 52.0 + +++ NEW METHOD: PUBLIC(+) io.opentelemetry.exporter.zipkin.ZipkinSpanExporterBuilder setCompression(java.lang.String) diff --git a/docs/apidiffs/1.20.0_vs_1.19.0/opentelemetry-extension-aws.txt b/docs/apidiffs/1.20.0_vs_1.19.0/opentelemetry-extension-aws.txt new file mode 100644 index 00000000000..979e67fbfcf --- /dev/null +++ b/docs/apidiffs/1.20.0_vs_1.19.0/opentelemetry-extension-aws.txt @@ -0,0 +1,7 @@ +Comparing source compatibility of against +=== UNCHANGED CLASS: PUBLIC FINAL io.opentelemetry.extension.aws.AwsConfigurablePropagator (not serializable) + === CLASS FILE FORMAT VERSION: 52.0 <- 52.0 + +++ NEW ANNOTATION: java.lang.Deprecated +=== UNCHANGED CLASS: PUBLIC FINAL io.opentelemetry.extension.aws.AwsXrayPropagator (not serializable) + === CLASS FILE FORMAT VERSION: 52.0 <- 52.0 + +++ NEW ANNOTATION: java.lang.Deprecated diff --git a/docs/apidiffs/1.20.0_vs_1.19.0/opentelemetry-extension-kotlin.txt b/docs/apidiffs/1.20.0_vs_1.19.0/opentelemetry-extension-kotlin.txt new file mode 100644 index 00000000000..df26146497b --- /dev/null +++ b/docs/apidiffs/1.20.0_vs_1.19.0/opentelemetry-extension-kotlin.txt @@ -0,0 +1,2 @@ +Comparing source compatibility of against +No changes. \ No newline at end of file diff --git a/docs/apidiffs/1.20.0_vs_1.19.0/opentelemetry-extension-trace-propagators.txt b/docs/apidiffs/1.20.0_vs_1.19.0/opentelemetry-extension-trace-propagators.txt new file mode 100644 index 00000000000..df26146497b --- /dev/null +++ b/docs/apidiffs/1.20.0_vs_1.19.0/opentelemetry-extension-trace-propagators.txt @@ -0,0 +1,2 @@ +Comparing source compatibility of against +No changes. \ No newline at end of file diff --git a/docs/apidiffs/1.20.0_vs_1.19.0/opentelemetry-sdk-common.txt b/docs/apidiffs/1.20.0_vs_1.19.0/opentelemetry-sdk-common.txt new file mode 100644 index 00000000000..df26146497b --- /dev/null +++ b/docs/apidiffs/1.20.0_vs_1.19.0/opentelemetry-sdk-common.txt @@ -0,0 +1,2 @@ +Comparing source compatibility of against +No changes. \ No newline at end of file diff --git a/docs/apidiffs/1.20.0_vs_1.19.0/opentelemetry-sdk-extension-autoconfigure-spi.txt b/docs/apidiffs/1.20.0_vs_1.19.0/opentelemetry-sdk-extension-autoconfigure-spi.txt new file mode 100644 index 00000000000..df26146497b --- /dev/null +++ b/docs/apidiffs/1.20.0_vs_1.19.0/opentelemetry-sdk-extension-autoconfigure-spi.txt @@ -0,0 +1,2 @@ +Comparing source compatibility of against +No changes. \ No newline at end of file diff --git a/docs/apidiffs/1.20.0_vs_1.19.0/opentelemetry-sdk-extension-jaeger-remote-sampler.txt b/docs/apidiffs/1.20.0_vs_1.19.0/opentelemetry-sdk-extension-jaeger-remote-sampler.txt new file mode 100644 index 00000000000..df26146497b --- /dev/null +++ b/docs/apidiffs/1.20.0_vs_1.19.0/opentelemetry-sdk-extension-jaeger-remote-sampler.txt @@ -0,0 +1,2 @@ +Comparing source compatibility of against +No changes. \ No newline at end of file diff --git a/docs/apidiffs/1.20.0_vs_1.19.0/opentelemetry-sdk-metrics.txt b/docs/apidiffs/1.20.0_vs_1.19.0/opentelemetry-sdk-metrics.txt new file mode 100644 index 00000000000..df26146497b --- /dev/null +++ b/docs/apidiffs/1.20.0_vs_1.19.0/opentelemetry-sdk-metrics.txt @@ -0,0 +1,2 @@ +Comparing source compatibility of against +No changes. \ No newline at end of file diff --git a/docs/apidiffs/1.20.0_vs_1.19.0/opentelemetry-sdk-testing.txt b/docs/apidiffs/1.20.0_vs_1.19.0/opentelemetry-sdk-testing.txt new file mode 100644 index 00000000000..df26146497b --- /dev/null +++ b/docs/apidiffs/1.20.0_vs_1.19.0/opentelemetry-sdk-testing.txt @@ -0,0 +1,2 @@ +Comparing source compatibility of against +No changes. \ No newline at end of file diff --git a/docs/apidiffs/1.20.0_vs_1.19.0/opentelemetry-sdk-trace.txt b/docs/apidiffs/1.20.0_vs_1.19.0/opentelemetry-sdk-trace.txt new file mode 100644 index 00000000000..df26146497b --- /dev/null +++ b/docs/apidiffs/1.20.0_vs_1.19.0/opentelemetry-sdk-trace.txt @@ -0,0 +1,2 @@ +Comparing source compatibility of against +No changes. \ No newline at end of file diff --git a/docs/apidiffs/1.20.0_vs_1.19.0/opentelemetry-sdk.txt b/docs/apidiffs/1.20.0_vs_1.19.0/opentelemetry-sdk.txt new file mode 100644 index 00000000000..df26146497b --- /dev/null +++ b/docs/apidiffs/1.20.0_vs_1.19.0/opentelemetry-sdk.txt @@ -0,0 +1,2 @@ +Comparing source compatibility of against +No changes. \ No newline at end of file diff --git a/docs/apidiffs/current_vs_latest/opentelemetry-exporter-jaeger.txt b/docs/apidiffs/current_vs_latest/opentelemetry-exporter-jaeger.txt index f2e115c71f2..df26146497b 100644 --- a/docs/apidiffs/current_vs_latest/opentelemetry-exporter-jaeger.txt +++ b/docs/apidiffs/current_vs_latest/opentelemetry-exporter-jaeger.txt @@ -1,4 +1,2 @@ Comparing source compatibility of against -*** MODIFIED CLASS: PUBLIC FINAL io.opentelemetry.exporter.jaeger.JaegerGrpcSpanExporterBuilder (not serializable) - === CLASS FILE FORMAT VERSION: 52.0 <- 52.0 - +++ NEW METHOD: PUBLIC(+) io.opentelemetry.exporter.jaeger.JaegerGrpcSpanExporterBuilder setCompression(java.lang.String) +No changes. \ No newline at end of file diff --git a/docs/apidiffs/current_vs_latest/opentelemetry-exporter-zipkin.txt b/docs/apidiffs/current_vs_latest/opentelemetry-exporter-zipkin.txt index 535314c07b1..df26146497b 100644 --- a/docs/apidiffs/current_vs_latest/opentelemetry-exporter-zipkin.txt +++ b/docs/apidiffs/current_vs_latest/opentelemetry-exporter-zipkin.txt @@ -1,4 +1,2 @@ Comparing source compatibility of against -*** MODIFIED CLASS: PUBLIC FINAL io.opentelemetry.exporter.zipkin.ZipkinSpanExporterBuilder (not serializable) - === CLASS FILE FORMAT VERSION: 52.0 <- 52.0 - +++ NEW METHOD: PUBLIC(+) io.opentelemetry.exporter.zipkin.ZipkinSpanExporterBuilder setCompression(java.lang.String) +No changes. \ No newline at end of file diff --git a/docs/apidiffs/current_vs_latest/opentelemetry-extension-aws.txt b/docs/apidiffs/current_vs_latest/opentelemetry-extension-aws.txt index 979e67fbfcf..df26146497b 100644 --- a/docs/apidiffs/current_vs_latest/opentelemetry-extension-aws.txt +++ b/docs/apidiffs/current_vs_latest/opentelemetry-extension-aws.txt @@ -1,7 +1,2 @@ Comparing source compatibility of against -=== UNCHANGED CLASS: PUBLIC FINAL io.opentelemetry.extension.aws.AwsConfigurablePropagator (not serializable) - === CLASS FILE FORMAT VERSION: 52.0 <- 52.0 - +++ NEW ANNOTATION: java.lang.Deprecated -=== UNCHANGED CLASS: PUBLIC FINAL io.opentelemetry.extension.aws.AwsXrayPropagator (not serializable) - === CLASS FILE FORMAT VERSION: 52.0 <- 52.0 - +++ NEW ANNOTATION: java.lang.Deprecated +No changes. \ No newline at end of file From aadcca8cf30f22331fbd6b0ba2c5ce5147dfce12 Mon Sep 17 00:00:00 2001 From: jack-berg <34418638+jack-berg@users.noreply.github.com> Date: Fri, 11 Nov 2022 16:05:21 -0600 Subject: [PATCH 26/68] Stop trying to update opentelemetry-java-instrumentation on release (#4943) --- .github/workflows/release.yml | 8 -- ...eate-java-instrumentation-pull-request.yml | 74 ------------------- 2 files changed, 82 deletions(-) delete mode 100644 .github/workflows/reusable-create-java-instrumentation-pull-request.yml diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 15b54964eb2..fc3e19e101f 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -201,14 +201,6 @@ jobs: --head $branch \ --base main - create-java-instrumentation-pull-request: - needs: release - uses: ./.github/workflows/reusable-create-java-instrumentation-pull-request.yml - with: - version: ${{ needs.release.outputs.version }} - secrets: - BOT_TOKEN: ${{ secrets.BOT_TOKEN }} - create-website-pull-request: needs: release uses: ./.github/workflows/reusable-create-website-pull-request.yml diff --git a/.github/workflows/reusable-create-java-instrumentation-pull-request.yml b/.github/workflows/reusable-create-java-instrumentation-pull-request.yml deleted file mode 100644 index 3e9b4bfab28..00000000000 --- a/.github/workflows/reusable-create-java-instrumentation-pull-request.yml +++ /dev/null @@ -1,74 +0,0 @@ -name: Reusable - Create Java instrumentation pull request - -on: - workflow_call: - inputs: - version: - type: string - required: true - secrets: - BOT_TOKEN: - required: true - # to help with partial release build failures - workflow_dispatch: - inputs: - version: - description: "Version" - required: true - -jobs: - create-java-instrumentation-pull-request: - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v3 - with: - repository: opentelemetrybot/opentelemetry-java-instrumentation - # this is the personal access token used for "git push" below - token: ${{ secrets.BOT_TOKEN }} - - - name: Initialize pull request branch - env: - VERSION: ${{ inputs.version }} - run: | - git remote add upstream https://github.com/open-telemetry/opentelemetry-java-instrumentation.git - git fetch upstream - git checkout -b update-opentelemetry-sdk-to-${VERSION} upstream/main - - - name: Update version - env: - VERSION: ${{ inputs.version }} - run: ./.github/scripts/update-sdk-version.sh $VERSION - - - name: Update license report - uses: gradle/gradle-build-action@v2 - with: - arguments: generateLicenseReport - - - name: Use CLA approved github bot - run: .github/scripts/use-cla-approved-github-bot.sh - - - name: Create pull request against opentelemetry-java-instrumentation - env: - # this is the personal access token used for "gh pr create" below - GITHUB_TOKEN: ${{ secrets.BOT_TOKEN }} - VERSION: ${{ inputs.version }} - run: | - message="Update the SDK version to $VERSION" - body=$(cat << EOF - Update the SDK version to \`$VERSION\`. - - Note: you will likely need to re-run the checks on this PR in an hour or so, once the - updated dependencies are visible in maven central. - EOF - ) - - # gh pr create doesn't have a way to explicitly specify different head and base - # repositories currently, but it will implicitly pick up the head from a different - # repository if you set up a tracking branch - - git commit -a -m "$message" - git push --set-upstream origin HEAD:update-opentelemetry-sdk-to-${VERSION} - gh pr create --title "$message" \ - --body "$body" \ - --repo open-telemetry/opentelemetry-java-instrumentation \ - --base main From 61b117079d2fb2b5338f8885562d968e3308ed21 Mon Sep 17 00:00:00 2001 From: jason plumb <75337021+breedx-splk@users.noreply.github.com> Date: Sat, 12 Nov 2022 06:49:56 -0800 Subject: [PATCH 27/68] De-singleton ZPageServer implementation (#4935) * remove the static/singleton nature from ZPageServer * add convenience method for creating zpages-based sdktracerprovider * update readme for zpageserver * oh checkstyle. * overload build and add test --- sdk-extensions/incubator/README.md | 35 +++++---- .../incubator/trace/zpages/ZPageServer.java | 74 +++++++++++++------ .../trace/zpages/ZPageServerTest.java | 23 +++++- 3 files changed, 91 insertions(+), 41 deletions(-) diff --git a/sdk-extensions/incubator/README.md b/sdk-extensions/incubator/README.md index c497fb2e6d9..ef52abea68d 100644 --- a/sdk-extensions/incubator/README.md +++ b/sdk-extensions/incubator/README.md @@ -108,30 +108,37 @@ make sure your version of the JDK includes this package. To setup the zPages, register zPages with your `OpenTelemetrySdk` and -call `ZPageServer.startHttpServerAndRegisterAllPages(int port)`: +call `startHttpServerAndRegisterAllPages(int port)` on your ZPageServer instance: ```java public class MyMainClass { public static void main(String[] args) throws Exception { + // Create a new ZPageServer + ZPageServer zpageServer = ZPageServer.create(); // Configure OpenTelemetrySdk with zPages - OpenTelemetry openTelemetry = OpenTelemetrySdk.builder() - .setTracerProvider( - SdkTracerProvider.builder() - .addSpanProcessor(ZPageServer.getSpanProcessor()) - .setSpanLimits(ZPageServer.getTracezTraceConfigSupplier()) - .setSampler(ZPageServer.getTracezSampler()) - .build()) - .build(); + OpenTelemetry openTelemetry = + OpenTelemetrySdk.builder().setTracerProvider(zpageServer.buildSdkTracerProvider()).build(); // Start zPages server - ZPageServer.startHttpServerAndRegisterAllPages(8080); - // ... do work + zpageServer.startHttpServerAndRegisterAllPages(8080); + // ...Do work (this is just an example) + long count = 0; + while (true) { + Tracer tracer = openTelemetry.getTracer("demo"); + Span span = tracer.spanBuilder("exampleSpan" + ++count).startSpan(); + try (Scope scope = span.makeCurrent()) { + System.out.println("Inside a span..."); + TimeUnit.SECONDS.sleep(2); + } + span.end(); + } } } ``` -Alternatively, you can call `ZPageServer.registerAllPagesToHttpServer(HttpServer server)` to -register the zPages to a shared server: +Note that `startHttpServerAndRegisterAllPages()` will create a new `HttpServer` and register the zPages +with it. If you already have an existing or shared `HttpServer`, you can instead call +`registerAllPagesToHttpServer(HttpServer server)`: ```java public class MyMainClass { @@ -140,7 +147,7 @@ public class MyMainClass { // Start zPages server HttpServer server = HttpServer.create(new InetSocketAddress(8000), 10); - ZPageServer.registerAllPagesToHttpServer(server); + zPageServer.registerAllPagesToHttpServer(server); server.start(); // ... do work } diff --git a/sdk-extensions/incubator/src/main/java/io/opentelemetry/sdk/extension/incubator/trace/zpages/ZPageServer.java b/sdk-extensions/incubator/src/main/java/io/opentelemetry/sdk/extension/incubator/trace/zpages/ZPageServer.java index 74bb2f7b7e8..2688c0ad8b2 100644 --- a/sdk-extensions/incubator/src/main/java/io/opentelemetry/sdk/extension/incubator/trace/zpages/ZPageServer.java +++ b/sdk-extensions/incubator/src/main/java/io/opentelemetry/sdk/extension/incubator/trace/zpages/ZPageServer.java @@ -7,6 +7,8 @@ import com.sun.net.httpserver.HttpServer; import io.opentelemetry.api.internal.GuardedBy; +import io.opentelemetry.sdk.trace.SdkTracerProvider; +import io.opentelemetry.sdk.trace.SdkTracerProviderBuilder; import io.opentelemetry.sdk.trace.SpanLimits; import io.opentelemetry.sdk.trace.SpanProcessor; import io.opentelemetry.sdk.trace.samplers.Sampler; @@ -74,42 +76,46 @@ public final class ZPageServer { // Length of time to wait for the HttpServer to stop private static final int HTTPSERVER_STOP_DELAY = 1; // Tracez SpanProcessor and DataAggregator for constructing TracezZPageHandler - private static final TracezSpanProcessor tracezSpanProcessor = - TracezSpanProcessor.builder().build(); - private static final TracezTraceConfigSupplier tracezTraceConfigSupplier = + private final TracezSpanProcessor tracezSpanProcessor = TracezSpanProcessor.builder().build(); + private final TracezTraceConfigSupplier tracezTraceConfigSupplier = new TracezTraceConfigSupplier(); - private static final TracezDataAggregator tracezDataAggregator = + private final TracezDataAggregator tracezDataAggregator = new TracezDataAggregator(tracezSpanProcessor); // Handler for /tracez page - private static final ZPageHandler tracezZPageHandler = - new TracezZPageHandler(tracezDataAggregator); + private final ZPageHandler tracezZPageHandler = new TracezZPageHandler(tracezDataAggregator); // Handler for /traceconfigz page - private static final ZPageHandler traceConfigzZPageHandler = + private final ZPageHandler traceConfigzZPageHandler = new TraceConfigzZPageHandler(tracezTraceConfigSupplier); // Handler for index page, **please include all available ZPageHandlers in the constructor** - private static final ZPageHandler indexZPageHandler = + private final ZPageHandler indexZPageHandler = new IndexZPageHandler(Arrays.asList(tracezZPageHandler, traceConfigzZPageHandler)); - private static final Object mutex = new Object(); + private final Object mutex = new Object(); @GuardedBy("mutex") @Nullable - private static HttpServer server; + private HttpServer server; + + private ZPageServer() {} + + public static ZPageServer create() { + return new ZPageServer(); + } /** Returns a supplier of {@link SpanLimits} which can be reconfigured using zpages. */ - public static Supplier getTracezTraceConfigSupplier() { + public Supplier getTracezTraceConfigSupplier() { return tracezTraceConfigSupplier; } /** Returns a {@link Sampler} which can be reconfigured using zpages. */ - public static Sampler getTracezSampler() { + public Sampler getTracezSampler() { return tracezTraceConfigSupplier; } /** * Returns a {@link SpanProcessor} which will allow processing of spans by {@link ZPageServer}. */ - public static SpanProcessor getSpanProcessor() { + public SpanProcessor getSpanProcessor() { return tracezSpanProcessor; } @@ -119,7 +125,7 @@ public static SpanProcessor getSpanProcessor() { * * @param server the {@link HttpServer} for the page to register to. */ - static void registerIndexZPageHandler(HttpServer server) { + private void registerIndexZPageHandler(HttpServer server) { server.createContext(indexZPageHandler.getUrlPath(), new ZPageHttpHandler(indexZPageHandler)); } @@ -138,7 +144,7 @@ static void registerIndexZPageHandler(HttpServer server) { * * @param server the {@link HttpServer} for the page to register to. */ - static void registerTracezZPageHandler(HttpServer server) { + private void registerTracezZPageHandler(HttpServer server) { server.createContext(tracezZPageHandler.getUrlPath(), new ZPageHttpHandler(tracezZPageHandler)); } @@ -154,7 +160,7 @@ static void registerTracezZPageHandler(HttpServer server) { * * @param server the {@link HttpServer} for the page to register to. */ - static void registerTraceConfigzZPageHandler(HttpServer server) { + private void registerTraceConfigzZPageHandler(HttpServer server) { server.createContext( traceConfigzZPageHandler.getUrlPath(), new ZPageHttpHandler(traceConfigzZPageHandler)); } @@ -164,7 +170,7 @@ static void registerTraceConfigzZPageHandler(HttpServer server) { * * @param server the {@link HttpServer} for the page to register to. */ - public static void registerAllPagesToHttpServer(HttpServer server) { + public void registerAllPagesToHttpServer(HttpServer server) { // For future zPages, register them to the server in here registerIndexZPageHandler(server); registerTracezZPageHandler(server); @@ -173,7 +179,7 @@ public static void registerAllPagesToHttpServer(HttpServer server) { } /** Method for stopping the {@link HttpServer} {@code server}. */ - private static void stop() { + private void stop() { synchronized (mutex) { if (server == null) { return; @@ -183,6 +189,30 @@ private static void stop() { } } + /** + * Convenience method to return a new SdkTracerProvider that has been configured with our ZPage + * specific span processor, sampler, and limits. + * + * @return new SdkTracerProvider + */ + public SdkTracerProvider buildSdkTracerProvider() { + return buildSdkTracerProvider(SdkTracerProvider.builder()); + } + + /** + * Convenience method to return a new SdkTracerProvider that has been configured with our ZPage + * specific span processor, sampler, and limits. + * + * @return new SdkTracerProvider + */ + public SdkTracerProvider buildSdkTracerProvider(SdkTracerProviderBuilder builder) { + return builder + .addSpanProcessor(getSpanProcessor()) + .setSpanLimits(getTracezTraceConfigSupplier()) + .setSampler(getTracezSampler()) + .build(); + } + /** * Starts a private {@link HttpServer} and registers all zPages to it. When the JVM shuts down the * server is stopped. @@ -193,13 +223,13 @@ private static void stop() { * @throws IllegalStateException if the server is already started. * @throws IOException if the server cannot bind to the specified port. */ - public static void startHttpServerAndRegisterAllPages(int port) throws IOException { + public void startHttpServerAndRegisterAllPages(int port) throws IOException { synchronized (mutex) { if (server != null) { throw new IllegalStateException("The HttpServer is already started."); } server = HttpServer.create(new InetSocketAddress(port), HTTPSERVER_BACKLOG); - ZPageServer.registerAllPagesToHttpServer(server); + registerAllPagesToHttpServer(server); server.start(); } @@ -208,10 +238,8 @@ public static void startHttpServerAndRegisterAllPages(int port) throws IOExcepti new Thread() { @Override public void run() { - ZPageServer.stop(); + ZPageServer.this.stop(); } }); } - - private ZPageServer() {} } diff --git a/sdk-extensions/incubator/src/test/java/io/opentelemetry/sdk/extension/incubator/trace/zpages/ZPageServerTest.java b/sdk-extensions/incubator/src/test/java/io/opentelemetry/sdk/extension/incubator/trace/zpages/ZPageServerTest.java index 2ba0e7726bd..a2e1a2c659f 100644 --- a/sdk-extensions/incubator/src/test/java/io/opentelemetry/sdk/extension/incubator/trace/zpages/ZPageServerTest.java +++ b/sdk-extensions/incubator/src/test/java/io/opentelemetry/sdk/extension/incubator/trace/zpages/ZPageServerTest.java @@ -7,23 +7,38 @@ import static org.assertj.core.api.Assertions.assertThat; +import io.opentelemetry.sdk.trace.SdkTracerProvider; +import io.opentelemetry.sdk.trace.SpanLimits; import org.junit.jupiter.api.Test; class ZPageServerTest { @Test void spanProcessor() { - assertThat(ZPageServer.getSpanProcessor()).isInstanceOf(TracezSpanProcessor.class); + ZPageServer server = ZPageServer.create(); + assertThat(server.getSpanProcessor()).isInstanceOf(TracezSpanProcessor.class); } @Test void traceConfigSupplier() { - assertThat(ZPageServer.getTracezTraceConfigSupplier()) - .isInstanceOf(TracezTraceConfigSupplier.class); + ZPageServer server = ZPageServer.create(); + assertThat(server.getTracezTraceConfigSupplier()).isInstanceOf(TracezTraceConfigSupplier.class); } @Test void testSampler() { - assertThat(ZPageServer.getTracezSampler()).isInstanceOf(TracezTraceConfigSupplier.class); + ZPageServer server = ZPageServer.create(); + assertThat(server.getTracezSampler()).isInstanceOf(TracezTraceConfigSupplier.class); + } + + @Test + void buildTracerProvider() { + ZPageServer server = ZPageServer.create(); + SpanLimits expectedLimits = server.getTracezTraceConfigSupplier().get(); + + try (SdkTracerProvider provider = server.buildSdkTracerProvider()) { + assertThat(provider.getSpanLimits()).isEqualTo(expectedLimits); + assertThat(provider.getSampler()).isSameAs(server.getTracezSampler()); + } } } From ea7883be202c15cf4c0de5a766b1ce65fa3bc3a9 Mon Sep 17 00:00:00 2001 From: John Watson Date: Sat, 12 Nov 2022 15:06:49 -0800 Subject: [PATCH 28/68] Update semantic and resource attributes for spec v0.15.0 (#4938) * Update semantic and resource attributes for spec v0.15.0 * explicitly exclude resource attributes * remove more resources, include deprecated tags and attributes --- buildscripts/semantic-convention/generate.sh | 6 +- .../templates/SemanticAttributes.java.j2 | 14 +- .../attributes/ResourceAttributes.java | 42 +++- .../trace/attributes/SemanticAttributes.java | 182 ++++++++++++++---- 4 files changed, 194 insertions(+), 50 deletions(-) diff --git a/buildscripts/semantic-convention/generate.sh b/buildscripts/semantic-convention/generate.sh index ee0a0ef4cf7..f94645157d8 100755 --- a/buildscripts/semantic-convention/generate.sh +++ b/buildscripts/semantic-convention/generate.sh @@ -4,7 +4,7 @@ SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" ROOT_DIR="${SCRIPT_DIR}/../../" # freeze the spec & generator tools versions to make SemanticAttributes generation reproducible -SEMCONV_VERSION=1.13.0 +SEMCONV_VERSION=1.15.0 SPEC_VERSION=v$SEMCONV_VERSION SCHEMA_URL=https://opentelemetry.io/schemas/$SEMCONV_VERSION GENERATOR_VERSION=0.14.0 @@ -22,13 +22,15 @@ git reset --hard FETCH_HEAD cd ${SCRIPT_DIR} docker run --rm \ - -v ${SCRIPT_DIR}/opentelemetry-specification/semantic_conventions/trace:/source \ + -v ${SCRIPT_DIR}/opentelemetry-specification/semantic_conventions:/source \ -v ${SCRIPT_DIR}/templates:/templates \ -v ${ROOT_DIR}/semconv/src/main/java/io/opentelemetry/semconv/trace/attributes/:/output \ otel/semconvgen:$GENERATOR_VERSION \ + --exclude resource/** \ -f /source code \ --template /templates/SemanticAttributes.java.j2 \ --output /output/SemanticAttributes.java \ + -Dsemconv=trace \ -Dclass=SemanticAttributes \ -DschemaUrl=$SCHEMA_URL \ -Dpkg=io.opentelemetry.semconv.trace.attributes diff --git a/buildscripts/semantic-convention/templates/SemanticAttributes.java.j2 b/buildscripts/semantic-convention/templates/SemanticAttributes.java.j2 index e0c5135515f..d7a7c99e66e 100644 --- a/buildscripts/semantic-convention/templates/SemanticAttributes.java.j2 +++ b/buildscripts/semantic-convention/templates/SemanticAttributes.java.j2 @@ -56,6 +56,7 @@ import io.opentelemetry.api.common.AttributeKey; import java.util.List; // DO NOT EDIT, this is an Auto-generated file from buildscripts/semantic-convention{{template}} +@SuppressWarnings("unused") public final class {{class}} { /** * The URL of the OpenTelemetry schema for these keys and values. @@ -70,12 +71,12 @@ public final class {{class}} { *

Notes:

    {{attribute.note | render_markdown(code="{{@code {0}}}", paragraph="
  • {0}
  • ", list="{0}")}}
{%- endif %} - {%- if attribute.deprecated %} + {%- if (attribute.stability | string()) == "StabilityLevel.DEPRECATED" %} * - * @deprecated {{attribute.deprecated | to_doc_brief}}. + * @deprecated {{attribute.brief | to_doc_brief}}. {%- endif %} */ - {%- if attribute.deprecated %} + {%- if (attribute.stability | string()) == "StabilityLevel.DEPRECATED" %} @Deprecated {%- endif %} public static final AttributeKey<{{upFirst(to_java_return_type(attribute.attr_type | string))}}> {{attribute.fqn | to_const_name}} = {{to_java_key_type(attribute.attr_type | string)}}("{{attribute.fqn}}"); @@ -177,6 +178,13 @@ public final class {{class}} { @Deprecated public static final AttributeKey NET_HOST_IP = stringKey("net.host.ip"); + /** + * The ordinal number of request re-sending attempt. + * @deprecated This item has been removed as of 1.15.0 of the semantic conventions. Use {@link SemanticAttributes#HTTP_RESEND_COUNT} instead. + */ + @Deprecated + public static final AttributeKey HTTP_RETRY_COUNT = longKey("http.retry_count"); + {% endif %} private {{class}}() {} diff --git a/semconv/src/main/java/io/opentelemetry/semconv/resource/attributes/ResourceAttributes.java b/semconv/src/main/java/io/opentelemetry/semconv/resource/attributes/ResourceAttributes.java index 03c5d2263f0..651af884035 100644 --- a/semconv/src/main/java/io/opentelemetry/semconv/resource/attributes/ResourceAttributes.java +++ b/semconv/src/main/java/io/opentelemetry/semconv/resource/attributes/ResourceAttributes.java @@ -5,6 +5,7 @@ package io.opentelemetry.semconv.resource.attributes; +import static io.opentelemetry.api.common.AttributeKey.booleanKey; import static io.opentelemetry.api.common.AttributeKey.longKey; import static io.opentelemetry.api.common.AttributeKey.stringArrayKey; import static io.opentelemetry.api.common.AttributeKey.stringKey; @@ -14,9 +15,10 @@ // DO NOT EDIT, this is an Auto-generated file from // buildscripts/semantic-convention/templates/SemanticAttributes.java.j2 +@SuppressWarnings("unused") public final class ResourceAttributes { /** The URL of the OpenTelemetry schema for these keys and values. */ - public static final String SCHEMA_URL = "https://opentelemetry.io/schemas/1.13.0"; + public static final String SCHEMA_URL = "https://opentelemetry.io/schemas/1.15.0"; /** * Array of brand name and version separated by a space @@ -25,8 +27,8 @@ public final class ResourceAttributes { * *
    *
  • This value is intended to be taken from the UA client hints API - * (navigator.userAgentData.brands). + * href="https://wicg.github.io/ua-client-hints/#interface">UA client hints API ({@code + * navigator.userAgentData.brands}). *
*/ public static final AttributeKey> BROWSER_BRANDS = stringArrayKey("browser.brands"); @@ -38,19 +40,32 @@ public final class ResourceAttributes { * *
    *
  • This value is intended to be taken from the UA client hints API - * (navigator.userAgentData.platform). If unavailable, the legacy {@code navigator.platform} + * href="https://wicg.github.io/ua-client-hints/#interface">UA client hints API ({@code + * navigator.userAgentData.platform}). If unavailable, the legacy {@code navigator.platform} * API SHOULD NOT be used instead and this attribute SHOULD be left unset in order for the * values to be consistent. The list of possible values is defined in the W3C User-Agent Client * Hints specification. Note that some (but not all) of these values can overlap with - * values in the os.type and os.name attributes. However, for - * consistency, the values in the {@code browser.platform} attribute should capture the - * exact value that the user agent provides. + * values in the {@code os.type} and {@code os.name} attributes. + * However, for consistency, the values in the {@code browser.platform} attribute should + * capture the exact value that the user agent provides. *
*/ public static final AttributeKey BROWSER_PLATFORM = stringKey("browser.platform"); + /** + * A boolean that is true if the browser is running on a mobile device + * + *

Notes: + * + *

    + *
  • This value is intended to be taken from the UA client hints API ({@code + * navigator.userAgentData.mobile}). If unavailable, this attribute SHOULD be left unset. + *
+ */ + public static final AttributeKey BROWSER_MOBILE = booleanKey("browser.mobile"); + /** * Full user-agent string provided by the browser * @@ -64,6 +79,17 @@ public final class ResourceAttributes { */ public static final AttributeKey BROWSER_USER_AGENT = stringKey("browser.user_agent"); + /** + * Preferred language of the user using the browser + * + *

Notes: + * + *

    + *
  • This value is intended to be taken from the Navigator API {@code navigator.language}. + *
+ */ + public static final AttributeKey BROWSER_LANGUAGE = stringKey("browser.language"); + /** Name of the cloud provider. */ public static final AttributeKey CLOUD_PROVIDER = stringKey("cloud.provider"); diff --git a/semconv/src/main/java/io/opentelemetry/semconv/trace/attributes/SemanticAttributes.java b/semconv/src/main/java/io/opentelemetry/semconv/trace/attributes/SemanticAttributes.java index d3287d37091..c74f98bd9fa 100644 --- a/semconv/src/main/java/io/opentelemetry/semconv/trace/attributes/SemanticAttributes.java +++ b/semconv/src/main/java/io/opentelemetry/semconv/trace/attributes/SemanticAttributes.java @@ -16,9 +16,64 @@ // DO NOT EDIT, this is an Auto-generated file from // buildscripts/semantic-convention/templates/SemanticAttributes.java.j2 +@SuppressWarnings("unused") public final class SemanticAttributes { /** The URL of the OpenTelemetry schema for these keys and values. */ - public static final String SCHEMA_URL = "https://opentelemetry.io/schemas/1.13.0"; + public static final String SCHEMA_URL = "https://opentelemetry.io/schemas/1.15.0"; + + /** + * The type of the exception (its fully-qualified class name, if applicable). The dynamic type of + * the exception should be preferred over the static type in languages that support it. + */ + public static final AttributeKey EXCEPTION_TYPE = stringKey("exception.type"); + + /** The exception message. */ + public static final AttributeKey EXCEPTION_MESSAGE = stringKey("exception.message"); + + /** + * A stacktrace as a string in the natural representation for the language runtime. The + * representation is to be determined and documented by each language SIG. + */ + public static final AttributeKey EXCEPTION_STACKTRACE = stringKey("exception.stacktrace"); + + /** The name identifies the event. */ + public static final AttributeKey EVENT_NAME = stringKey("event.name"); + + /** + * The domain identifies the context in which an event happened. An event name is unique only + * within a domain. + * + *

Notes: + * + *

    + *
  • An {@code event.name} is supposed to be unique only in the context of an {@code + * event.domain}, so this allows for two events in different domains to have same {@code + * event.name}, yet be unrelated events. + *
+ */ + public static final AttributeKey EVENT_DOMAIN = stringKey("event.domain"); + + /** The name of the instrumentation scope - ({@code InstrumentationScope.Name} in OTLP). */ + public static final AttributeKey OTEL_SCOPE_NAME = stringKey("otel.scope.name"); + + /** The version of the instrumentation scope - ({@code InstrumentationScope.Version} in OTLP). */ + public static final AttributeKey OTEL_SCOPE_VERSION = stringKey("otel.scope.version"); + + /** + * Deprecated, use the {@code otel.scope.name} attribute. + * + * @deprecated Deprecated, use the `otel.scope.name` attribute. + */ + @Deprecated + public static final AttributeKey OTEL_LIBRARY_NAME = stringKey("otel.library.name"); + + /** + * Deprecated, use the {@code otel.scope.version} attribute. + * + * @deprecated Deprecated, use the `otel.scope.version` attribute. + */ + @Deprecated + public static final AttributeKey OTEL_LIBRARY_VERSION = stringKey("otel.library.version"); /** * The full invoked ARN as provided on the {@code Context} passed to the function ({@code @@ -237,42 +292,14 @@ public final class SemanticAttributes { public static final AttributeKey DB_SQL_TABLE = stringKey("db.sql.table"); /** - * The type of the exception (its fully-qualified class name, if applicable). The dynamic type of - * the exception should be preferred over the static type in languages that support it. + * Name of the code, either "OK" or "ERROR". MUST NOT be set if the status + * code is UNSET. */ - public static final AttributeKey EXCEPTION_TYPE = stringKey("exception.type"); - - /** The exception message. */ - public static final AttributeKey EXCEPTION_MESSAGE = stringKey("exception.message"); + public static final AttributeKey OTEL_STATUS_CODE = stringKey("otel.status_code"); - /** - * A stacktrace as a string in the natural representation for the language runtime. The - * representation is to be determined and documented by each language SIG. - */ - public static final AttributeKey EXCEPTION_STACKTRACE = stringKey("exception.stacktrace"); - - /** - * SHOULD be set to true if the exception event is recorded at a point where it is known that the - * exception is escaping the scope of the span. - * - *

Notes: - * - *

    - *
  • An exception is considered to have escaped (or left) the scope of a span, if that span is - * ended while the exception is still logically "in flight". This may be actually - * "in flight" in some languages (e.g. if the exception is passed to a Context - * manager's {@code __exit__} method in Python) but will usually be caught at the point of - * recording the exception in most languages. - *
  • It is usually not possible to determine at the point where an exception is thrown whether - * it will escape the scope of a span. However, it is trivial to know that an exception will - * escape, if one checks for an active exception just before ending the span, as done in the - * example above. - *
  • It follows that an exception may still escape the scope of the span even if the {@code - * exception.escaped} attribute was not set or set to false, since the event might have been - * recorded at a time where it was not clear whether the exception will escape. - *
- */ - public static final AttributeKey EXCEPTION_ESCAPED = booleanKey("exception.escaped"); + /** Description of the Status if it has a value, otherwise not set. */ + public static final AttributeKey OTEL_STATUS_DESCRIPTION = + stringKey("otel.status_description"); /** * Type of the trigger which caused this function execution. @@ -579,8 +606,18 @@ public final class SemanticAttributes { */ public static final AttributeKey HTTP_URL = stringKey("http.url"); - /** The ordinal number of request re-sending attempt. */ - public static final AttributeKey HTTP_RETRY_COUNT = longKey("http.retry_count"); + /** + * The ordinal number of request resending attempt (for any reason, including redirects). + * + *

Notes: + * + *

    + *
  • The resend count SHOULD be updated each time an HTTP request gets resent by the client, + * regardless of what was the cause of the resending (e.g. redirection, authorization + * failure, 503 Server Unavailable, network issues, or any other). + *
+ */ + public static final AttributeKey HTTP_RESEND_COUNT = longKey("http.resend_count"); /** The URI scheme identifying the used protocol. */ public static final AttributeKey HTTP_SCHEME = stringKey("http.scheme"); @@ -849,6 +886,23 @@ public final class SemanticAttributes { public static final AttributeKey MESSAGING_ROCKETMQ_CLIENT_ID = stringKey("messaging.rocketmq.client_id"); + /** + * The timestamp in milliseconds that the delay message is expected to be delivered to consumer. + */ + public static final AttributeKey MESSAGING_ROCKETMQ_DELIVERY_TIMESTAMP = + longKey("messaging.rocketmq.delivery_timestamp"); + + /** The delay time level for delay message, which determines the message delay time. */ + public static final AttributeKey MESSAGING_ROCKETMQ_DELAY_TIME_LEVEL = + longKey("messaging.rocketmq.delay_time_level"); + + /** + * It is essential for FIFO message. Messages that belong to the same message group are always + * processed one by one within the same consumer group. + */ + public static final AttributeKey MESSAGING_ROCKETMQ_MESSAGE_GROUP = + stringKey("messaging.rocketmq.message_group"); + /** Type of message. */ public static final AttributeKey MESSAGING_ROCKETMQ_MESSAGE_TYPE = stringKey("messaging.rocketmq.message_type"); @@ -949,7 +1003,41 @@ public final class SemanticAttributes { public static final AttributeKey MESSAGE_UNCOMPRESSED_SIZE = longKey("message.uncompressed_size"); + /** + * SHOULD be set to true if the exception event is recorded at a point where it is known that the + * exception is escaping the scope of the span. + * + *

Notes: + * + *

    + *
  • An exception is considered to have escaped (or left) the scope of a span, if that span is + * ended while the exception is still logically "in flight". This may be actually + * "in flight" in some languages (e.g. if the exception is passed to a Context + * manager's {@code __exit__} method in Python) but will usually be caught at the point of + * recording the exception in most languages. + *
  • It is usually not possible to determine at the point where an exception is thrown whether + * it will escape the scope of a span. However, it is trivial to know that an exception will + * escape, if one checks for an active exception just before ending the span, as done in the + * example above. + *
  • It follows that an exception may still escape the scope of the span even if the {@code + * exception.escaped} attribute was not set or set to false, since the event might have been + * recorded at a time where it was not clear whether the exception will escape. + *
+ */ + public static final AttributeKey EXCEPTION_ESCAPED = booleanKey("exception.escaped"); + // Enum definitions + public static final class EventDomainValues { + /** Events from browser apps. */ + public static final String BROWSER = "browser"; + /** Events from mobile apps. */ + public static final String DEVICE = "device"; + /** Events from Kubernetes. */ + public static final String K8S = "k8s"; + + private EventDomainValues() {} + } + public static final class OpentracingRefTypeValues { /** The parent Span depends on the child Span in some capacity. */ public static final String CHILD_OF = "child_of"; @@ -1087,6 +1175,18 @@ public static final class DbCassandraConsistencyLevelValues { private DbCassandraConsistencyLevelValues() {} } + public static final class OtelStatusCodeValues { + /** + * The operation has been validated by an Application developer or Operator to have completed + * successfully. + */ + public static final String OK = "OK"; + /** The operation contains an error. */ + public static final String ERROR = "ERROR"; + + private OtelStatusCodeValues() {} + } + public static final class FaasTriggerValues { /** A response to some data source operation such as a database or filesystem read/write. */ public static final String DATASOURCE = "datasource"; @@ -1425,5 +1525,13 @@ private MessageTypeValues() {} */ @Deprecated public static final AttributeKey NET_HOST_IP = stringKey("net.host.ip"); + /** + * The ordinal number of request re-sending attempt. + * + * @deprecated This item has been removed as of 1.15.0 of the semantic conventions. Use {@link + * SemanticAttributes#HTTP_RESEND_COUNT} instead. + */ + @Deprecated public static final AttributeKey HTTP_RETRY_COUNT = longKey("http.retry_count"); + private SemanticAttributes() {} } From fa3d29287925f06f614e109e7289f066bbfaf59b Mon Sep 17 00:00:00 2001 From: jack-berg <34418638+jack-berg@users.noreply.github.com> Date: Sun, 13 Nov 2022 08:53:42 -0600 Subject: [PATCH 29/68] Fix misleading javadoc (#4946) --- .../opentelemetry/sdk/testing/assertj/SummaryPointAssert.java | 2 +- .../sdk/testing/assertj/ValueAtQuantileAssert.java | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/sdk/testing/src/main/java/io/opentelemetry/sdk/testing/assertj/SummaryPointAssert.java b/sdk/testing/src/main/java/io/opentelemetry/sdk/testing/assertj/SummaryPointAssert.java index a5dbcb10eef..c948d17af13 100644 --- a/sdk/testing/src/main/java/io/opentelemetry/sdk/testing/assertj/SummaryPointAssert.java +++ b/sdk/testing/src/main/java/io/opentelemetry/sdk/testing/assertj/SummaryPointAssert.java @@ -13,7 +13,7 @@ import org.assertj.core.api.Assertions; /** - * Test assertions for (deprecated) {@link SummaryPointData}. + * Test assertions for {@link SummaryPointData}. * * @since 1.14.0 */ diff --git a/sdk/testing/src/main/java/io/opentelemetry/sdk/testing/assertj/ValueAtQuantileAssert.java b/sdk/testing/src/main/java/io/opentelemetry/sdk/testing/assertj/ValueAtQuantileAssert.java index 0c5ab61a0c1..162fec94bd6 100644 --- a/sdk/testing/src/main/java/io/opentelemetry/sdk/testing/assertj/ValueAtQuantileAssert.java +++ b/sdk/testing/src/main/java/io/opentelemetry/sdk/testing/assertj/ValueAtQuantileAssert.java @@ -10,7 +10,7 @@ import org.assertj.core.api.Assertions; /** - * Test assertions for (deprecated) {@link ValueAtQuantile}. + * Test assertions for {@link ValueAtQuantile}. * * @since 1.14.0 */ From ab1064e80bdcc9d9b12772538be06cb976ee1854 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 14 Nov 2022 10:13:32 -0600 Subject: [PATCH 30/68] Bump com.github.ben-manes.versions from 0.43.0 to 0.44.0 (#4947) Bumps com.github.ben-manes.versions from 0.43.0 to 0.44.0. --- updated-dependencies: - dependency-name: com.github.ben-manes.versions dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> --- settings.gradle.kts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/settings.gradle.kts b/settings.gradle.kts index 8f1df84b63a..bdbc66e3bd4 100644 --- a/settings.gradle.kts +++ b/settings.gradle.kts @@ -1,6 +1,6 @@ pluginManagement { plugins { - id("com.github.ben-manes.versions") version "0.43.0" + id("com.github.ben-manes.versions") version "0.44.0" id("com.github.johnrengelman.shadow") version "7.1.2" id("com.gradle.enterprise") version "3.11.4" id("io.github.gradle-nexus.publish-plugin") version "1.1.0" From ef4150ce3731d1bc0a899b712b68e0fec96feb84 Mon Sep 17 00:00:00 2001 From: Carlos Alberto Cortez Date: Mon, 14 Nov 2022 17:14:13 +0100 Subject: [PATCH 31/68] OpenTracing Shim: Handle unsupported types when setting Attributes. (#4939) * OpenTracing Shim: Handle unsupported types when setting Attributes. This happens through: * SpanBuilder.withTag() * Span.setTag() * Simplify BigInteger conversion assertions. --- .../opentracingshim/SpanBuilderShim.java | 5 +++-- .../opentelemetry/opentracingshim/SpanShim.java | 4 ++-- .../opentracingshim/SpanBuilderShimTest.java | 15 +++++++++++++++ .../opentracingshim/SpanShimTest.java | 11 +++++++++++ 4 files changed, 31 insertions(+), 4 deletions(-) diff --git a/opentracing-shim/src/main/java/io/opentelemetry/opentracingshim/SpanBuilderShim.java b/opentracing-shim/src/main/java/io/opentelemetry/opentracingshim/SpanBuilderShim.java index 9c3f8db4946..ac3c1f62c17 100644 --- a/opentracing-shim/src/main/java/io/opentelemetry/opentracingshim/SpanBuilderShim.java +++ b/opentracing-shim/src/main/java/io/opentelemetry/opentracingshim/SpanBuilderShim.java @@ -164,7 +164,7 @@ public SpanBuilder withTag(String key, Number value) { if (value == null) { return this; } - // TODO - Verify only the 'basic' types are supported/used. + if (value instanceof Integer || value instanceof Long || value instanceof Short @@ -175,7 +175,8 @@ public SpanBuilder withTag(String key, Number value) { this.spanBuilderAttributeKeys.add(doubleKey(key)); this.spanBuilderAttributeValues.add(value.doubleValue()); } else { - throw new IllegalArgumentException("Number type not supported"); + this.spanBuilderAttributeKeys.add(stringKey(key)); + this.spanBuilderAttributeValues.add(value.toString()); } return this; 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 03449a979b4..10adf19adf5 100644 --- a/opentracing-shim/src/main/java/io/opentelemetry/opentracingshim/SpanShim.java +++ b/opentracing-shim/src/main/java/io/opentelemetry/opentracingshim/SpanShim.java @@ -112,7 +112,7 @@ public Span setTag(String key, Number value) { if (value == null) { return this; } - // TODO - Verify only the 'basic' types are supported/used. + if (value instanceof Integer || value instanceof Long || value instanceof Short @@ -121,7 +121,7 @@ public Span setTag(String key, Number value) { } else if (value instanceof Float || value instanceof Double) { span.setAttribute(key, value.doubleValue()); } else { - throw new IllegalArgumentException("Number type not supported"); + span.setAttribute(key, value.toString()); } return this; 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 05a412478c3..16ff9cfeb99 100644 --- a/opentracing-shim/src/test/java/io/opentelemetry/opentracingshim/SpanBuilderShimTest.java +++ b/opentracing-shim/src/test/java/io/opentelemetry/opentracingshim/SpanBuilderShimTest.java @@ -22,6 +22,7 @@ import io.opentelemetry.sdk.trace.samplers.SamplingResult; import io.opentelemetry.semconv.trace.attributes.SemanticAttributes; import io.opentracing.References; +import java.math.BigInteger; import java.util.List; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; @@ -296,6 +297,20 @@ void withStartTimestamp() { assertThat(spanData.getStartEpochNanos()).isEqualTo(micros * 1000L); } + @Test + void setAttribute_unrecognizedType() { + SpanShim span = + (SpanShim) + new SpanBuilderShim(telemetryInfo, SPAN_NAME).withTag("foo", BigInteger.TEN).start(); + try { + SpanData spanData = ((ReadableSpan) span.getSpan()).toSpanData(); + assertThat(spanData.getAttributes().size()).isEqualTo(1); + assertThat(spanData.getAttributes().get(AttributeKey.stringKey("foo"))).isEqualTo("10"); + } finally { + span.finish(); + } + } + @Test void setAttributes_beforeSpanStart() { SdkTracerProvider tracerSdkFactory = diff --git a/opentracing-shim/src/test/java/io/opentelemetry/opentracingshim/SpanShimTest.java b/opentracing-shim/src/test/java/io/opentelemetry/opentracingshim/SpanShimTest.java index 3ecf7418d97..1d304e04c32 100644 --- a/opentracing-shim/src/test/java/io/opentelemetry/opentracingshim/SpanShimTest.java +++ b/opentracing-shim/src/test/java/io/opentelemetry/opentracingshim/SpanShimTest.java @@ -17,6 +17,7 @@ import io.opentelemetry.sdk.trace.data.SpanData; import io.opentelemetry.semconv.trace.attributes.SemanticAttributes; import io.opentracing.log.Fields; +import java.math.BigInteger; import java.util.HashMap; import java.util.Map; import java.util.concurrent.ExecutorService; @@ -59,6 +60,16 @@ void context_simple() { assertThat(contextShim.baggageItems().iterator().hasNext()).isFalse(); } + @Test + void setAttribute_unrecognizedType() { + SpanShim spanShim = new SpanShim(telemetryInfo, span); + spanShim.setTag("foo", BigInteger.ONE); + + SpanData spanData = ((ReadableSpan) span).toSpanData(); + assertThat(spanData.getAttributes().size()).isEqualTo(1); + assertThat(spanData.getAttributes().get(AttributeKey.stringKey("foo"))).isEqualTo("1"); + } + @Test void baggage() { SpanShim spanShim = new SpanShim(telemetryInfo, span); From 2cca0fb96c566f741f76fe23713646a358fdedd5 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Tue, 15 Nov 2022 10:55:24 -0600 Subject: [PATCH 32/68] Bump junit-pioneer from 1.8.0 to 1.9.0 (#4952) Bumps [junit-pioneer](https://github.com/junit-pioneer/junit-pioneer) from 1.8.0 to 1.9.0. - [Release notes](https://github.com/junit-pioneer/junit-pioneer/releases) - [Commits](https://github.com/junit-pioneer/junit-pioneer/compare/v1.8.0...v1.9.0) --- updated-dependencies: - dependency-name: org.junit-pioneer:junit-pioneer dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> --- dependencyManagement/build.gradle.kts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/dependencyManagement/build.gradle.kts b/dependencyManagement/build.gradle.kts index 8f93bc51859..55716a43036 100644 --- a/dependencyManagement/build.gradle.kts +++ b/dependencyManagement/build.gradle.kts @@ -97,7 +97,7 @@ val DEPENDENCIES = listOf( "org.bouncycastle:bcpkix-jdk15on:1.70", "org.codehaus.mojo:animal-sniffer-annotations:1.22", "org.jctools:jctools-core:4.0.1", - "org.junit-pioneer:junit-pioneer:1.8.0", + "org.junit-pioneer:junit-pioneer:1.9.0", "org.skyscreamer:jsonassert:1.5.1", ) From bd8b5650ac5c80201ded9158b7c1dc288ea2aff7 Mon Sep 17 00:00:00 2001 From: jack-berg <34418638+jack-berg@users.noreply.github.com> Date: Tue, 15 Nov 2022 11:15:50 -0600 Subject: [PATCH 33/68] Fix concurrent modification exception in ComponentRegistry (#4951) * Fix concurrent modification exception in ComponentRegistry * Reduce number of threads and iterations --- .../sdk/internal/ComponentRegistry.java | 13 +++++- .../sdk/internal/ComponentRegistryTest.java | 40 +++++++++++++++++++ 2 files changed, 51 insertions(+), 2 deletions(-) diff --git a/sdk/common/src/main/java/io/opentelemetry/sdk/internal/ComponentRegistry.java b/sdk/common/src/main/java/io/opentelemetry/sdk/internal/ComponentRegistry.java index 93215cf2bf4..3d65a8c4945 100644 --- a/sdk/common/src/main/java/io/opentelemetry/sdk/internal/ComponentRegistry.java +++ b/sdk/common/src/main/java/io/opentelemetry/sdk/internal/ComponentRegistry.java @@ -6,7 +6,9 @@ package io.opentelemetry.sdk.internal; import io.opentelemetry.api.common.Attributes; +import io.opentelemetry.api.internal.GuardedBy; import io.opentelemetry.sdk.common.InstrumentationScopeInfo; +import java.util.ArrayList; import java.util.Collection; import java.util.Collections; import java.util.IdentityHashMap; @@ -44,6 +46,9 @@ public final class ComponentRegistry { private final Map>> componentByNameVersionAndSchema = new ConcurrentHashMap<>(); + private final Object lock = new Object(); + + @GuardedBy("lock") private final Set allComponents = Collections.newSetFromMap(new IdentityHashMap<>()); private final Function factory; @@ -109,7 +114,9 @@ public V get( private V buildComponent(InstrumentationScopeInfo instrumentationScopeInfo) { V component = factory.apply(instrumentationScopeInfo); - allComponents.add(component); + synchronized (lock) { + allComponents.add(component); + } return component; } @@ -119,6 +126,8 @@ private V buildComponent(InstrumentationScopeInfo instrumentationScopeInfo) { * @return a {@code Collection} view of the registered components. */ public Collection getComponents() { - return Collections.unmodifiableCollection(allComponents); + synchronized (lock) { + return Collections.unmodifiableCollection(new ArrayList<>(allComponents)); + } } } diff --git a/sdk/common/src/test/java/io/opentelemetry/sdk/internal/ComponentRegistryTest.java b/sdk/common/src/test/java/io/opentelemetry/sdk/internal/ComponentRegistryTest.java index 1e566b28972..e93f5588b76 100644 --- a/sdk/common/src/test/java/io/opentelemetry/sdk/internal/ComponentRegistryTest.java +++ b/sdk/common/src/test/java/io/opentelemetry/sdk/internal/ComponentRegistryTest.java @@ -5,9 +5,18 @@ package io.opentelemetry.sdk.internal; +import static java.util.stream.Collectors.joining; import static org.assertj.core.api.Assertions.assertThat; import io.opentelemetry.api.common.Attributes; +import java.util.ArrayList; +import java.util.List; +import java.util.Random; +import java.util.concurrent.ExecutionException; +import java.util.concurrent.ExecutorService; +import java.util.concurrent.Executors; +import java.util.concurrent.Future; +import java.util.stream.IntStream; import org.junit.jupiter.api.Test; class ComponentRegistryTest { @@ -52,5 +61,36 @@ void get_DifferentInstance() { .isNotSameAs(registry.get(NAME, null, null, Attributes.empty())); } + @Test + @SuppressWarnings("ReturnValueIgnored") + void getComponents_HighConcurrency() throws ExecutionException, InterruptedException { + List> futures = new ArrayList<>(); + Random random = new Random(); + int concurrency = 2; + ExecutorService executor = Executors.newFixedThreadPool(concurrency); + + try { + for (int i = 0; i < 100; i++) { + futures.add( + executor.submit( + () -> { + String name = + IntStream.range(0, 20) + .mapToObj(unused -> String.valueOf((char) random.nextInt(26))) + .collect(joining()); + registry.get(name, null, null, Attributes.empty()); + })); + futures.add( + executor.submit(() -> registry.getComponents().forEach(TestComponent::hashCode))); + } + + for (Future future : futures) { + future.get(); + } + } finally { + executor.shutdown(); + } + } + private static final class TestComponent {} } From cc1d6ae78a155e9f4b756e9b30cac3d698bfa0bc Mon Sep 17 00:00:00 2001 From: jack-berg <34418638+jack-berg@users.noreply.github.com> Date: Tue, 15 Nov 2022 11:49:58 -0600 Subject: [PATCH 34/68] Disable jApiCmp diff check on release branches (#4955) --- .github/workflows/build.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index d8618cd1920..b4a68350718 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -60,6 +60,8 @@ jobs: -Porg.gradle.java.installations.paths=${{ steps.setup-java-test.outputs.path }},${{ steps.setup-java.outputs.path }} - name: Check for diff + # The jApiCmp diff compares current to latest, which isn't appropriate for release branches + if: ${{ !startsWith(github.ref_name, 'release/') }} run: | if git diff --quiet then From 6c7047e71a3755c28d047f9c01d2bc9dd5cbf128 Mon Sep 17 00:00:00 2001 From: jack-berg <34418638+jack-berg@users.noreply.github.com> Date: Tue, 15 Nov 2022 14:27:58 -0600 Subject: [PATCH 35/68] Disable japicmp when base_ref is release (#4957) --- .github/workflows/build.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index b4a68350718..548d92b10f0 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -61,7 +61,7 @@ jobs: - name: Check for diff # The jApiCmp diff compares current to latest, which isn't appropriate for release branches - if: ${{ !startsWith(github.ref_name, 'release/') }} + if: ${{ !startsWith(github.ref_name, 'release/') && !startsWith(github.base_ref, 'release/') }} run: | if git diff --quiet then From 59702a79a5b04df0822377b93cd62d741aa9bc5a Mon Sep 17 00:00:00 2001 From: jack-berg <34418638+jack-berg@users.noreply.github.com> Date: Tue, 15 Nov 2022 17:11:21 -0600 Subject: [PATCH 36/68] Post release 1.20.1 (#4960) * Update version in docs * Reset japicmp --- README.md | 74 +++++++++---------- .../1.20.1_vs_1.20.0/opentelemetry-api.txt | 2 + .../opentelemetry-context.txt | 2 + .../opentelemetry-exporter-common.txt | 2 + .../opentelemetry-exporter-jaeger-thrift.txt | 2 + .../opentelemetry-exporter-jaeger.txt | 2 + .../opentelemetry-exporter-logging-otlp.txt | 2 + .../opentelemetry-exporter-logging.txt | 2 + .../opentelemetry-exporter-otlp-common.txt | 2 + .../opentelemetry-exporter-otlp.txt | 2 + .../opentelemetry-exporter-zipkin.txt | 2 + .../opentelemetry-extension-aws.txt | 2 + .../opentelemetry-extension-kotlin.txt | 2 + ...ntelemetry-extension-trace-propagators.txt | 2 + .../opentelemetry-sdk-common.txt | 2 + ...emetry-sdk-extension-autoconfigure-spi.txt | 2 + ...ry-sdk-extension-jaeger-remote-sampler.txt | 2 + .../opentelemetry-sdk-metrics.txt | 2 + .../opentelemetry-sdk-testing.txt | 2 + .../opentelemetry-sdk-trace.txt | 2 + .../1.20.1_vs_1.20.0/opentelemetry-sdk.txt | 2 + 21 files changed, 77 insertions(+), 37 deletions(-) create mode 100644 docs/apidiffs/1.20.1_vs_1.20.0/opentelemetry-api.txt create mode 100644 docs/apidiffs/1.20.1_vs_1.20.0/opentelemetry-context.txt create mode 100644 docs/apidiffs/1.20.1_vs_1.20.0/opentelemetry-exporter-common.txt create mode 100644 docs/apidiffs/1.20.1_vs_1.20.0/opentelemetry-exporter-jaeger-thrift.txt create mode 100644 docs/apidiffs/1.20.1_vs_1.20.0/opentelemetry-exporter-jaeger.txt create mode 100644 docs/apidiffs/1.20.1_vs_1.20.0/opentelemetry-exporter-logging-otlp.txt create mode 100644 docs/apidiffs/1.20.1_vs_1.20.0/opentelemetry-exporter-logging.txt create mode 100644 docs/apidiffs/1.20.1_vs_1.20.0/opentelemetry-exporter-otlp-common.txt create mode 100644 docs/apidiffs/1.20.1_vs_1.20.0/opentelemetry-exporter-otlp.txt create mode 100644 docs/apidiffs/1.20.1_vs_1.20.0/opentelemetry-exporter-zipkin.txt create mode 100644 docs/apidiffs/1.20.1_vs_1.20.0/opentelemetry-extension-aws.txt create mode 100644 docs/apidiffs/1.20.1_vs_1.20.0/opentelemetry-extension-kotlin.txt create mode 100644 docs/apidiffs/1.20.1_vs_1.20.0/opentelemetry-extension-trace-propagators.txt create mode 100644 docs/apidiffs/1.20.1_vs_1.20.0/opentelemetry-sdk-common.txt create mode 100644 docs/apidiffs/1.20.1_vs_1.20.0/opentelemetry-sdk-extension-autoconfigure-spi.txt create mode 100644 docs/apidiffs/1.20.1_vs_1.20.0/opentelemetry-sdk-extension-jaeger-remote-sampler.txt create mode 100644 docs/apidiffs/1.20.1_vs_1.20.0/opentelemetry-sdk-metrics.txt create mode 100644 docs/apidiffs/1.20.1_vs_1.20.0/opentelemetry-sdk-testing.txt create mode 100644 docs/apidiffs/1.20.1_vs_1.20.0/opentelemetry-sdk-trace.txt create mode 100644 docs/apidiffs/1.20.1_vs_1.20.0/opentelemetry-sdk.txt diff --git a/README.md b/README.md index d99dccef173..c759f1d6981 100644 --- a/README.md +++ b/README.md @@ -91,7 +91,7 @@ dependency versions in sync. io.opentelemetry opentelemetry-bom - 1.20.0 + 1.20.1 pom import @@ -110,7 +110,7 @@ dependency versions in sync. ```groovy dependencies { - implementation platform("io.opentelemetry:opentelemetry-bom:1.20.0") + implementation platform("io.opentelemetry:opentelemetry-bom:1.20.1") implementation('io.opentelemetry:opentelemetry-api') } ``` @@ -119,8 +119,8 @@ Note that if you want to use any artifacts that have not fully stabilized yet (s ```groovy dependencies { - implementation platform("io.opentelemetry:opentelemetry-bom:1.20.0") - implementation platform('io.opentelemetry:opentelemetry-bom-alpha:1.20.0-alpha') + implementation platform("io.opentelemetry:opentelemetry-bom:1.20.1") + implementation platform('io.opentelemetry:opentelemetry-bom-alpha:1.20.1-alpha') implementation('io.opentelemetry:opentelemetry-api') implementation('io.opentelemetry:opentelemetry-semconv') @@ -216,69 +216,69 @@ dependency as follows, replacing `{{artifact-id}}` with the value from the "Arti | Component | Description | Artifact ID | Version | |----------------------------------------------|----------------------------------------|---------------------------|-------------------------------------------------------------| -| [Bill of Materials (BOM)](./bom) | Bill of materials for stable artifacts | `opentelemetry-bom` | 1.20.0 | -| [Alpha Bill of Materials (BOM)](./bom-alpha) | Bill of materials for alpha artifacts | `opentelemetry-bom-alpha` | 1.20.0-alpha | +| [Bill of Materials (BOM)](./bom) | Bill of materials for stable artifacts | `opentelemetry-bom` | 1.20.1 | +| [Alpha Bill of Materials (BOM)](./bom-alpha) | Bill of materials for alpha artifacts | `opentelemetry-bom-alpha` | 1.20.1-alpha | ### API | Component | Description | Artifact ID | Version | |-----------------------------------|----------------------------------------------------------------------------------------------------------------------------------------------------|--------------------------|-------------------------------------------------------------| -| [API](./api/all) | OpenTelemetry API, including metrics, traces, baggage, context | `opentelemetry-api` | 1.20.0 | -| [Logs API](./api/logs) | OpenTelemetry Log API for emitting events and bridging log frameworks (NOT a replacement for application logging frameworks like SLF4J, JUL, etc.) | `opentelemetry-api-logs` | 1.20.0-alpha | -| [Context API](./context) | OpenTelemetry context API | `opentelemetry-context` | 1.20.0 | -| [Semantic Conventions](./semconv) | Generated code for OpenTelemetry semantic conventions | `opentelemetry-semconv` | 1.20.0-alpha | +| [API](./api/all) | OpenTelemetry API, including metrics, traces, baggage, context | `opentelemetry-api` | 1.20.1 | +| [Logs API](./api/logs) | OpenTelemetry Log API for emitting events and bridging log frameworks (NOT a replacement for application logging frameworks like SLF4J, JUL, etc.) | `opentelemetry-api-logs` | 1.20.1-alpha | +| [Context API](./context) | OpenTelemetry context API | `opentelemetry-context` | 1.20.1 | +| [Semantic Conventions](./semconv) | Generated code for OpenTelemetry semantic conventions | `opentelemetry-semconv` | 1.20.1-alpha | ### API Extensions | Component | Description | Artifact ID | Version | |---------------------------------------------------------------|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|---------------------------------------------|-------------------------------------------------------------| -| [AWS Extension](./extensions/aws) | AWS Xray propagator (deprecated, moved to [opentelemetry-java-contrib/aws-xray-propagator](https://github.com/open-telemetry/opentelemetry-java-contrib/tree/main/aws-xray-propagator)) | `opentelemetry-extension-aws` | 1.20.0 | -| [Kotlin Extension](./extensions/kotlin) | Context extension for coroutines | `opentelemetry-extension-kotlin` | 1.20.0 | -| [Trace Propagators Extension](./extensions/trace-propagators) | Trace propagators, including B3, Jaeger, OT Trace | `opentelemetry-extension-trace-propagators` | 1.20.0 | -| [Incubator Extension](./extensions/incubator) | API incubator, including pass through propagator, and extended tracer | `opentelemetry-extension-incubator` | 1.20.0-alpha | +| [AWS Extension](./extensions/aws) | AWS Xray propagator (deprecated, moved to [opentelemetry-java-contrib/aws-xray-propagator](https://github.com/open-telemetry/opentelemetry-java-contrib/tree/main/aws-xray-propagator)) | `opentelemetry-extension-aws` | 1.20.1 | +| [Kotlin Extension](./extensions/kotlin) | Context extension for coroutines | `opentelemetry-extension-kotlin` | 1.20.1 | +| [Trace Propagators Extension](./extensions/trace-propagators) | Trace propagators, including B3, Jaeger, OT Trace | `opentelemetry-extension-trace-propagators` | 1.20.1 | +| [Incubator Extension](./extensions/incubator) | API incubator, including pass through propagator, and extended tracer | `opentelemetry-extension-incubator` | 1.20.1-alpha | ### SDK | Component | Description | Artifact ID | Version | |----------------------------------------|--------------------------------------------------------|----------------------------------|-------------------------------------------------------------| -| [SDK](./sdk/all) | OpenTelemetry SDK, including metrics, traces, and logs | `opentelemetry-sdk` | 1.20.0 | -| [Metrics SDK](./sdk/metrics) | OpenTelemetry metrics SDK | `opentelemetry-sdk-metrics` | 1.20.0 | -| [Trace SDK](./sdk/trace) | OpenTelemetry trace SDK | `opentelemetry-sdk-trace` | 1.20.0 | -| [Log SDK](./sdk/logs) | OpenTelemetry log SDK | `opentelemetry-sdk-logs` | 1.20.0-alpha | -| [SDK Common](./sdk/common) | Shared SDK components | `opentelemetry-sdk-common` | 1.20.0 | -| [SDK Testing](./sdk/testing) | Components for testing OpenTelemetry instrumentation | `opentelemetry-sdk-testing` | 1.20.0 | -| [SDK Logs Testing](./sdk/logs-testing) | Components for testing OpenTelemetry logs | `opentelemetry-sdk-logs-testing` | 1.20.0-alpha | +| [SDK](./sdk/all) | OpenTelemetry SDK, including metrics, traces, and logs | `opentelemetry-sdk` | 1.20.1 | +| [Metrics SDK](./sdk/metrics) | OpenTelemetry metrics SDK | `opentelemetry-sdk-metrics` | 1.20.1 | +| [Trace SDK](./sdk/trace) | OpenTelemetry trace SDK | `opentelemetry-sdk-trace` | 1.20.1 | +| [Log SDK](./sdk/logs) | OpenTelemetry log SDK | `opentelemetry-sdk-logs` | 1.20.1-alpha | +| [SDK Common](./sdk/common) | Shared SDK components | `opentelemetry-sdk-common` | 1.20.1 | +| [SDK Testing](./sdk/testing) | Components for testing OpenTelemetry instrumentation | `opentelemetry-sdk-testing` | 1.20.1 | +| [SDK Logs Testing](./sdk/logs-testing) | Components for testing OpenTelemetry logs | `opentelemetry-sdk-logs-testing` | 1.20.1-alpha | ### SDK Exporters | Component | Description | Artifact ID | Version | |-----------------------------------------------------|-------------------------------------------------------------------------------------|---------------------------------------|-------------------------------------------------------------| -| [OTLP Exporters](./exporters/otlp/all) | OTLP gRPC & HTTP exporters, including metrics and trace | `opentelemetry-exporter-otlp` | 1.20.0 | -| [OTLP Log Exporters](./exporters/otlp/logs) | OTLP gRPC & HTTP log exporters | `opentelemetry-exporter-otlp-logs` | 1.20.0-alpha | -| [OTLP Common](./exporters/otlp/common) | Shared OTLP components (internal) | `opentelemetry-exporter-otlp-common` | 1.20.0 | -| [Jaeger gRPC Exporter](./exporters/jaeger) | Jaeger gRPC trace exporter | `opentelemetry-exporter-jaeger` | 1.20.0 | -| [Jaeger Thrift Exporter](./exporters/jaeger-thrift) | Jaeger thrift trace exporter | `opentelemetry-exporter-jaeger-thift` | 1.20.0 | -| [Logging Exporter](./exporters/logging) | Logging exporters, includings metrics, traces, and logs | `opentelemetry-exporter-logging` | 1.20.0 | -| [OTLP Logging Exporter](./exporters/logging-otlp) | Logging exporters in OTLP protobuf JSON format, including metrics, traces, and logs | `opentelemetry-exporter-logging-otlp` | 1.20.0 | -| [Zipkin Exporter](./exporters/zipkin) | Zipkin trace exporter | `opentelemetry-exporter-zipkin` | 1.20.0 | -| [Prometheus Exporter](./exporters/prometheus) | Prometheus metric exporter | `opentelemetry-exporter-prometheus` | 1.20.0-alpha | -| [Exporter Common](./exporters/common) | Shared exporter components (internal) | `opentelemetry-exporter-common` | 1.20.0 | +| [OTLP Exporters](./exporters/otlp/all) | OTLP gRPC & HTTP exporters, including metrics and trace | `opentelemetry-exporter-otlp` | 1.20.1 | +| [OTLP Log Exporters](./exporters/otlp/logs) | OTLP gRPC & HTTP log exporters | `opentelemetry-exporter-otlp-logs` | 1.20.1-alpha | +| [OTLP Common](./exporters/otlp/common) | Shared OTLP components (internal) | `opentelemetry-exporter-otlp-common` | 1.20.1 | +| [Jaeger gRPC Exporter](./exporters/jaeger) | Jaeger gRPC trace exporter | `opentelemetry-exporter-jaeger` | 1.20.1 | +| [Jaeger Thrift Exporter](./exporters/jaeger-thrift) | Jaeger thrift trace exporter | `opentelemetry-exporter-jaeger-thift` | 1.20.1 | +| [Logging Exporter](./exporters/logging) | Logging exporters, includings metrics, traces, and logs | `opentelemetry-exporter-logging` | 1.20.1 | +| [OTLP Logging Exporter](./exporters/logging-otlp) | Logging exporters in OTLP protobuf JSON format, including metrics, traces, and logs | `opentelemetry-exporter-logging-otlp` | 1.20.1 | +| [Zipkin Exporter](./exporters/zipkin) | Zipkin trace exporter | `opentelemetry-exporter-zipkin` | 1.20.1 | +| [Prometheus Exporter](./exporters/prometheus) | Prometheus metric exporter | `opentelemetry-exporter-prometheus` | 1.20.1-alpha | +| [Exporter Common](./exporters/common) | Shared exporter components (internal) | `opentelemetry-exporter-common` | 1.20.1 | ### SDK Extensions | Component | Description | Artifact ID | Version | |-------------------------------------------------------------------------------|------------------------------------------------------------------------------------------------|-----------------------------------------------------|-------------------------------------------------------------| -| [SDK Autoconfigure Extension](./sdk-extensions/autoconfigure) | Autoconfigure OpenTelemetry SDK from env vars, system properties, and SPI | `opentelemetry-sdk-extension-autoconfigure` | 1.20.0-alpha | -| [SDK Autoconfigure SPI](./sdk-extensions/autoconfigure-spi) | Service Provider Interface (SPI) definitions for autoconfigure | `opentelemetry-sdk-extension-autoconfigure-spi` | 1.20.0 | -| [SDK Jaeger Remote Sampler Extension](./sdk-extensions/jaeger-remote-sampler) | Sampler which obtains sampling configuration from remote Jaeger server | `opentelemetry-sdk-extension-jaeger-remote-sampler` | 1.20.0 | -| [SDK Incubator](./sdk-extensions/incubator) | SDK incubator, including YAML based view configuration, LeakDetectingSpanProcessor, and zPages | `opentelemetry-sdk-extension-incubator` | 1.20.0-alpha | +| [SDK Autoconfigure Extension](./sdk-extensions/autoconfigure) | Autoconfigure OpenTelemetry SDK from env vars, system properties, and SPI | `opentelemetry-sdk-extension-autoconfigure` | 1.20.1-alpha | +| [SDK Autoconfigure SPI](./sdk-extensions/autoconfigure-spi) | Service Provider Interface (SPI) definitions for autoconfigure | `opentelemetry-sdk-extension-autoconfigure-spi` | 1.20.1 | +| [SDK Jaeger Remote Sampler Extension](./sdk-extensions/jaeger-remote-sampler) | Sampler which obtains sampling configuration from remote Jaeger server | `opentelemetry-sdk-extension-jaeger-remote-sampler` | 1.20.1 | +| [SDK Incubator](./sdk-extensions/incubator) | SDK incubator, including YAML based view configuration, LeakDetectingSpanProcessor, and zPages | `opentelemetry-sdk-extension-incubator` | 1.20.1-alpha | ### Shims | Component | Description | Artifact ID | Version | |----------------------------------------|--------------------------------------------------------------|----------------------------------|-------------------------------------------------------------| -| [OpenCensus Shim](./opencensus-shim) | Bridge opencensus metrics into the OpenTelemetry metrics SDK | `opentelemetry-opencensus-shim` | 1.20.0-alpha | -| [OpenTracing Shim](./opentracing-shim) | Bridge opentracing spans into the OpenTelemetry trace API | `opentelemetry-opentracing-shim` | 1.20.0-alpha | +| [OpenCensus Shim](./opencensus-shim) | Bridge opencensus metrics into the OpenTelemetry metrics SDK | `opentelemetry-opencensus-shim` | 1.20.1-alpha | +| [OpenTracing Shim](./opentracing-shim) | Bridge opentracing spans into the OpenTelemetry trace API | `opentelemetry-opentracing-shim` | 1.20.1-alpha | ## Contributing diff --git a/docs/apidiffs/1.20.1_vs_1.20.0/opentelemetry-api.txt b/docs/apidiffs/1.20.1_vs_1.20.0/opentelemetry-api.txt new file mode 100644 index 00000000000..df26146497b --- /dev/null +++ b/docs/apidiffs/1.20.1_vs_1.20.0/opentelemetry-api.txt @@ -0,0 +1,2 @@ +Comparing source compatibility of against +No changes. \ No newline at end of file diff --git a/docs/apidiffs/1.20.1_vs_1.20.0/opentelemetry-context.txt b/docs/apidiffs/1.20.1_vs_1.20.0/opentelemetry-context.txt new file mode 100644 index 00000000000..df26146497b --- /dev/null +++ b/docs/apidiffs/1.20.1_vs_1.20.0/opentelemetry-context.txt @@ -0,0 +1,2 @@ +Comparing source compatibility of against +No changes. \ No newline at end of file diff --git a/docs/apidiffs/1.20.1_vs_1.20.0/opentelemetry-exporter-common.txt b/docs/apidiffs/1.20.1_vs_1.20.0/opentelemetry-exporter-common.txt new file mode 100644 index 00000000000..df26146497b --- /dev/null +++ b/docs/apidiffs/1.20.1_vs_1.20.0/opentelemetry-exporter-common.txt @@ -0,0 +1,2 @@ +Comparing source compatibility of against +No changes. \ No newline at end of file diff --git a/docs/apidiffs/1.20.1_vs_1.20.0/opentelemetry-exporter-jaeger-thrift.txt b/docs/apidiffs/1.20.1_vs_1.20.0/opentelemetry-exporter-jaeger-thrift.txt new file mode 100644 index 00000000000..df26146497b --- /dev/null +++ b/docs/apidiffs/1.20.1_vs_1.20.0/opentelemetry-exporter-jaeger-thrift.txt @@ -0,0 +1,2 @@ +Comparing source compatibility of against +No changes. \ No newline at end of file diff --git a/docs/apidiffs/1.20.1_vs_1.20.0/opentelemetry-exporter-jaeger.txt b/docs/apidiffs/1.20.1_vs_1.20.0/opentelemetry-exporter-jaeger.txt new file mode 100644 index 00000000000..df26146497b --- /dev/null +++ b/docs/apidiffs/1.20.1_vs_1.20.0/opentelemetry-exporter-jaeger.txt @@ -0,0 +1,2 @@ +Comparing source compatibility of against +No changes. \ No newline at end of file diff --git a/docs/apidiffs/1.20.1_vs_1.20.0/opentelemetry-exporter-logging-otlp.txt b/docs/apidiffs/1.20.1_vs_1.20.0/opentelemetry-exporter-logging-otlp.txt new file mode 100644 index 00000000000..df26146497b --- /dev/null +++ b/docs/apidiffs/1.20.1_vs_1.20.0/opentelemetry-exporter-logging-otlp.txt @@ -0,0 +1,2 @@ +Comparing source compatibility of against +No changes. \ No newline at end of file diff --git a/docs/apidiffs/1.20.1_vs_1.20.0/opentelemetry-exporter-logging.txt b/docs/apidiffs/1.20.1_vs_1.20.0/opentelemetry-exporter-logging.txt new file mode 100644 index 00000000000..df26146497b --- /dev/null +++ b/docs/apidiffs/1.20.1_vs_1.20.0/opentelemetry-exporter-logging.txt @@ -0,0 +1,2 @@ +Comparing source compatibility of against +No changes. \ No newline at end of file diff --git a/docs/apidiffs/1.20.1_vs_1.20.0/opentelemetry-exporter-otlp-common.txt b/docs/apidiffs/1.20.1_vs_1.20.0/opentelemetry-exporter-otlp-common.txt new file mode 100644 index 00000000000..df26146497b --- /dev/null +++ b/docs/apidiffs/1.20.1_vs_1.20.0/opentelemetry-exporter-otlp-common.txt @@ -0,0 +1,2 @@ +Comparing source compatibility of against +No changes. \ No newline at end of file diff --git a/docs/apidiffs/1.20.1_vs_1.20.0/opentelemetry-exporter-otlp.txt b/docs/apidiffs/1.20.1_vs_1.20.0/opentelemetry-exporter-otlp.txt new file mode 100644 index 00000000000..df26146497b --- /dev/null +++ b/docs/apidiffs/1.20.1_vs_1.20.0/opentelemetry-exporter-otlp.txt @@ -0,0 +1,2 @@ +Comparing source compatibility of against +No changes. \ No newline at end of file diff --git a/docs/apidiffs/1.20.1_vs_1.20.0/opentelemetry-exporter-zipkin.txt b/docs/apidiffs/1.20.1_vs_1.20.0/opentelemetry-exporter-zipkin.txt new file mode 100644 index 00000000000..df26146497b --- /dev/null +++ b/docs/apidiffs/1.20.1_vs_1.20.0/opentelemetry-exporter-zipkin.txt @@ -0,0 +1,2 @@ +Comparing source compatibility of against +No changes. \ No newline at end of file diff --git a/docs/apidiffs/1.20.1_vs_1.20.0/opentelemetry-extension-aws.txt b/docs/apidiffs/1.20.1_vs_1.20.0/opentelemetry-extension-aws.txt new file mode 100644 index 00000000000..df26146497b --- /dev/null +++ b/docs/apidiffs/1.20.1_vs_1.20.0/opentelemetry-extension-aws.txt @@ -0,0 +1,2 @@ +Comparing source compatibility of against +No changes. \ No newline at end of file diff --git a/docs/apidiffs/1.20.1_vs_1.20.0/opentelemetry-extension-kotlin.txt b/docs/apidiffs/1.20.1_vs_1.20.0/opentelemetry-extension-kotlin.txt new file mode 100644 index 00000000000..df26146497b --- /dev/null +++ b/docs/apidiffs/1.20.1_vs_1.20.0/opentelemetry-extension-kotlin.txt @@ -0,0 +1,2 @@ +Comparing source compatibility of against +No changes. \ No newline at end of file diff --git a/docs/apidiffs/1.20.1_vs_1.20.0/opentelemetry-extension-trace-propagators.txt b/docs/apidiffs/1.20.1_vs_1.20.0/opentelemetry-extension-trace-propagators.txt new file mode 100644 index 00000000000..df26146497b --- /dev/null +++ b/docs/apidiffs/1.20.1_vs_1.20.0/opentelemetry-extension-trace-propagators.txt @@ -0,0 +1,2 @@ +Comparing source compatibility of against +No changes. \ No newline at end of file diff --git a/docs/apidiffs/1.20.1_vs_1.20.0/opentelemetry-sdk-common.txt b/docs/apidiffs/1.20.1_vs_1.20.0/opentelemetry-sdk-common.txt new file mode 100644 index 00000000000..df26146497b --- /dev/null +++ b/docs/apidiffs/1.20.1_vs_1.20.0/opentelemetry-sdk-common.txt @@ -0,0 +1,2 @@ +Comparing source compatibility of against +No changes. \ No newline at end of file diff --git a/docs/apidiffs/1.20.1_vs_1.20.0/opentelemetry-sdk-extension-autoconfigure-spi.txt b/docs/apidiffs/1.20.1_vs_1.20.0/opentelemetry-sdk-extension-autoconfigure-spi.txt new file mode 100644 index 00000000000..df26146497b --- /dev/null +++ b/docs/apidiffs/1.20.1_vs_1.20.0/opentelemetry-sdk-extension-autoconfigure-spi.txt @@ -0,0 +1,2 @@ +Comparing source compatibility of against +No changes. \ No newline at end of file diff --git a/docs/apidiffs/1.20.1_vs_1.20.0/opentelemetry-sdk-extension-jaeger-remote-sampler.txt b/docs/apidiffs/1.20.1_vs_1.20.0/opentelemetry-sdk-extension-jaeger-remote-sampler.txt new file mode 100644 index 00000000000..df26146497b --- /dev/null +++ b/docs/apidiffs/1.20.1_vs_1.20.0/opentelemetry-sdk-extension-jaeger-remote-sampler.txt @@ -0,0 +1,2 @@ +Comparing source compatibility of against +No changes. \ No newline at end of file diff --git a/docs/apidiffs/1.20.1_vs_1.20.0/opentelemetry-sdk-metrics.txt b/docs/apidiffs/1.20.1_vs_1.20.0/opentelemetry-sdk-metrics.txt new file mode 100644 index 00000000000..df26146497b --- /dev/null +++ b/docs/apidiffs/1.20.1_vs_1.20.0/opentelemetry-sdk-metrics.txt @@ -0,0 +1,2 @@ +Comparing source compatibility of against +No changes. \ No newline at end of file diff --git a/docs/apidiffs/1.20.1_vs_1.20.0/opentelemetry-sdk-testing.txt b/docs/apidiffs/1.20.1_vs_1.20.0/opentelemetry-sdk-testing.txt new file mode 100644 index 00000000000..df26146497b --- /dev/null +++ b/docs/apidiffs/1.20.1_vs_1.20.0/opentelemetry-sdk-testing.txt @@ -0,0 +1,2 @@ +Comparing source compatibility of against +No changes. \ No newline at end of file diff --git a/docs/apidiffs/1.20.1_vs_1.20.0/opentelemetry-sdk-trace.txt b/docs/apidiffs/1.20.1_vs_1.20.0/opentelemetry-sdk-trace.txt new file mode 100644 index 00000000000..df26146497b --- /dev/null +++ b/docs/apidiffs/1.20.1_vs_1.20.0/opentelemetry-sdk-trace.txt @@ -0,0 +1,2 @@ +Comparing source compatibility of against +No changes. \ No newline at end of file diff --git a/docs/apidiffs/1.20.1_vs_1.20.0/opentelemetry-sdk.txt b/docs/apidiffs/1.20.1_vs_1.20.0/opentelemetry-sdk.txt new file mode 100644 index 00000000000..df26146497b --- /dev/null +++ b/docs/apidiffs/1.20.1_vs_1.20.0/opentelemetry-sdk.txt @@ -0,0 +1,2 @@ +Comparing source compatibility of against +No changes. \ No newline at end of file From 6c7637b96ea3d4ee80b8a306fbc358bf348c1d39 Mon Sep 17 00:00:00 2001 From: OpenTelemetry Bot <107717825+opentelemetrybot@users.noreply.github.com> Date: Wed, 16 Nov 2022 09:51:48 -0800 Subject: [PATCH 37/68] Copy change log updates from release/v1.20.x (#4959) --- CHANGELOG.md | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index da72d65fd54..6de58f8f7bf 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,14 @@ ## Unreleased +## Version 1.20.1 (2022-11-15) + +### Bugfixes + +* Fix bug in `ComponentRegistry` that produces `ConcurrentModificationException` when reading + metrics at the same time as obtaining a meter. + [(#4951)](https://github.com/open-telemetry/opentelemetry-java/pull/4951) + ## Version 1.20.0 (2022-11-11) ### API From 08e19e38c68725e20d8ea83a1611963c56c8ff42 Mon Sep 17 00:00:00 2001 From: jack-berg <34418638+jack-berg@users.noreply.github.com> Date: Thu, 17 Nov 2022 09:40:29 -0600 Subject: [PATCH 38/68] Stop publishing opentelemetry-extension-aws artifact (#4945) --- CHANGELOG.md | 2 +- README.md | 1 - all/build.gradle.kts | 1 + .../all/FallbackArtifactsTest.java | 6 + bom/build.gradle.kts | 1 + .../opentelemetry-extension-aws.txt | 2 - extensions/aws/README.md | 12 - extensions/aws/build.gradle.kts | 14 - .../aws/AwsConfigurablePropagator.java | 30 -- .../extension/aws/AwsXrayPropagator.java | 333 ------------ .../extension/aws/package-info.java | 5 - ...nfigure.spi.ConfigurablePropagatorProvider | 1 - .../extension/aws/AwsXrayPropagatorTest.java | 479 ------------------ settings.gradle.kts | 1 - 14 files changed, 9 insertions(+), 879 deletions(-) delete mode 100644 docs/apidiffs/current_vs_latest/opentelemetry-extension-aws.txt delete mode 100644 extensions/aws/README.md delete mode 100644 extensions/aws/build.gradle.kts delete mode 100644 extensions/aws/src/main/java/io/opentelemetry/extension/aws/AwsConfigurablePropagator.java delete mode 100644 extensions/aws/src/main/java/io/opentelemetry/extension/aws/AwsXrayPropagator.java delete mode 100644 extensions/aws/src/main/java/io/opentelemetry/extension/aws/package-info.java delete mode 100644 extensions/aws/src/main/resources/META-INF/services/io.opentelemetry.sdk.autoconfigure.spi.ConfigurablePropagatorProvider delete mode 100644 extensions/aws/src/test/java/io/opentelemetry/extension/aws/AwsXrayPropagatorTest.java diff --git a/CHANGELOG.md b/CHANGELOG.md index 6de58f8f7bf..79cd8508c2b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -20,7 +20,7 @@ #### API Extensions * DEPRECATION: the `opentelemetry-extension-aws` module containing - various `AwsXrayPropagator` implementations has been deprecated for removal in next major version. + various `AwsXrayPropagator` implementations has been deprecated for removal in next minor version. A copy of the code will instead be maintained in [opentelemetry-java-contrib/aws-xray-propagator](https://github.com/open-telemetry/opentelemetry-java-contrib/tree/main/aws-xray-propagator) and published under diff --git a/README.md b/README.md index c759f1d6981..479df09e343 100644 --- a/README.md +++ b/README.md @@ -232,7 +232,6 @@ dependency as follows, replacing `{{artifact-id}}` with the value from the "Arti | Component | Description | Artifact ID | Version | |---------------------------------------------------------------|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|---------------------------------------------|-------------------------------------------------------------| -| [AWS Extension](./extensions/aws) | AWS Xray propagator (deprecated, moved to [opentelemetry-java-contrib/aws-xray-propagator](https://github.com/open-telemetry/opentelemetry-java-contrib/tree/main/aws-xray-propagator)) | `opentelemetry-extension-aws` | 1.20.1 | | [Kotlin Extension](./extensions/kotlin) | Context extension for coroutines | `opentelemetry-extension-kotlin` | 1.20.1 | | [Trace Propagators Extension](./extensions/trace-propagators) | Trace propagators, including B3, Jaeger, OT Trace | `opentelemetry-extension-trace-propagators` | 1.20.1 | | [Incubator Extension](./extensions/incubator) | API incubator, including pass through propagator, and extended tracer | `opentelemetry-extension-incubator` | 1.20.1-alpha | diff --git a/all/build.gradle.kts b/all/build.gradle.kts index 8c152a1e72c..0eaf8041b60 100644 --- a/all/build.gradle.kts +++ b/all/build.gradle.kts @@ -48,6 +48,7 @@ dependencies { testImplementation("io.grpc:grpc-protobuf") testImplementation("io.grpc:grpc-stub") testImplementation("io.opentelemetry:opentelemetry-extension-annotations") + testImplementation("io.opentelemetry:opentelemetry-extension-aws") testImplementation("io.opentelemetry:opentelemetry-sdk-extension-resources") testImplementation("io.opentelemetry:opentelemetry-sdk-extension-aws") diff --git a/all/src/test/java/io/opentelemetry/all/FallbackArtifactsTest.java b/all/src/test/java/io/opentelemetry/all/FallbackArtifactsTest.java index 78e91f19f8a..eebe961e292 100644 --- a/all/src/test/java/io/opentelemetry/all/FallbackArtifactsTest.java +++ b/all/src/test/java/io/opentelemetry/all/FallbackArtifactsTest.java @@ -56,6 +56,12 @@ void sdkExtensionAws() { classAvailable("io.opentelemetry.sdk.extension.aws.trace.AwsXrayIdGenerator"); } + @Test + void extensionAws() { + classAvailable("io.opentelemetry.extension.aws.AwsConfigurablePropagator"); + classAvailable("io.opentelemetry.extension.aws.AwsXrayPropagator"); + } + private static void classAvailable(String fqcn) { Assertions.assertThatCode(() -> Class.forName(fqcn)).doesNotThrowAnyException(); } diff --git a/bom/build.gradle.kts b/bom/build.gradle.kts index d921ab49bec..72e53b6b24a 100644 --- a/bom/build.gradle.kts +++ b/bom/build.gradle.kts @@ -13,3 +13,4 @@ otelBom.addFallback("opentelemetry-exporter-jaeger-proto", "1.17.0") otelBom.addFallback("opentelemetry-extension-annotations", "1.18.0") otelBom.addFallback("opentelemetry-sdk-extension-resources", "1.19.0") otelBom.addFallback("opentelemetry-sdk-extension-aws", "1.19.0") +otelBom.addFallback("opentelemetry-extension-aws", "1.20.0") diff --git a/docs/apidiffs/current_vs_latest/opentelemetry-extension-aws.txt b/docs/apidiffs/current_vs_latest/opentelemetry-extension-aws.txt deleted file mode 100644 index df26146497b..00000000000 --- a/docs/apidiffs/current_vs_latest/opentelemetry-extension-aws.txt +++ /dev/null @@ -1,2 +0,0 @@ -Comparing source compatibility of against -No changes. \ No newline at end of file diff --git a/extensions/aws/README.md b/extensions/aws/README.md deleted file mode 100644 index 7157e7df5d4..00000000000 --- a/extensions/aws/README.md +++ /dev/null @@ -1,12 +0,0 @@ -# OpenTelemetry Extension AWS - -[![Javadocs][javadoc-image]][javadoc-url] - -> **NOTICE**: This artifact is deprecated and its contents have been moved -> to [io.opentelemetry.contrib:opentelemetry-aws-xray-propagator](https://github.com/open-telemetry/opentelemetry-java-contrib/tree/main/aws-xray-propagator). -> Version 1.20.0 will be the last minor version published. However, it will continue to receive -> patches for security vulnerabilities, and `io.opentelemetry:opentelemetry-bom` will reference the -> last published version. - -[javadoc-image]: https://www.javadoc.io/badge/io.opentelemetry/opentelemetry-extension-aws.svg -[javadoc-url]: https://www.javadoc.io/doc/io.opentelemetry/opentelemetry-extension-aws diff --git a/extensions/aws/build.gradle.kts b/extensions/aws/build.gradle.kts deleted file mode 100644 index 24209c37509..00000000000 --- a/extensions/aws/build.gradle.kts +++ /dev/null @@ -1,14 +0,0 @@ -plugins { - id("otel.java-conventions") - id("otel.publish-conventions") - - id("otel.animalsniffer-conventions") -} - -description = "OpenTelemetry API Extensions for AWS" -otelJava.moduleName.set("io.opentelemetry.extension.aws") - -dependencies { - api(project(":api:all")) - compileOnly(project(":sdk-extensions:autoconfigure")) -} diff --git a/extensions/aws/src/main/java/io/opentelemetry/extension/aws/AwsConfigurablePropagator.java b/extensions/aws/src/main/java/io/opentelemetry/extension/aws/AwsConfigurablePropagator.java deleted file mode 100644 index 1682f16ec3a..00000000000 --- a/extensions/aws/src/main/java/io/opentelemetry/extension/aws/AwsConfigurablePropagator.java +++ /dev/null @@ -1,30 +0,0 @@ -/* - * Copyright The OpenTelemetry Authors - * SPDX-License-Identifier: Apache-2.0 - */ - -package io.opentelemetry.extension.aws; - -import io.opentelemetry.context.propagation.TextMapPropagator; -import io.opentelemetry.sdk.autoconfigure.spi.ConfigProperties; -import io.opentelemetry.sdk.autoconfigure.spi.ConfigurablePropagatorProvider; - -/** - * A {@link ConfigurablePropagatorProvider} which allows enabling the {@link AwsXrayPropagator} with - * the propagator name {@code xray}. - * - * @deprecated Moved to io.opentelemetry.contrib:opentelemetry-aws-xray-propagator. - */ -@Deprecated -public final class AwsConfigurablePropagator implements ConfigurablePropagatorProvider { - @Override - public TextMapPropagator getPropagator(ConfigProperties config) { - return AwsXrayPropagator.getInstance(); - } - - @Override - public String getName() { - return "xray"; - } -} diff --git a/extensions/aws/src/main/java/io/opentelemetry/extension/aws/AwsXrayPropagator.java b/extensions/aws/src/main/java/io/opentelemetry/extension/aws/AwsXrayPropagator.java deleted file mode 100644 index d483f339462..00000000000 --- a/extensions/aws/src/main/java/io/opentelemetry/extension/aws/AwsXrayPropagator.java +++ /dev/null @@ -1,333 +0,0 @@ -/* - * Copyright The OpenTelemetry Authors - * SPDX-License-Identifier: Apache-2.0 - */ - -package io.opentelemetry.extension.aws; - -import io.opentelemetry.api.baggage.Baggage; -import io.opentelemetry.api.baggage.BaggageBuilder; -import io.opentelemetry.api.baggage.BaggageEntry; -import io.opentelemetry.api.internal.StringUtils; -import io.opentelemetry.api.trace.Span; -import io.opentelemetry.api.trace.SpanContext; -import io.opentelemetry.api.trace.SpanId; -import io.opentelemetry.api.trace.TraceFlags; -import io.opentelemetry.api.trace.TraceId; -import io.opentelemetry.api.trace.TraceState; -import io.opentelemetry.context.Context; -import io.opentelemetry.context.propagation.TextMapGetter; -import io.opentelemetry.context.propagation.TextMapPropagator; -import io.opentelemetry.context.propagation.TextMapSetter; -import java.util.Collection; -import java.util.Collections; -import java.util.function.BiConsumer; -import java.util.logging.Logger; -import javax.annotation.Nullable; - -/** - * Implementation of the AWS X-Ray Trace Header propagation protocol. See AWS - * Tracing header spec - * - *

To register the X-Ray propagator together with default propagator when using the SDK: - * - *

{@code
- * OpenTelemetrySdk.builder()
- *   .setPropagators(
- *     ContextPropagators.create(
- *         TextMapPropagator.composite(
- *             W3CTraceContextPropagator.getInstance(),
- *             AWSXrayPropagator.getInstance())))
- *    .build();
- * }
- * - * @deprecated Moved to io.opentelemetry.contrib:opentelemetry-aws-xray-propagator. - */ -@Deprecated -public final class AwsXrayPropagator implements TextMapPropagator { - - // Visible for testing - static final String TRACE_HEADER_KEY = "X-Amzn-Trace-Id"; - - private static final Logger logger = Logger.getLogger(AwsXrayPropagator.class.getName()); - - private static final char TRACE_HEADER_DELIMITER = ';'; - private static final char KV_DELIMITER = '='; - - private static final String TRACE_ID_KEY = "Root"; - private static final int TRACE_ID_LENGTH = 35; - private static final String TRACE_ID_VERSION = "1"; - private static final char TRACE_ID_DELIMITER = '-'; - private static final int TRACE_ID_DELIMITER_INDEX_1 = 1; - private static final int TRACE_ID_DELIMITER_INDEX_2 = 10; - private static final int TRACE_ID_FIRST_PART_LENGTH = 8; - - private static final String PARENT_ID_KEY = "Parent"; - private static final int PARENT_ID_LENGTH = 16; - - private static final String SAMPLED_FLAG_KEY = "Sampled"; - private static final int SAMPLED_FLAG_LENGTH = 1; - private static final char IS_SAMPLED = '1'; - private static final char NOT_SAMPLED = '0'; - - private static final Collection FIELDS = Collections.singletonList(TRACE_HEADER_KEY); - - private static final AwsXrayPropagator INSTANCE = new AwsXrayPropagator(); - - private AwsXrayPropagator() { - // singleton - } - - public static AwsXrayPropagator getInstance() { - return INSTANCE; - } - - @Override - public Collection fields() { - return FIELDS; - } - - @Override - public void inject(Context context, @Nullable C carrier, TextMapSetter setter) { - if (context == null) { - return; - } - if (setter == null) { - return; - } - - Span span = Span.fromContext(context); - if (!span.getSpanContext().isValid()) { - return; - } - - SpanContext spanContext = span.getSpanContext(); - - String otTraceId = spanContext.getTraceId(); - String xrayTraceId = - TRACE_ID_VERSION - + TRACE_ID_DELIMITER - + otTraceId.substring(0, TRACE_ID_FIRST_PART_LENGTH) - + TRACE_ID_DELIMITER - + otTraceId.substring(TRACE_ID_FIRST_PART_LENGTH); - String parentId = spanContext.getSpanId(); - char samplingFlag = spanContext.isSampled() ? IS_SAMPLED : NOT_SAMPLED; - // TODO: Add OT trace state to the X-Ray trace header - - StringBuilder traceHeader = new StringBuilder(); - traceHeader - .append(TRACE_ID_KEY) - .append(KV_DELIMITER) - .append(xrayTraceId) - .append(TRACE_HEADER_DELIMITER) - .append(PARENT_ID_KEY) - .append(KV_DELIMITER) - .append(parentId) - .append(TRACE_HEADER_DELIMITER) - .append(SAMPLED_FLAG_KEY) - .append(KV_DELIMITER) - .append(samplingFlag); - - Baggage baggage = Baggage.fromContext(context); - // Truncate baggage to 256 chars per X-Ray spec. - baggage.forEach( - new BiConsumer() { - - private int baggageWrittenBytes; - - @Override - public void accept(String key, BaggageEntry entry) { - if (key.equals(TRACE_ID_KEY) - || key.equals(PARENT_ID_KEY) - || key.equals(SAMPLED_FLAG_KEY)) { - return; - } - // Size is key/value pair, excludes delimiter. - int size = key.length() + entry.getValue().length() + 1; - if (baggageWrittenBytes + size > 256) { - return; - } - traceHeader - .append(TRACE_HEADER_DELIMITER) - .append(key) - .append(KV_DELIMITER) - .append(entry.getValue()); - baggageWrittenBytes += size; - } - }); - - setter.set(carrier, TRACE_HEADER_KEY, traceHeader.toString()); - } - - @Override - public Context extract(Context context, @Nullable C carrier, TextMapGetter getter) { - if (context == null) { - return Context.root(); - } - if (getter == null) { - return context; - } - - return getContextFromHeader(context, carrier, getter); - } - - private static Context getContextFromHeader( - Context context, @Nullable C carrier, TextMapGetter getter) { - String traceHeader = getter.get(carrier, TRACE_HEADER_KEY); - if (traceHeader == null || traceHeader.isEmpty()) { - return context; - } - - String traceId = TraceId.getInvalid(); - String spanId = SpanId.getInvalid(); - Boolean isSampled = false; - - BaggageBuilder baggage = null; - int baggageReadBytes = 0; - - int pos = 0; - while (pos < traceHeader.length()) { - int delimiterIndex = traceHeader.indexOf(TRACE_HEADER_DELIMITER, pos); - String part; - if (delimiterIndex >= 0) { - part = traceHeader.substring(pos, delimiterIndex); - pos = delimiterIndex + 1; - } else { - // Last part. - part = traceHeader.substring(pos); - pos = traceHeader.length(); - } - String trimmedPart = part.trim(); - int equalsIndex = trimmedPart.indexOf(KV_DELIMITER); - if (equalsIndex < 0) { - logger.fine("Error parsing X-Ray trace header. Invalid key value pair: " + part); - return context; - } - - String value = trimmedPart.substring(equalsIndex + 1); - - if (trimmedPart.startsWith(TRACE_ID_KEY)) { - traceId = parseTraceId(value); - } else if (trimmedPart.startsWith(PARENT_ID_KEY)) { - spanId = parseSpanId(value); - } else if (trimmedPart.startsWith(SAMPLED_FLAG_KEY)) { - isSampled = parseTraceFlag(value); - } else if (baggageReadBytes + trimmedPart.length() <= 256) { - if (baggage == null) { - baggage = Baggage.builder(); - } - baggage.put(trimmedPart.substring(0, equalsIndex), value); - baggageReadBytes += trimmedPart.length(); - } - } - if (isSampled == null) { - logger.fine( - "Invalid Sampling flag in X-Ray trace header: '" - + TRACE_HEADER_KEY - + "' with value " - + traceHeader - + "'."); - return context; - } - - if (spanId == null || traceId == null) { - logger.finest("Both traceId and spanId are required to extract a valid span context. "); - } - - SpanContext spanContext = - SpanContext.createFromRemoteParent( - StringUtils.padLeft(traceId, TraceId.getLength()), - spanId, - isSampled ? TraceFlags.getSampled() : TraceFlags.getDefault(), - TraceState.getDefault()); - if (spanContext.isValid()) { - context = context.with(Span.wrap(spanContext)); - } - if (baggage != null) { - context = context.with(baggage.build()); - } - return context; - } - - private static String parseTraceId(String xrayTraceId) { - return (xrayTraceId.length() == TRACE_ID_LENGTH - ? parseSpecTraceId(xrayTraceId) - : parseShortTraceId(xrayTraceId)); - } - - private static String parseSpecTraceId(String xrayTraceId) { - - // Check version trace id version - if (!xrayTraceId.startsWith(TRACE_ID_VERSION)) { - return TraceId.getInvalid(); - } - - // Check delimiters - if (xrayTraceId.charAt(TRACE_ID_DELIMITER_INDEX_1) != TRACE_ID_DELIMITER - || xrayTraceId.charAt(TRACE_ID_DELIMITER_INDEX_2) != TRACE_ID_DELIMITER) { - return TraceId.getInvalid(); - } - - String epochPart = - xrayTraceId.substring(TRACE_ID_DELIMITER_INDEX_1 + 1, TRACE_ID_DELIMITER_INDEX_2); - String uniquePart = xrayTraceId.substring(TRACE_ID_DELIMITER_INDEX_2 + 1, TRACE_ID_LENGTH); - - // X-Ray trace id format is 1-{8 digit hex}-{24 digit hex} - return epochPart + uniquePart; - } - - private static String parseShortTraceId(String xrayTraceId) { - if (xrayTraceId.length() > TRACE_ID_LENGTH) { - return TraceId.getInvalid(); - } - - // Check version trace id version - if (!xrayTraceId.startsWith(TRACE_ID_VERSION)) { - return TraceId.getInvalid(); - } - - // Check delimiters - int firstDelimiter = xrayTraceId.indexOf(TRACE_ID_DELIMITER); - // we don't allow the epoch part to be missing completely - int secondDelimiter = xrayTraceId.indexOf(TRACE_ID_DELIMITER, firstDelimiter + 2); - if (firstDelimiter != TRACE_ID_DELIMITER_INDEX_1 - || secondDelimiter == -1 - || secondDelimiter > TRACE_ID_DELIMITER_INDEX_2) { - return TraceId.getInvalid(); - } - - String epochPart = xrayTraceId.substring(firstDelimiter + 1, secondDelimiter); - String uniquePart = xrayTraceId.substring(secondDelimiter + 1, secondDelimiter + 25); - - // X-Ray trace id format is 1-{at most 8 digit hex}-{24 digit hex} - // epoch part can have leading 0s truncated - return epochPart + uniquePart; - } - - private static String parseSpanId(String xrayParentId) { - if (xrayParentId.length() != PARENT_ID_LENGTH) { - return SpanId.getInvalid(); - } - - return xrayParentId; - } - - @Nullable - private static Boolean parseTraceFlag(String xraySampledFlag) { - if (xraySampledFlag.length() != SAMPLED_FLAG_LENGTH) { - // Returning null as there is no invalid trace flag defined. - return null; - } - - char flag = xraySampledFlag.charAt(0); - if (flag == IS_SAMPLED) { - return true; - } else if (flag == NOT_SAMPLED) { - return false; - } else { - return null; - } - } -} diff --git a/extensions/aws/src/main/java/io/opentelemetry/extension/aws/package-info.java b/extensions/aws/src/main/java/io/opentelemetry/extension/aws/package-info.java deleted file mode 100644 index f70fc7eac53..00000000000 --- a/extensions/aws/src/main/java/io/opentelemetry/extension/aws/package-info.java +++ /dev/null @@ -1,5 +0,0 @@ -/** OpenTelemetry API extensions for use with AWS. */ -@ParametersAreNonnullByDefault -package io.opentelemetry.extension.aws; - -import javax.annotation.ParametersAreNonnullByDefault; diff --git a/extensions/aws/src/main/resources/META-INF/services/io.opentelemetry.sdk.autoconfigure.spi.ConfigurablePropagatorProvider b/extensions/aws/src/main/resources/META-INF/services/io.opentelemetry.sdk.autoconfigure.spi.ConfigurablePropagatorProvider deleted file mode 100644 index 838deff6656..00000000000 --- a/extensions/aws/src/main/resources/META-INF/services/io.opentelemetry.sdk.autoconfigure.spi.ConfigurablePropagatorProvider +++ /dev/null @@ -1 +0,0 @@ -io.opentelemetry.extension.aws.AwsConfigurablePropagator diff --git a/extensions/aws/src/test/java/io/opentelemetry/extension/aws/AwsXrayPropagatorTest.java b/extensions/aws/src/test/java/io/opentelemetry/extension/aws/AwsXrayPropagatorTest.java deleted file mode 100644 index 3ad4a957f81..00000000000 --- a/extensions/aws/src/test/java/io/opentelemetry/extension/aws/AwsXrayPropagatorTest.java +++ /dev/null @@ -1,479 +0,0 @@ -/* - * Copyright The OpenTelemetry Authors - * SPDX-License-Identifier: Apache-2.0 - */ - -package io.opentelemetry.extension.aws; - -import static org.assertj.core.api.Assertions.assertThat; - -import io.opentelemetry.api.baggage.Baggage; -import io.opentelemetry.api.trace.Span; -import io.opentelemetry.api.trace.SpanContext; -import io.opentelemetry.api.trace.TraceFlags; -import io.opentelemetry.api.trace.TraceState; -import io.opentelemetry.context.Context; -import io.opentelemetry.context.propagation.TextMapGetter; -import io.opentelemetry.context.propagation.TextMapSetter; -import java.util.Collections; -import java.util.LinkedHashMap; -import java.util.Map; -import java.util.stream.Collectors; -import java.util.stream.Stream; -import javax.annotation.Nullable; -import org.junit.jupiter.api.Test; - -@SuppressWarnings("deprecation") // Moved to contrib -class AwsXrayPropagatorTest { - - private static final String TRACE_ID = "8a3c60f7d188f8fa79d48a391a778fa6"; - private static final String SPAN_ID = "53995c3f42cd8ad8"; - - private static final TextMapSetter> setter = Map::put; - private static final TextMapGetter> getter = - new TextMapGetter>() { - @Override - public Iterable keys(Map carrier) { - return carrier.keySet(); - } - - @Nullable - @Override - public String get(Map carrier, String key) { - return carrier.get(key); - } - }; - private final AwsXrayPropagator xrayPropagator = AwsXrayPropagator.getInstance(); - - @Test - void inject_SampledContext() { - Map carrier = new LinkedHashMap<>(); - xrayPropagator.inject( - withSpanContext( - SpanContext.create(TRACE_ID, SPAN_ID, TraceFlags.getSampled(), TraceState.getDefault()), - Context.current()), - carrier, - setter); - - assertThat(carrier) - .containsEntry( - AwsXrayPropagator.TRACE_HEADER_KEY, - "Root=1-8a3c60f7-d188f8fa79d48a391a778fa6;Parent=53995c3f42cd8ad8;Sampled=1"); - } - - @Test - void inject_NotSampledContext() { - Map carrier = new LinkedHashMap<>(); - xrayPropagator.inject( - withSpanContext( - SpanContext.create(TRACE_ID, SPAN_ID, TraceFlags.getDefault(), TraceState.getDefault()), - Context.current()), - carrier, - setter); - - assertThat(carrier) - .containsEntry( - AwsXrayPropagator.TRACE_HEADER_KEY, - "Root=1-8a3c60f7-d188f8fa79d48a391a778fa6;Parent=53995c3f42cd8ad8;Sampled=0"); - } - - @Test - void inject_WithBaggage() { - Map carrier = new LinkedHashMap<>(); - xrayPropagator.inject( - withSpanContext( - SpanContext.create( - TRACE_ID, SPAN_ID, TraceFlags.getDefault(), TraceState.getDefault()), - Context.current()) - .with( - Baggage.builder() - .put("cat", "meow") - .put("dog", "bark") - .put("Root", "ignored") - .put("Parent", "ignored") - .put("Sampled", "ignored") - .build()), - carrier, - setter); - - assertThat(carrier) - .containsEntry( - AwsXrayPropagator.TRACE_HEADER_KEY, - "Root=1-8a3c60f7-d188f8fa79d48a391a778fa6;Parent=53995c3f42cd8ad8;Sampled=0;" - + "cat=meow;dog=bark"); - } - - @Test - void inject_WithBaggage_LimitTruncates() { - Map carrier = new LinkedHashMap<>(); - // Limit is 256 characters for all baggage. We add a 254-character key/value pair and a - // 3 character key value pair. - String key1 = Stream.generate(() -> "a").limit(252).collect(Collectors.joining()); - String value1 = "a"; // 252 + 1 (=) + 1 = 254 - - String key2 = "b"; - String value2 = "b"; // 1 + 1 (=) + 1 = 3 - - Baggage baggage = Baggage.builder().put(key1, value1).put(key2, value2).build(); - - xrayPropagator.inject( - withSpanContext( - SpanContext.create( - TRACE_ID, SPAN_ID, TraceFlags.getDefault(), TraceState.getDefault()), - Context.current()) - .with(baggage), - carrier, - setter); - - assertThat(carrier) - .containsEntry( - AwsXrayPropagator.TRACE_HEADER_KEY, - "Root=1-8a3c60f7-d188f8fa79d48a391a778fa6;Parent=53995c3f42cd8ad8;Sampled=0;" - + key1 - + '=' - + value1); - } - - @Test - void inject_WithTraceState() { - Map carrier = new LinkedHashMap<>(); - xrayPropagator.inject( - withSpanContext( - SpanContext.create( - TRACE_ID, - SPAN_ID, - TraceFlags.getDefault(), - TraceState.builder().put("foo", "bar").build()), - Context.current()), - carrier, - setter); - - // TODO: assert trace state when the propagator supports it, for general key/value pairs we are - // mapping with baggage. - assertThat(carrier) - .containsEntry( - AwsXrayPropagator.TRACE_HEADER_KEY, - "Root=1-8a3c60f7-d188f8fa79d48a391a778fa6;Parent=53995c3f42cd8ad8;Sampled=0"); - } - - @Test - void inject_nullContext() { - Map carrier = new LinkedHashMap<>(); - xrayPropagator.inject(null, carrier, setter); - assertThat(carrier).isEmpty(); - } - - @Test - void inject_nullSetter() { - Map carrier = new LinkedHashMap<>(); - Context context = - withSpanContext( - SpanContext.create(TRACE_ID, SPAN_ID, TraceFlags.getDefault(), TraceState.getDefault()), - Context.current()); - xrayPropagator.inject(context, carrier, null); - assertThat(carrier).isEmpty(); - } - - @Test - void extract_Nothing() { - // Context remains untouched. - assertThat( - xrayPropagator.extract( - Context.current(), Collections.emptyMap(), getter)) - .isSameAs(Context.current()); - } - - @Test - void extract_SampledContext() { - Map carrier = new LinkedHashMap<>(); - carrier.put( - AwsXrayPropagator.TRACE_HEADER_KEY, - "Root=1-8a3c60f7-d188f8fa79d48a391a778fa6;Parent=53995c3f42cd8ad8;Sampled=1"); - - assertThat(getSpanContext(xrayPropagator.extract(Context.current(), carrier, getter))) - .isEqualTo( - SpanContext.createFromRemoteParent( - TRACE_ID, SPAN_ID, TraceFlags.getSampled(), TraceState.getDefault())); - } - - @Test - void extract_NotSampledContext() { - Map carrier = new LinkedHashMap<>(); - carrier.put( - AwsXrayPropagator.TRACE_HEADER_KEY, - "Root=1-8a3c60f7-d188f8fa79d48a391a778fa6;Parent=53995c3f42cd8ad8;Sampled=0"); - - assertThat(getSpanContext(xrayPropagator.extract(Context.current(), carrier, getter))) - .isEqualTo( - SpanContext.createFromRemoteParent( - TRACE_ID, SPAN_ID, TraceFlags.getDefault(), TraceState.getDefault())); - } - - @Test - void extract_DifferentPartOrder() { - Map carrier = new LinkedHashMap<>(); - carrier.put( - AwsXrayPropagator.TRACE_HEADER_KEY, - "Parent=53995c3f42cd8ad8;Sampled=1;Root=1-8a3c60f7-d188f8fa79d48a391a778fa6"); - - assertThat(getSpanContext(xrayPropagator.extract(Context.current(), carrier, getter))) - .isEqualTo( - SpanContext.createFromRemoteParent( - TRACE_ID, SPAN_ID, TraceFlags.getSampled(), TraceState.getDefault())); - } - - @Test - void extract_AdditionalFields() { - Map carrier = new LinkedHashMap<>(); - carrier.put( - AwsXrayPropagator.TRACE_HEADER_KEY, - "Root=1-8a3c60f7-d188f8fa79d48a391a778fa6;Parent=53995c3f42cd8ad8;Sampled=1;Foo=Bar"); - - Context context = xrayPropagator.extract(Context.current(), carrier, getter); - assertThat(getSpanContext(context)) - .isEqualTo( - SpanContext.createFromRemoteParent( - TRACE_ID, SPAN_ID, TraceFlags.getSampled(), TraceState.getDefault())); - assertThat(Baggage.fromContext(context).getEntryValue("Foo")).isEqualTo("Bar"); - } - - @Test - void extract_Baggage_LimitTruncates() { - // Limit is 256 characters for all baggage. We add a 254-character key/value pair and a - // 3 character key value pair. - String key1 = Stream.generate(() -> "a").limit(252).collect(Collectors.joining()); - String value1 = "a"; // 252 + 1 (=) + 1 = 254 - - String key2 = "b"; - String value2 = "b"; // 1 + 1 (=) + 1 = 3 - - Map carrier = new LinkedHashMap<>(); - carrier.put( - AwsXrayPropagator.TRACE_HEADER_KEY, - "Root=1-8a3c60f7-d188f8fa79d48a391a778fa6;Parent=53995c3f42cd8ad8;Sampled=1;" - + key1 - + '=' - + value1 - + ';' - + key2 - + '=' - + value2); - - Context context = xrayPropagator.extract(Context.current(), carrier, getter); - assertThat(getSpanContext(context)) - .isEqualTo( - SpanContext.createFromRemoteParent( - TRACE_ID, SPAN_ID, TraceFlags.getSampled(), TraceState.getDefault())); - assertThat(Baggage.fromContext(context).getEntryValue(key1)).isEqualTo(value1); - assertThat(Baggage.fromContext(context).getEntryValue(key2)).isNull(); - } - - @Test - void extract_EmptyHeaderValue() { - Map invalidHeaders = new LinkedHashMap<>(); - invalidHeaders.put(AwsXrayPropagator.TRACE_HEADER_KEY, ""); - - verifyInvalidBehavior(invalidHeaders); - } - - @Test - void extract_InvalidTraceId() { - Map invalidHeaders = new LinkedHashMap<>(); - invalidHeaders.put( - AwsXrayPropagator.TRACE_HEADER_KEY, - "Root=abcdefghijklmnopabcdefghijklmnop;Parent=53995c3f42cd8ad8;Sampled=0"); - - verifyInvalidBehavior(invalidHeaders); - } - - @Test - void extract_InvalidTraceId_Size() { - Map invalidHeaders = new LinkedHashMap<>(); - invalidHeaders.put( - AwsXrayPropagator.TRACE_HEADER_KEY, - "Root=1-8a3c60f7-d188f8fa79d48a391a778fa600;Parent=53995c3f42cd8ad8;Sampled=0"); - - verifyInvalidBehavior(invalidHeaders); - } - - @Test - void extract_InvalidSpanId() { - Map invalidHeaders = new LinkedHashMap<>(); - invalidHeaders.put( - AwsXrayPropagator.TRACE_HEADER_KEY, - "Root=1-8a3c60f7-d188f8fa79d48a391a778fa6;Parent=abcdefghijklmnop;Sampled=0"); - - verifyInvalidBehavior(invalidHeaders); - } - - @Test - void extract_InvalidSpanId_Size() { - Map invalidHeaders = new LinkedHashMap<>(); - invalidHeaders.put( - AwsXrayPropagator.TRACE_HEADER_KEY, - "Root=1-8a3c60f7-d188f8fa79d48a391a778fa6;Parent=53995c3f42cd8ad800;Sampled=0"); - - verifyInvalidBehavior(invalidHeaders); - } - - @Test - void extract_InvalidFlags() { - Map invalidHeaders = new LinkedHashMap<>(); - invalidHeaders.put( - AwsXrayPropagator.TRACE_HEADER_KEY, - "Root=1-8a3c60f7-d188f8fa79d48a391a778fa6;Parent=53995c3f42cd8ad8;Sampled="); - - verifyInvalidBehavior(invalidHeaders); - } - - @Test - void extract_InvalidFlags_Size() { - Map invalidHeaders = new LinkedHashMap<>(); - invalidHeaders.put( - AwsXrayPropagator.TRACE_HEADER_KEY, - "Root=1-8a3c60f7-d188f8fa79d48a391a778fa6;Parent=53995c3f42cd8ad8;Sampled=10220"); - - verifyInvalidBehavior(invalidHeaders); - } - - @Test - void extract_InvalidFlags_NonNumeric() { - Map invalidHeaders = new LinkedHashMap<>(); - invalidHeaders.put( - AwsXrayPropagator.TRACE_HEADER_KEY, - "Root=1-8a3c60f7-d188f8fa79d48a391a778fa6;Parent=53995c3f42cd8ad8;Sampled=a"); - - verifyInvalidBehavior(invalidHeaders); - } - - @Test - void extract_Invalid_NoSpanId() { - Map invalidHeaders = new LinkedHashMap<>(1); - invalidHeaders.put( - AwsXrayPropagator.TRACE_HEADER_KEY, "Root=1-622422bf-59625fe25708d4660735d8ef"); - - verifyInvalidBehavior(invalidHeaders); - } - - private void verifyInvalidBehavior(Map invalidHeaders) { - Context input = Context.current(); - Context result = xrayPropagator.extract(input, invalidHeaders, getter); - assertThat(result).isSameAs(input); - assertThat(getSpanContext(result)).isSameAs(SpanContext.getInvalid()); - } - - @Test - void extract_nullContext() { - assertThat(xrayPropagator.extract(null, Collections.emptyMap(), getter)) - .isSameAs(Context.root()); - } - - @Test - void extract_nullGetter() { - Context context = - withSpanContext( - SpanContext.create(TRACE_ID, SPAN_ID, TraceFlags.getDefault(), TraceState.getDefault()), - Context.current()); - assertThat(xrayPropagator.extract(context, Collections.emptyMap(), null)).isSameAs(context); - } - - @Test - void extract_EpochPart_ZeroedSingleDigit() { - Map carrier = new LinkedHashMap<>(); - carrier.put( - AwsXrayPropagator.TRACE_HEADER_KEY, - "Root=1-0-d188f8fa79d48a391a778fa6;Parent=53995c3f42cd8ad8;Sampled=1;Foo=Bar"); - - assertThat(getSpanContext(xrayPropagator.extract(Context.current(), carrier, getter))) - .isEqualTo( - SpanContext.createFromRemoteParent( - "00000000d188f8fa79d48a391a778fa6", - SPAN_ID, - TraceFlags.getSampled(), - TraceState.getDefault())); - } - - @Test - void extract_EpochPart_TwoChars() { - Map carrier = new LinkedHashMap<>(); - carrier.put( - AwsXrayPropagator.TRACE_HEADER_KEY, - "Root=1-1a-d188f8fa79d48a391a778fa6;Parent=53995c3f42cd8ad8;Sampled=1;Foo=Bar"); - - assertThat(getSpanContext(xrayPropagator.extract(Context.current(), carrier, getter))) - .isEqualTo( - SpanContext.createFromRemoteParent( - "0000001ad188f8fa79d48a391a778fa6", - SPAN_ID, - TraceFlags.getSampled(), - TraceState.getDefault())); - } - - @Test - void extract_EpochPart_Zeroed() { - Map carrier = new LinkedHashMap<>(); - carrier.put( - AwsXrayPropagator.TRACE_HEADER_KEY, - "Root=1-00000000-d188f8fa79d48a391a778fa6;Parent=53995c3f42cd8ad8;Sampled=1;Foo=Bar"); - - assertThat(getSpanContext(xrayPropagator.extract(Context.current(), carrier, getter))) - .isEqualTo( - SpanContext.createFromRemoteParent( - "00000000d188f8fa79d48a391a778fa6", - SPAN_ID, - TraceFlags.getSampled(), - TraceState.getDefault())); - } - - @Test - void extract_InvalidTraceId_EpochPart_TooLong() { - Map invalidHeaders = new LinkedHashMap<>(); - invalidHeaders.put( - AwsXrayPropagator.TRACE_HEADER_KEY, - "Root=1-8a3c60f711-d188f8fa79d48a391a778fa6;Parent=53995c3f42cd8ad8;Sampled=0"); - - assertThat(getSpanContext(xrayPropagator.extract(Context.current(), invalidHeaders, getter))) - .isSameAs(SpanContext.getInvalid()); - } - - @Test - void extract_InvalidTraceId_EpochPart_Empty() { - Map invalidHeaders = new LinkedHashMap<>(); - invalidHeaders.put( - AwsXrayPropagator.TRACE_HEADER_KEY, - "Root=1--d188f8fa79d48a391a778fa6;Parent=53995c3f42cd8ad8;Sampled=0"); - - assertThat(getSpanContext(xrayPropagator.extract(Context.current(), invalidHeaders, getter))) - .isSameAs(SpanContext.getInvalid()); - } - - @Test - void extract_InvalidTraceId_EpochPart_Missing() { - Map invalidHeaders = new LinkedHashMap<>(); - invalidHeaders.put( - AwsXrayPropagator.TRACE_HEADER_KEY, - "Root=1-d188f8fa79d48a391a778fa6;Parent=53995c3f42cd8ad8;Sampled=0"); - - assertThat(getSpanContext(xrayPropagator.extract(Context.current(), invalidHeaders, getter))) - .isSameAs(SpanContext.getInvalid()); - } - - @Test - void extract_InvalidTraceId_WrongVersion() { - Map carrier = new LinkedHashMap<>(); - carrier.put( - AwsXrayPropagator.TRACE_HEADER_KEY, - "Root=2-1a2a3a4a-d188f8fa79d48a391a778fa6;Parent=53995c3f42cd8ad8;Sampled=1;Foo=Bar"); - - assertThat(getSpanContext(xrayPropagator.extract(Context.current(), carrier, getter))) - .isSameAs(SpanContext.getInvalid()); - } - - private static Context withSpanContext(SpanContext spanContext, Context context) { - return context.with(Span.wrap(spanContext)); - } - - private static SpanContext getSpanContext(Context context) { - return Span.fromContext(context).getSpanContext(); - } -} diff --git a/settings.gradle.kts b/settings.gradle.kts index bdbc66e3bd4..ce5563a6007 100644 --- a/settings.gradle.kts +++ b/settings.gradle.kts @@ -30,7 +30,6 @@ include(":bom-alpha") include(":context") include(":dependencyManagement") include(":extensions:incubator") -include(":extensions:aws") include(":extensions:kotlin") include(":extensions:trace-propagators") include(":exporters:common") From dd012d94c353c091b9986f6bbcc7a7b45eae2368 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Thu, 17 Nov 2022 09:59:45 -0600 Subject: [PATCH 39/68] Bump testcontainers-bom from 1.17.5 to 1.17.6 (#4963) Bumps [testcontainers-bom](https://github.com/testcontainers/testcontainers-java) from 1.17.5 to 1.17.6. - [Release notes](https://github.com/testcontainers/testcontainers-java/releases) - [Changelog](https://github.com/testcontainers/testcontainers-java/blob/main/CHANGELOG.md) - [Commits](https://github.com/testcontainers/testcontainers-java/compare/1.17.5...1.17.6) --- updated-dependencies: - dependency-name: org.testcontainers:testcontainers-bom dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> --- dependencyManagement/build.gradle.kts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/dependencyManagement/build.gradle.kts b/dependencyManagement/build.gradle.kts index 55716a43036..0c1ec973b89 100644 --- a/dependencyManagement/build.gradle.kts +++ b/dependencyManagement/build.gradle.kts @@ -21,7 +21,7 @@ val DEPENDENCY_BOMS = listOf( "io.zipkin.brave:brave-bom:5.14.1", "io.zipkin.reporter2:zipkin-reporter-bom:2.16.3", "org.junit:junit-bom:5.9.1", - "org.testcontainers:testcontainers-bom:1.17.5", + "org.testcontainers:testcontainers-bom:1.17.6", "org.yaml:snakeyaml:1.33" ) From 0e41b1469d1fbc20c4fc5e7b59df0f4ac54330b6 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Thu, 17 Nov 2022 10:00:08 -0600 Subject: [PATCH 40/68] Bump grpc-bom from 1.50.2 to 1.51.0 (#4964) Bumps [grpc-bom](https://github.com/grpc/grpc-java) from 1.50.2 to 1.51.0. - [Release notes](https://github.com/grpc/grpc-java/releases) - [Commits](https://github.com/grpc/grpc-java/compare/v1.50.2...v1.51.0) --- updated-dependencies: - dependency-name: io.grpc:grpc-bom dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> --- dependencyManagement/build.gradle.kts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/dependencyManagement/build.gradle.kts b/dependencyManagement/build.gradle.kts index 0c1ec973b89..6f721a483b7 100644 --- a/dependencyManagement/build.gradle.kts +++ b/dependencyManagement/build.gradle.kts @@ -17,7 +17,7 @@ val DEPENDENCY_BOMS = listOf( "com.google.protobuf:protobuf-bom:3.21.9", "com.linecorp.armeria:armeria-bom:1.20.3", "com.squareup.okhttp3:okhttp-bom:4.10.0", - "io.grpc:grpc-bom:1.50.2", + "io.grpc:grpc-bom:1.51.0", "io.zipkin.brave:brave-bom:5.14.1", "io.zipkin.reporter2:zipkin-reporter-bom:2.16.3", "org.junit:junit-bom:5.9.1", From 4c95521faae43522079656ffd3146f59c03de151 Mon Sep 17 00:00:00 2001 From: Trask Stalnaker Date: Thu, 17 Nov 2022 15:45:46 -0800 Subject: [PATCH 41/68] Update apidiff to check newly created files too (#4967) --- .github/workflows/build.yml | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 548d92b10f0..d7b7d6d44e3 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -63,13 +63,15 @@ jobs: # The jApiCmp diff compares current to latest, which isn't appropriate for release branches if: ${{ !startsWith(github.ref_name, 'release/') && !startsWith(github.base_ref, 'release/') }} run: | - if git diff --quiet + # need to "git add" in case any generated files did not already exist + git add docs/apidiffs + if git diff --cached --quiet then echo "No diff detected." else echo "Diff detected - did you run './gradlew jApiCmp'?" - echo $(git diff --name-only) - echo $(git diff) + echo $(git diff --cached --name-only) + echo $(git diff --cached) exit 1 fi From 16054964e029c10afd47fafc65212895b435d002 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 21 Nov 2022 06:37:37 -0800 Subject: [PATCH 42/68] Bump equalsverifier from 3.11 to 3.11.1 (#4970) --- dependencyManagement/build.gradle.kts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/dependencyManagement/build.gradle.kts b/dependencyManagement/build.gradle.kts index 6f721a483b7..2ff2328b76c 100644 --- a/dependencyManagement/build.gradle.kts +++ b/dependencyManagement/build.gradle.kts @@ -91,7 +91,7 @@ val DEPENDENCIES = listOf( "io.opentelemetry.proto:opentelemetry-proto:0.19.0-alpha", "io.opentracing:opentracing-api:0.33.0", "junit:junit:4.13.2", - "nl.jqno.equalsverifier:equalsverifier:3.11", + "nl.jqno.equalsverifier:equalsverifier:3.11.1", "org.assertj:assertj-core:3.23.1", "org.awaitility:awaitility:4.2.0", "org.bouncycastle:bcpkix-jdk15on:1.70", From c9053b67356a9d1daf8a2c751c36ff4436e3f78b Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 21 Nov 2022 06:37:54 -0800 Subject: [PATCH 43/68] Bump nullaway from 0.10.4 to 0.10.5 (#4971) --- dependencyManagement/build.gradle.kts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/dependencyManagement/build.gradle.kts b/dependencyManagement/build.gradle.kts index 2ff2328b76c..a23abb0d0e2 100644 --- a/dependencyManagement/build.gradle.kts +++ b/dependencyManagement/build.gradle.kts @@ -82,7 +82,7 @@ val DEPENDENCIES = listOf( "com.lmax:disruptor:3.4.4", "com.sun.net.httpserver:http:20070405", "com.tngtech.archunit:archunit-junit5:1.0.0", - "com.uber.nullaway:nullaway:0.10.4", + "com.uber.nullaway:nullaway:0.10.5", // TODO(anuraaga): Skip 1.8 because of https://github.com/rohanpadhye/JQF/issues/172 "edu.berkeley.cs.jqf:jqf-fuzz:1.7", "eu.rekawek.toxiproxy:toxiproxy-java:2.1.7", From f004af9a14e37ab8ccdb44a579b7abd2c479e639 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 21 Nov 2022 10:20:10 -0600 Subject: [PATCH 44/68] Bump auto-value-annotations from 1.10 to 1.10.1 (#4969) Bumps [auto-value-annotations](https://github.com/google/auto) from 1.10 to 1.10.1. - [Release notes](https://github.com/google/auto/releases) - [Commits](https://github.com/google/auto/compare/auto-value-1.10...auto-value-1.10.1) --- updated-dependencies: - dependency-name: com.google.auto.value:auto-value-annotations dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> --- buildSrc/build.gradle.kts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/buildSrc/build.gradle.kts b/buildSrc/build.gradle.kts index 63d43ef97d2..218a42d1c24 100644 --- a/buildSrc/build.gradle.kts +++ b/buildSrc/build.gradle.kts @@ -12,7 +12,7 @@ repositories { } dependencies { - implementation("com.google.auto.value:auto-value-annotations:1.10") + implementation("com.google.auto.value:auto-value-annotations:1.10.1") // When updating, update above in plugins too implementation("com.diffplug.spotless:spotless-plugin-gradle:6.11.0") // Needed for japicmp but not automatically brought in for some reason. From e61d7c84a3c1c3eff5114bf507674c2b6659dcfa Mon Sep 17 00:00:00 2001 From: jason plumb <75337021+breedx-splk@users.noreply.github.com> Date: Mon, 21 Nov 2022 14:53:52 -0800 Subject: [PATCH 45/68] Zipkin exporter: Serialize EventData attributes as JSON (#4934) * serialize EventData attributes to json * remove import * fix test * address code review comments. * safety first --- .../zipkin/EventDataToAnnotation.java | 48 ++++++++++++++++++ .../zipkin/OtelToZipkinSpanTransformer.java | 8 +-- .../zipkin/EventDataToAnnotationTest.java | 49 +++++++++++++++++++ .../ZipkinSpanExporterEndToEndHttpTest.java | 4 +- .../exporter/zipkin/ZipkinTestUtil.java | 4 +- 5 files changed, 105 insertions(+), 8 deletions(-) create mode 100644 exporters/zipkin/src/main/java/io/opentelemetry/exporter/zipkin/EventDataToAnnotation.java create mode 100644 exporters/zipkin/src/test/java/io/opentelemetry/exporter/zipkin/EventDataToAnnotationTest.java diff --git a/exporters/zipkin/src/main/java/io/opentelemetry/exporter/zipkin/EventDataToAnnotation.java b/exporters/zipkin/src/main/java/io/opentelemetry/exporter/zipkin/EventDataToAnnotation.java new file mode 100644 index 00000000000..9374ddc3204 --- /dev/null +++ b/exporters/zipkin/src/main/java/io/opentelemetry/exporter/zipkin/EventDataToAnnotation.java @@ -0,0 +1,48 @@ +/* + * Copyright The OpenTelemetry Authors + * SPDX-License-Identifier: Apache-2.0 + */ + +package io.opentelemetry.exporter.zipkin; + +import static java.util.stream.Collectors.joining; + +import io.opentelemetry.api.common.Attributes; +import io.opentelemetry.sdk.trace.data.EventData; +import java.util.List; + +/** + * Converts an EventData instance to a String representation of that data, with attributes converted + * to JSON. + * + *

See the + * zipkin exporter spec for details. + */ +final class EventDataToAnnotation { + + private EventDataToAnnotation() {} + + static String apply(EventData eventData) { + String name = eventData.getName(); + String value = toJson(eventData.getAttributes()); + return "\"" + name + "\":" + value; + } + + private static String toJson(Attributes attributes) { + return attributes.asMap().entrySet().stream() + .map(entry -> "\"" + entry.getKey() + "\":" + toValue(entry.getValue())) + .collect(joining(",", "{", "}")); + } + + private static String toValue(Object o) { + if (o instanceof String) { + return "\"" + o + "\""; + } + if (o instanceof List) { + return ((List) o) + .stream().map(EventDataToAnnotation::toValue).collect(joining(",", "[", "]")); + } + return String.valueOf(o); + } +} diff --git a/exporters/zipkin/src/main/java/io/opentelemetry/exporter/zipkin/OtelToZipkinSpanTransformer.java b/exporters/zipkin/src/main/java/io/opentelemetry/exporter/zipkin/OtelToZipkinSpanTransformer.java index acb76c242ab..5fb82c7389f 100644 --- a/exporters/zipkin/src/main/java/io/opentelemetry/exporter/zipkin/OtelToZipkinSpanTransformer.java +++ b/exporters/zipkin/src/main/java/io/opentelemetry/exporter/zipkin/OtelToZipkinSpanTransformer.java @@ -41,7 +41,6 @@ final class OtelToZipkinSpanTransformer { static final String OTEL_STATUS_CODE = "otel.status_code"; static final AttributeKey STATUS_ERROR = stringKey("error"); private final Supplier ipAddressSupplier; - /** * Creates an instance of an OtelToZipkinSpanTransformer with the given Supplier that can produce * an InetAddress, which may be null. This value from this Supplier will be used when creating the @@ -125,8 +124,9 @@ Span generateSpan(SpanData spanData) { KEY_INSTRUMENTATION_LIBRARY_VERSION, instrumentationScopeInfo.getVersion()); } - for (EventData annotation : spanData.getEvents()) { - spanBuilder.addAnnotation(toEpochMicros(annotation.getEpochNanos()), annotation.getName()); + for (EventData eventData : spanData.getEvents()) { + String annotation = EventDataToAnnotation.apply(eventData); + spanBuilder.addAnnotation(toEpochMicros(eventData.getEpochNanos()), annotation); } int droppedEvents = spanData.getTotalRecordedEvents() - spanData.getEvents().size(); if (droppedEvents > 0) { @@ -136,7 +136,7 @@ Span generateSpan(SpanData spanData) { return spanBuilder.build(); } - private static String nullToEmpty(String value) { + private static String nullToEmpty(@Nullable String value) { return value != null ? value : ""; } diff --git a/exporters/zipkin/src/test/java/io/opentelemetry/exporter/zipkin/EventDataToAnnotationTest.java b/exporters/zipkin/src/test/java/io/opentelemetry/exporter/zipkin/EventDataToAnnotationTest.java new file mode 100644 index 00000000000..fa2cad0f284 --- /dev/null +++ b/exporters/zipkin/src/test/java/io/opentelemetry/exporter/zipkin/EventDataToAnnotationTest.java @@ -0,0 +1,49 @@ +/* + * Copyright The OpenTelemetry Authors + * SPDX-License-Identifier: Apache-2.0 + */ + +package io.opentelemetry.exporter.zipkin; + +import static org.assertj.core.api.AssertionsForClassTypes.assertThat; + +import io.opentelemetry.api.common.Attributes; +import io.opentelemetry.sdk.trace.data.EventData; +import org.junit.jupiter.api.Test; + +class EventDataToAnnotationTest { + + @Test + void basicConversion() { + + Attributes attrs = + Attributes.builder() + .put("v1", "v1") + .put("v2", 12L) + .put("v3", 123.45) + .put("v4", false) + .put("v5", "foo", "bar", "baz") + .put("v6", 1, 2, 3) + .put("v7", 1.23, 3.45) + .put("v8", true, false, true) + .build(); + String expected = + "\"cat\":{\"v1\":\"v1\",\"v2\":12,\"v3\":123.45,\"v4\":false,\"v5\":[\"foo\",\"bar\",\"baz\"],\"v6\":[1,2,3],\"v7\":[1.23,3.45],\"v8\":[true,false,true]}"; + EventData eventData = EventData.create(0, "cat", attrs); + + String result = EventDataToAnnotation.apply(eventData); + + assertThat(result).isEqualTo(expected); + } + + @Test + void empty() { + Attributes attrs = Attributes.empty(); + String expected = "\"dog\":{}"; + EventData eventData = EventData.create(0, "dog", attrs); + + String result = EventDataToAnnotation.apply(eventData); + + assertThat(result).isEqualTo(expected); + } +} diff --git a/exporters/zipkin/src/test/java/io/opentelemetry/exporter/zipkin/ZipkinSpanExporterEndToEndHttpTest.java b/exporters/zipkin/src/test/java/io/opentelemetry/exporter/zipkin/ZipkinSpanExporterEndToEndHttpTest.java index b0af4f2cf23..50fdabf24f4 100644 --- a/exporters/zipkin/src/test/java/io/opentelemetry/exporter/zipkin/ZipkinSpanExporterEndToEndHttpTest.java +++ b/exporters/zipkin/src/test/java/io/opentelemetry/exporter/zipkin/ZipkinSpanExporterEndToEndHttpTest.java @@ -230,8 +230,8 @@ private static Span buildZipkinSpan(InetAddress localAddress, String traceId) { .timestamp(START_EPOCH_NANOS / 1000) .duration((END_EPOCH_NANOS / 1000) - (START_EPOCH_NANOS / 1000)) .localEndpoint(Endpoint.newBuilder().serviceName(SERVICE_NAME).ip(localAddress).build()) - .addAnnotation(RECEIVED_TIMESTAMP_NANOS / 1000, "RECEIVED") - .addAnnotation(SENT_TIMESTAMP_NANOS / 1000, "SENT") + .addAnnotation(RECEIVED_TIMESTAMP_NANOS / 1000, "\"RECEIVED\":{}") + .addAnnotation(SENT_TIMESTAMP_NANOS / 1000, "\"SENT\":{}") .putTag(OtelToZipkinSpanTransformer.OTEL_STATUS_CODE, "OK") .build(); } diff --git a/exporters/zipkin/src/test/java/io/opentelemetry/exporter/zipkin/ZipkinTestUtil.java b/exporters/zipkin/src/test/java/io/opentelemetry/exporter/zipkin/ZipkinTestUtil.java index 1c96e034eeb..5f8ffe8c4a9 100644 --- a/exporters/zipkin/src/test/java/io/opentelemetry/exporter/zipkin/ZipkinTestUtil.java +++ b/exporters/zipkin/src/test/java/io/opentelemetry/exporter/zipkin/ZipkinTestUtil.java @@ -74,7 +74,7 @@ static Span.Builder zipkinSpanBuilder(Span.Kind kind, InetAddress localIp) { .timestamp(1505855794000000L + 194009601L / 1000) .duration((1505855799000000L + 465726528L / 1000) - (1505855794000000L + 194009601L / 1000)) .localEndpoint(Endpoint.newBuilder().ip(localIp).serviceName("tweetiebird").build()) - .addAnnotation(1505855799000000L + 433901068L / 1000, "RECEIVED") - .addAnnotation(1505855799000000L + 459486280L / 1000, "SENT"); + .addAnnotation(1505855799000000L + 433901068L / 1000, "\"RECEIVED\":{}") + .addAnnotation(1505855799000000L + 459486280L / 1000, "\"SENT\":{}"); } } From c4d0d862babcb976651c4b3e9a423d5d5e7854df Mon Sep 17 00:00:00 2001 From: jack-berg <34418638+jack-berg@users.noreply.github.com> Date: Tue, 22 Nov 2022 08:40:21 -0600 Subject: [PATCH 46/68] Add support for EC mTLS keys (#4920) * Add support for EC mTlS keys * Revert change to integration test --- .../exporter/internal/TlsUtil.java | 41 ++++++++++-- .../exporter/internal/TlsUtilTest.java | 63 +++++++++++++++++++ 2 files changed, 99 insertions(+), 5 deletions(-) create mode 100644 exporters/common/src/test/java/io/opentelemetry/exporter/internal/TlsUtilTest.java diff --git a/exporters/common/src/main/java/io/opentelemetry/exporter/internal/TlsUtil.java b/exporters/common/src/main/java/io/opentelemetry/exporter/internal/TlsUtil.java index cd529eba68f..83d9d89f2f1 100644 --- a/exporters/common/src/main/java/io/opentelemetry/exporter/internal/TlsUtil.java +++ b/exporters/common/src/main/java/io/opentelemetry/exporter/internal/TlsUtil.java @@ -6,6 +6,7 @@ package io.opentelemetry.exporter.internal; import static java.util.Objects.requireNonNull; +import static java.util.stream.Collectors.joining; import java.io.ByteArrayInputStream; import java.io.IOException; @@ -48,6 +49,21 @@ public final class TlsUtil { private static final String PEM_KEY_HEADER = "-----BEGIN PRIVATE KEY-----"; private static final String PEM_KEY_FOOTER = "-----END PRIVATE KEY-----"; + private static final List SUPPORTED_KEY_FACTORIES; + + static { + SUPPORTED_KEY_FACTORIES = new ArrayList<>(); + try { + SUPPORTED_KEY_FACTORIES.add(KeyFactory.getInstance("RSA")); + } catch (NoSuchAlgorithmException e) { + // Ignore and continue + } + try { + SUPPORTED_KEY_FACTORIES.add(KeyFactory.getInstance("EC")); + } catch (NoSuchAlgorithmException e) { + // Ignore and continue + } + } private TlsUtil() {} @@ -83,9 +99,8 @@ public static X509KeyManager keyManager(byte[] privateKeyPem, byte[] certificate try { KeyStore ks = KeyStore.getInstance(KeyStore.getDefaultType()); ks.load(null); - KeyFactory factory = KeyFactory.getInstance("RSA"); PKCS8EncodedKeySpec keySpec = new PKCS8EncodedKeySpec(decodePem(privateKeyPem)); - PrivateKey key = factory.generatePrivate(keySpec); + PrivateKey key = generatePrivateKey(keySpec, SUPPORTED_KEY_FACTORIES); CertificateFactory cf = CertificateFactory.getInstance("X.509"); @@ -106,12 +121,27 @@ public static X509KeyManager keyManager(byte[] privateKeyPem, byte[] certificate | KeyStoreException | IOException | NoSuchAlgorithmException - | UnrecoverableKeyException - | InvalidKeySpecException e) { + | UnrecoverableKeyException e) { throw new SSLException("Could not build KeyManagerFactory from clientKeysPem.", e); } } + // Visible for testing + static PrivateKey generatePrivateKey(PKCS8EncodedKeySpec keySpec, List keyFactories) + throws SSLException { + // Try to generate key using supported key factories + for (KeyFactory factory : keyFactories) { + try { + return factory.generatePrivate(keySpec); + } catch (InvalidKeySpecException e) { + // Ignore + } + } + throw new SSLException( + "Unable to generate key from supported algorithms: " + + keyFactories.stream().map(KeyFactory::getAlgorithm).collect(joining(",", "[", "]"))); + } + /** Returns a {@link TrustManager} for the given trusted certificates. */ public static X509TrustManager trustManager(byte[] trustedCertificatesPem) throws SSLException { requireNonNull(trustedCertificatesPem, "trustedCertificatesPem"); @@ -140,7 +170,8 @@ public static X509TrustManager trustManager(byte[] trustedCertificatesPem) throw // We catch linkage error to provide a better exception message on Android. // https://github.com/open-telemetry/opentelemetry-java/issues/4533 @IgnoreJRERequirement - private static byte[] decodePem(byte[] pem) { + // Visible for testing + static byte[] decodePem(byte[] pem) { String pemStr = new String(pem, StandardCharsets.UTF_8).trim(); if (!pemStr.startsWith(PEM_KEY_HEADER) || !pemStr.endsWith(PEM_KEY_FOOTER)) { // pem may already be a decoded binary key, try to use it. diff --git a/exporters/common/src/test/java/io/opentelemetry/exporter/internal/TlsUtilTest.java b/exporters/common/src/test/java/io/opentelemetry/exporter/internal/TlsUtilTest.java new file mode 100644 index 00000000000..caca1dee1ab --- /dev/null +++ b/exporters/common/src/test/java/io/opentelemetry/exporter/internal/TlsUtilTest.java @@ -0,0 +1,63 @@ +/* + * Copyright The OpenTelemetry Authors + * SPDX-License-Identifier: Apache-2.0 + */ + +package io.opentelemetry.exporter.internal; + +import static org.assertj.core.api.Assertions.assertThatCode; + +import com.linecorp.armeria.internal.common.util.SelfSignedCertificate; +import java.security.KeyFactory; +import java.security.cert.CertificateException; +import java.security.spec.PKCS8EncodedKeySpec; +import java.time.Instant; +import java.util.Collections; +import java.util.Date; +import javax.net.ssl.SSLException; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; + +class TlsUtilTest { + + private SelfSignedCertificate rsaCertificate; + private SelfSignedCertificate ecCertificate; + + @BeforeEach + void setup() throws CertificateException { + rsaCertificate = + new SelfSignedCertificate(Date.from(Instant.now()), Date.from(Instant.now()), "RSA", 2048); + ecCertificate = + new SelfSignedCertificate(Date.from(Instant.now()), Date.from(Instant.now()), "EC", 256); + } + + @Test + void keyManager_Rsa() { + assertThatCode( + () -> + TlsUtil.keyManager( + rsaCertificate.key().getEncoded(), rsaCertificate.cert().getEncoded())) + .doesNotThrowAnyException(); + } + + @Test + void keyManager_Ec() { + assertThatCode( + () -> + TlsUtil.keyManager( + ecCertificate.key().getEncoded(), ecCertificate.cert().getEncoded())) + .doesNotThrowAnyException(); + } + + @Test + void generatePrivateKey_Invalid() { + PKCS8EncodedKeySpec keySpec = + new PKCS8EncodedKeySpec(TlsUtil.decodePem(rsaCertificate.key().getEncoded())); + assertThatCode( + () -> + TlsUtil.generatePrivateKey( + keySpec, Collections.singletonList(KeyFactory.getInstance("EC")))) + .isInstanceOf(SSLException.class) + .hasMessage("Unable to generate key from supported algorithms: [EC]"); + } +} From 8e3e14ad29904e0106e896882ca04ffdf528b6ed Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Tue, 22 Nov 2022 09:14:03 -0600 Subject: [PATCH 47/68] Bump org.graalvm.buildtools.native from 0.9.17 to 0.9.18 (#4976) Bumps [org.graalvm.buildtools.native](https://github.com/graalvm/native-build-tools) from 0.9.17 to 0.9.18. - [Release notes](https://github.com/graalvm/native-build-tools/releases) - [Commits](https://github.com/graalvm/native-build-tools/compare/0.9.17...0.9.18) --- updated-dependencies: - dependency-name: org.graalvm.buildtools.native dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> --- settings.gradle.kts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/settings.gradle.kts b/settings.gradle.kts index ce5563a6007..3dcb6964cab 100644 --- a/settings.gradle.kts +++ b/settings.gradle.kts @@ -5,7 +5,7 @@ pluginManagement { id("com.gradle.enterprise") version "3.11.4" id("io.github.gradle-nexus.publish-plugin") version "1.1.0" id("org.jetbrains.kotlin.jvm") version "1.7.21" - id("org.graalvm.buildtools.native") version "0.9.17" + id("org.graalvm.buildtools.native") version "0.9.18" } } From 292c11e91f2b133bfd77c0c7bf4cbcae7caf4550 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Tue, 22 Nov 2022 09:15:31 -0600 Subject: [PATCH 48/68] Bump archunit-junit5 from 1.0.0 to 1.0.1 (#4974) Bumps [archunit-junit5](https://github.com/TNG/ArchUnit) from 1.0.0 to 1.0.1. - [Release notes](https://github.com/TNG/ArchUnit/releases) - [Commits](https://github.com/TNG/ArchUnit/compare/v1.0.0...v1.0.1) --- updated-dependencies: - dependency-name: com.tngtech.archunit:archunit-junit5 dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> --- dependencyManagement/build.gradle.kts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/dependencyManagement/build.gradle.kts b/dependencyManagement/build.gradle.kts index a23abb0d0e2..aa8bf15edcd 100644 --- a/dependencyManagement/build.gradle.kts +++ b/dependencyManagement/build.gradle.kts @@ -81,7 +81,7 @@ val DEPENDENCIES = listOf( "com.google.guava:guava-beta-checker:1.0", "com.lmax:disruptor:3.4.4", "com.sun.net.httpserver:http:20070405", - "com.tngtech.archunit:archunit-junit5:1.0.0", + "com.tngtech.archunit:archunit-junit5:1.0.1", "com.uber.nullaway:nullaway:0.10.5", // TODO(anuraaga): Skip 1.8 because of https://github.com/rohanpadhye/JQF/issues/172 "edu.berkeley.cs.jqf:jqf-fuzz:1.7", From c95723e5265721f6124fc43d75d60583c5742b43 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Tue, 22 Nov 2022 09:47:48 -0600 Subject: [PATCH 49/68] Bump jackson-bom from 2.14.0 to 2.14.1 (#4975) Bumps [jackson-bom](https://github.com/FasterXML/jackson-bom) from 2.14.0 to 2.14.1. - [Release notes](https://github.com/FasterXML/jackson-bom/releases) - [Commits](https://github.com/FasterXML/jackson-bom/compare/jackson-bom-2.14.0...jackson-bom-2.14.1) --- updated-dependencies: - dependency-name: com.fasterxml.jackson:jackson-bom dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> --- dependencyManagement/build.gradle.kts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/dependencyManagement/build.gradle.kts b/dependencyManagement/build.gradle.kts index aa8bf15edcd..e8f36e59e4a 100644 --- a/dependencyManagement/build.gradle.kts +++ b/dependencyManagement/build.gradle.kts @@ -12,7 +12,7 @@ val dependencyVersions = hashMapOf() rootProject.extra["versions"] = dependencyVersions val DEPENDENCY_BOMS = listOf( - "com.fasterxml.jackson:jackson-bom:2.14.0", + "com.fasterxml.jackson:jackson-bom:2.14.1", "com.google.guava:guava-bom:31.1-jre", "com.google.protobuf:protobuf-bom:3.21.9", "com.linecorp.armeria:armeria-bom:1.20.3", From 25c92fb6ac7169aa05c95511171210ceaa78cc02 Mon Sep 17 00:00:00 2001 From: jack-berg <34418638+jack-berg@users.noreply.github.com> Date: Tue, 22 Nov 2022 12:58:44 -0600 Subject: [PATCH 50/68] Remove outdated todo (#4978) --- .../exporter/internal/otlp/logs/ResourceLogsMarshaler.java | 2 -- 1 file changed, 2 deletions(-) diff --git a/exporters/otlp/common/src/main/java/io/opentelemetry/exporter/internal/otlp/logs/ResourceLogsMarshaler.java b/exporters/otlp/common/src/main/java/io/opentelemetry/exporter/internal/otlp/logs/ResourceLogsMarshaler.java index 4e2ee16e7e1..76767e8266e 100644 --- a/exporters/otlp/common/src/main/java/io/opentelemetry/exporter/internal/otlp/logs/ResourceLogsMarshaler.java +++ b/exporters/otlp/common/src/main/java/io/opentelemetry/exporter/internal/otlp/logs/ResourceLogsMarshaler.java @@ -96,8 +96,6 @@ private static int calculateSize( groupByResourceAndScope(Collection logs) { return MarshalerUtil.groupByResourceAndScope( logs, - // TODO(anuraaga): Replace with an internal SdkData type of interface that exposes these - // two. LogRecordData::getResource, LogRecordData::getInstrumentationScopeInfo, LogMarshaler::create); From f6deb4c1b7b9ed250f3f7cda992a012b6e738af2 Mon Sep 17 00:00:00 2001 From: jack-berg <34418638+jack-berg@users.noreply.github.com> Date: Tue, 22 Nov 2022 13:55:27 -0600 Subject: [PATCH 51/68] Remove japicmp exception for log SDK changes (#4977) --- .../otel.japicmp-conventions.gradle.kts | 34 ------------------- 1 file changed, 34 deletions(-) diff --git a/buildSrc/src/main/kotlin/otel.japicmp-conventions.gradle.kts b/buildSrc/src/main/kotlin/otel.japicmp-conventions.gradle.kts index ab182cb40de..37b176efb7b 100644 --- a/buildSrc/src/main/kotlin/otel.japicmp-conventions.gradle.kts +++ b/buildSrc/src/main/kotlin/otel.japicmp-conventions.gradle.kts @@ -1,9 +1,7 @@ import com.google.auto.value.AutoValue import japicmp.model.JApiChangeStatus -import japicmp.model.JApiClass import japicmp.model.JApiCompatibility import japicmp.model.JApiCompatibilityChange -import japicmp.model.JApiConstructor import japicmp.model.JApiMethod import me.champeau.gradle.japicmp.JapicmpTask import me.champeau.gradle.japicmp.report.Severity @@ -40,9 +38,6 @@ class AllowDefaultMethodRule : AbstractRecordingSeenMembers() { if (isAbstractMethodOnAutoValue(member, change)) { continue } - if (isLogRename(member)) { - continue - } if (!change.isSourceCompatible) { return Violation.error(member, "Not source compatible") } @@ -64,35 +59,6 @@ class AllowDefaultMethodRule : AbstractRecordingSeenMembers() { member is JApiMethod && member.getjApiClass().newClass.get().getAnnotation(AutoValue::class.java) != null } - - /** - * Check if the change is related to log related renames. - */ - // TODO(jack-berg): remove after 1.19.0. - fun isLogRename(member: JApiCompatibility): Boolean { - try { - if (member is JApiMethod) { - val longName = member.oldMethod.get().longName - return longName.matches(".*OpenTelemetrySdk\\.getSdkLogEmitterProvider.*".toRegex()) || - longName.matches(".*OpenTelemetrySdkBuilder\\.setLogEmitterProvider.*".toRegex()) || - longName.matches(".*AutoConfigurationCustomizer\\.addLogExporterCustomizer.*".toRegex()) || - longName.matches(".*AutoConfigurationCustomizer\\.addLogEmitterProviderCustomizer.*".toRegex()) || - longName.matches(".*ConfigurableLogExporterProvider.*".toRegex()) || - longName.matches(".*SystemOutLogExporter.*".toRegex()) || - longName.matches(".*OtlpJsonLoggingLogExporter.*".toRegex()) - } else if (member is JApiClass) { - val fqcn = member.fullyQualifiedName - return fqcn.matches(".*SystemOutLogExporter".toRegex()) || - fqcn.matches(".*ConfigurableLogExporterProvider".toRegex()) || - fqcn.matches(".*OtlpJsonLoggingLogExporter".toRegex()) - } else if (member is JApiConstructor) { - return member.oldConstructor.get().longName.matches(".*SystemOutLogExporter.*".toRegex()) - } - return false - } catch (e: IllegalStateException) { - return false - } - } } /** From 41c5fbc19a508d41f46f0d2f3d7aa3df9fd4c9d5 Mon Sep 17 00:00:00 2001 From: Carlos Alberto Cortez Date: Thu, 24 Nov 2022 19:53:09 +0100 Subject: [PATCH 52/68] OpenTracing Shim: Properly set the status based on the error tag. (#4962) --- .../opentracingshim/SpanBuilderShim.java | 6 +- .../opentracingshim/SpanShim.java | 4 +- .../opentracingshim/SpanBuilderShimTest.java | 68 +++++++++++++++++++ .../opentracingshim/SpanShimTest.java | 28 ++++++++ 4 files changed, 101 insertions(+), 5 deletions(-) diff --git a/opentracing-shim/src/main/java/io/opentelemetry/opentracingshim/SpanBuilderShim.java b/opentracing-shim/src/main/java/io/opentelemetry/opentracingshim/SpanBuilderShim.java index ac3c1f62c17..2551e83d7d8 100644 --- a/opentracing-shim/src/main/java/io/opentelemetry/opentracingshim/SpanBuilderShim.java +++ b/opentracing-shim/src/main/java/io/opentelemetry/opentracingshim/SpanBuilderShim.java @@ -44,7 +44,7 @@ final class SpanBuilderShim extends BaseShimObject implements SpanBuilder { private final List spanBuilderAttributeValues = new ArrayList<>(); @Nullable private SpanKind spanKind; - private boolean error; + @Nullable private Boolean error; private long startTimestampMicros; private static final Attributes CHILD_OF_ATTR = @@ -249,8 +249,8 @@ public Span start() { } io.opentelemetry.api.trace.Span span = builder.startSpan(); - if (error) { - span.setStatus(StatusCode.ERROR); + if (error != null) { + span.setStatus(error ? StatusCode.ERROR : StatusCode.OK); } return new SpanShim(telemetryInfo(), span, baggage); 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 10adf19adf5..c12858c72ff 100644 --- a/opentracing-shim/src/main/java/io/opentelemetry/opentracingshim/SpanShim.java +++ b/opentracing-shim/src/main/java/io/opentelemetry/opentracingshim/SpanShim.java @@ -86,7 +86,7 @@ public Span setTag(String key, String value) { // TODO: confirm we can safely ignore span.kind after Span was created // https://github.com/bogdandrutu/opentelemetry/issues/42 } else if (Tags.ERROR.getKey().equals(key)) { - StatusCode canonicalCode = Boolean.parseBoolean(value) ? StatusCode.ERROR : StatusCode.UNSET; + StatusCode canonicalCode = Boolean.parseBoolean(value) ? StatusCode.ERROR : StatusCode.OK; span.setStatus(canonicalCode); } else { span.setAttribute(key, value); @@ -98,7 +98,7 @@ public Span setTag(String key, String value) { @Override public Span setTag(String key, boolean value) { if (Tags.ERROR.getKey().equals(key)) { - StatusCode canonicalCode = value ? StatusCode.ERROR : StatusCode.UNSET; + StatusCode canonicalCode = value ? StatusCode.ERROR : StatusCode.OK; span.setStatus(canonicalCode); } else { span.setAttribute(key, value); 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 16ff9cfeb99..a915cee1272 100644 --- a/opentracing-shim/src/test/java/io/opentelemetry/opentracingshim/SpanBuilderShimTest.java +++ b/opentracing-shim/src/test/java/io/opentelemetry/opentracingshim/SpanBuilderShimTest.java @@ -11,6 +11,7 @@ import io.opentelemetry.api.GlobalOpenTelemetry; import io.opentelemetry.api.common.AttributeKey; import io.opentelemetry.api.common.Attributes; +import io.opentelemetry.api.trace.SpanContext; import io.opentelemetry.api.trace.SpanKind; import io.opentelemetry.api.trace.Tracer; import io.opentelemetry.context.Context; @@ -18,10 +19,12 @@ import io.opentelemetry.sdk.trace.SdkTracerProvider; import io.opentelemetry.sdk.trace.data.LinkData; import io.opentelemetry.sdk.trace.data.SpanData; +import io.opentelemetry.sdk.trace.data.StatusData; import io.opentelemetry.sdk.trace.samplers.Sampler; import io.opentelemetry.sdk.trace.samplers.SamplingResult; import io.opentelemetry.semconv.trace.attributes.SemanticAttributes; import io.opentracing.References; +import io.opentracing.tag.Tags; import java.math.BigInteger; import java.util.List; import org.junit.jupiter.api.BeforeEach; @@ -41,6 +44,23 @@ void setUp() { GlobalOpenTelemetry.resetForTest(); } + @Test + void default_values() { + SpanShim span = (SpanShim) new SpanBuilderShim(telemetryInfo, SPAN_NAME).start(); + try { + SpanData spanData = ((ReadableSpan) span.getSpan()).toSpanData(); + assertThat(spanData.getName()).isEqualTo(SPAN_NAME); + assertThat(spanData.getStatus()).isEqualTo(StatusData.unset()); + assertThat(spanData.getSpanContext()).isNotEqualTo(SpanContext.getInvalid()); + assertThat(spanData.getKind()).isEqualTo(SpanKind.INTERNAL); + assertThat(spanData.getAttributes().size()).isEqualTo(0); + assertThat(spanData.getEvents()).hasSize(0); + assertThat(spanData.getLinks()).hasSize(0); + } finally { + span.finish(); + } + } + @Test void parent_single() { SpanShim parentSpan = (SpanShim) new SpanBuilderShim(telemetryInfo, SPAN_NAME).start(); @@ -297,6 +317,54 @@ void withStartTimestamp() { assertThat(spanData.getStartEpochNanos()).isEqualTo(micros * 1000L); } + @Test + void setAttribute_errorAsBoolean() { + SpanShim span1 = + (SpanShim) + new SpanBuilderShim(telemetryInfo, SPAN_NAME) + .withTag(Tags.ERROR.getKey(), true) + .start(); + SpanShim span2 = + (SpanShim) + new SpanBuilderShim(telemetryInfo, SPAN_NAME) + .withTag(Tags.ERROR.getKey(), false) + .start(); + try { + SpanData spanData1 = ((ReadableSpan) span1.getSpan()).toSpanData(); + assertThat(spanData1.getStatus()).isEqualTo(StatusData.error()); + + SpanData spanData2 = ((ReadableSpan) span2.getSpan()).toSpanData(); + assertThat(spanData2.getStatus()).isEqualTo(StatusData.ok()); + } finally { + span1.finish(); + span2.finish(); + } + } + + @Test + void setAttribute_errorAsString() { + SpanShim span1 = + (SpanShim) + new SpanBuilderShim(telemetryInfo, SPAN_NAME) + .withTag(Tags.ERROR.getKey(), "tRuE") + .start(); + SpanShim span2 = + (SpanShim) + new SpanBuilderShim(telemetryInfo, SPAN_NAME) + .withTag(Tags.ERROR.getKey(), "FaLsE") + .start(); + try { + SpanData spanData1 = ((ReadableSpan) span1.getSpan()).toSpanData(); + assertThat(spanData1.getStatus()).isEqualTo(StatusData.error()); + + SpanData spanData2 = ((ReadableSpan) span2.getSpan()).toSpanData(); + assertThat(spanData2.getStatus()).isEqualTo(StatusData.ok()); + } finally { + span1.finish(); + span2.finish(); + } + } + @Test void setAttribute_unrecognizedType() { SpanShim span = diff --git a/opentracing-shim/src/test/java/io/opentelemetry/opentracingshim/SpanShimTest.java b/opentracing-shim/src/test/java/io/opentelemetry/opentracingshim/SpanShimTest.java index 1d304e04c32..66b9a21be25 100644 --- a/opentracing-shim/src/test/java/io/opentelemetry/opentracingshim/SpanShimTest.java +++ b/opentracing-shim/src/test/java/io/opentelemetry/opentracingshim/SpanShimTest.java @@ -15,8 +15,10 @@ import io.opentelemetry.sdk.trace.SdkTracerProvider; import io.opentelemetry.sdk.trace.data.EventData; import io.opentelemetry.sdk.trace.data.SpanData; +import io.opentelemetry.sdk.trace.data.StatusData; import io.opentelemetry.semconv.trace.attributes.SemanticAttributes; import io.opentracing.log.Fields; +import io.opentracing.tag.Tags; import java.math.BigInteger; import java.util.HashMap; import java.util.Map; @@ -60,6 +62,32 @@ void context_simple() { assertThat(contextShim.baggageItems().iterator().hasNext()).isFalse(); } + @Test + void setAttribute_errorAsBoolean() { + SpanShim spanShim = new SpanShim(telemetryInfo, span); + spanShim.setTag(Tags.ERROR.getKey(), true); + + SpanData spanData = ((ReadableSpan) span).toSpanData(); + assertThat(spanData.getStatus()).isEqualTo(StatusData.error()); + + spanShim.setTag(Tags.ERROR.getKey(), false); + spanData = ((ReadableSpan) span).toSpanData(); + assertThat(spanData.getStatus()).isEqualTo(StatusData.ok()); + } + + @Test + void setAttribute_errorAsString() { + SpanShim spanShim = new SpanShim(telemetryInfo, span); + spanShim.setTag(Tags.ERROR.getKey(), "tRuE"); + + SpanData spanData = ((ReadableSpan) span).toSpanData(); + assertThat(spanData.getStatus()).isEqualTo(StatusData.error()); + + spanShim.setTag(Tags.ERROR.getKey(), "FaLsE"); + spanData = ((ReadableSpan) span).toSpanData(); + assertThat(spanData.getStatus()).isEqualTo(StatusData.ok()); + } + @Test void setAttribute_unrecognizedType() { SpanShim spanShim = new SpanShim(telemetryInfo, span); From c8a382618eea6d8e7defd266c2a39098401065e3 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Fri, 25 Nov 2022 13:06:56 -0800 Subject: [PATCH 53/68] Bump com.diffplug.spotless from 6.11.0 to 6.12.0 (#4986) Bumps com.diffplug.spotless from 6.11.0 to 6.12.0. --- updated-dependencies: - dependency-name: com.diffplug.spotless dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> --- buildSrc/build.gradle.kts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/buildSrc/build.gradle.kts b/buildSrc/build.gradle.kts index 218a42d1c24..4a483ed5f35 100644 --- a/buildSrc/build.gradle.kts +++ b/buildSrc/build.gradle.kts @@ -2,7 +2,7 @@ plugins { `kotlin-dsl` // When updating, update below in dependencies too - id("com.diffplug.spotless") version "6.11.0" + id("com.diffplug.spotless") version "6.12.0" } repositories { From 1209826ef1dc4e829f0b2b9c5e2b9af799e6cf7c Mon Sep 17 00:00:00 2001 From: Trask Stalnaker Date: Fri, 25 Nov 2022 13:11:32 -0800 Subject: [PATCH 54/68] GitHub actions sync (#4966) * Sync * Sync * chmod * Fix misspelling --- .../markdown-link-check-config.json | 0 .github/scripts/draft-change-log-entries.sh | 34 +++++++ .../scripts/markdown-link-check-with-retry.sh | 2 +- .../scripts/merge-change-log-after-release.sh | 44 +++++++++ .github/workflows/backport.yml | 6 +- .github/workflows/build.yml | 19 ++-- .github/workflows/codeql-daily.yml | 6 +- .github/workflows/prepare-patch-release.yml | 6 +- .github/workflows/prepare-release-branch.yml | 21 ++-- .github/workflows/release.yml | 98 ++++++++----------- .github/workflows/reusable-misspell-check.yml | 2 +- .../reusable-open-issue-on-failure.yml | 4 +- 12 files changed, 150 insertions(+), 92 deletions(-) rename .github/{scripts => config}/markdown-link-check-config.json (100%) create mode 100755 .github/scripts/draft-change-log-entries.sh create mode 100755 .github/scripts/merge-change-log-after-release.sh diff --git a/.github/scripts/markdown-link-check-config.json b/.github/config/markdown-link-check-config.json similarity index 100% rename from .github/scripts/markdown-link-check-config.json rename to .github/config/markdown-link-check-config.json diff --git a/.github/scripts/draft-change-log-entries.sh b/.github/scripts/draft-change-log-entries.sh new file mode 100755 index 00000000000..d62f210bfe9 --- /dev/null +++ b/.github/scripts/draft-change-log-entries.sh @@ -0,0 +1,34 @@ +#!/bin/bash -e + +version=$("$(dirname "$0")/get-version.sh") + +if [[ $version =~ ([0-9]+)\.([0-9]+)\.0 ]]; then + major="${BASH_REMATCH[1]}" + minor="${BASH_REMATCH[2]}" +else + echo "unexpected version: $version" + exit 1 +fi + +if [[ $minor == 0 ]]; then + prior_major=$((major - 1)) + prior_minor=$(sed -n "s/^## Version $prior_major\.\([0-9]\+\)\..*/\1/p" CHANGELOG.md | head -1) + if [[ -z $prior_minor ]]; then + # assuming this is the first release + range= + else + range="v$prior_major.$prior_minor.0..HEAD" + fi +else + range="v$major.$((minor - 1)).0..HEAD" +fi + +echo "## Unreleased" +echo + +git log --reverse \ + --perl-regexp \ + --author='^(?!dependabot\[bot\] )' \ + --pretty=format:"- %s" \ + "$range" \ + | sed -E 's,\(#([0-9]+)\)$,\n ([#\1](https://github.com/open-telemetry/opentelemetry-java/pull/\1)),' diff --git a/.github/scripts/markdown-link-check-with-retry.sh b/.github/scripts/markdown-link-check-with-retry.sh index 109146abfec..9a81e8df95b 100755 --- a/.github/scripts/markdown-link-check-with-retry.sh +++ b/.github/scripts/markdown-link-check-with-retry.sh @@ -6,7 +6,7 @@ retry_count=3 for file in "$@"; do for i in $(seq 1 $retry_count); do - if markdown-link-check --config "$(dirname "$0")/markdown-link-check-config.json" \ + if markdown-link-check --config "$(dirname "$0")/../config/markdown-link-check-config.json" \ "$file"; then break elif [[ $i -eq $retry_count ]]; then diff --git a/.github/scripts/merge-change-log-after-release.sh b/.github/scripts/merge-change-log-after-release.sh new file mode 100755 index 00000000000..1b95eeb8cb4 --- /dev/null +++ b/.github/scripts/merge-change-log-after-release.sh @@ -0,0 +1,44 @@ +#!/bin/bash -e + +# this script merges release notes for $VERSION into CHANGELOG.md +# the release date for $VERSION should be available in $RELEASE_DATE +# and the release notes for $VERSION should be available in /tmp/changelog-section.md + +if [[ $VERSION =~ ^[0-9]+\.[0-9]+\.0 ]]; then + # this was not a patch release, so the version exists already in the CHANGELOG.md + + # update the release date + sed -Ei "s/## Version $VERSION .*/## Version $VERSION ($RELEASE_DATE)/" CHANGELOG.md + + # the entries are copied over from the release branch to support workflows + # where change log entries may be updated after preparing the release branch + + { + # copy the portion above the release, up to and including the heading + sed -n "0,/^## Version $VERSION /p" CHANGELOG.md + # copy the release notes for $VERSION + cat /tmp/changelog-section.md + # copy the portion below the release + sed -n "0,/^## Version $VERSION /d;0,/^## Version /{/^## Version/!d};p" CHANGELOG.md + } > /tmp/CHANGELOG.md + + # update the real CHANGELOG.md + cp /tmp/CHANGELOG.md CHANGELOG.md + +else + # this was a patch release, so the version does not exist already in the CHANGELOG.md + + { + # copy the portion above the top-most release, not including the heading + sed -n "0,/^## Version /{ /^## Version /!p }" CHANGELOG.md + # add the heading + echo "## Version $VERSION ($RELEASE_DATE)" + # copy the release notes for $VERSION + cat /tmp/changelog-section.md + # copy the portion starting from the top-most release + sed -n "/^## Version /,\$p" CHANGELOG.md + } > /tmp/CHANGELOG.md + + # update the real CHANGELOG.md + cp /tmp/CHANGELOG.md CHANGELOG.md +fi diff --git a/.github/workflows/backport.yml b/.github/workflows/backport.yml index 2759b639876..fcff72284da 100644 --- a/.github/workflows/backport.yml +++ b/.github/workflows/backport.yml @@ -28,16 +28,16 @@ jobs: env: NUMBER: ${{ github.event.inputs.number }} # not using secrets.GITHUB_TOKEN since pull requests from that token do not run workflows - GITHUB_TOKEN: ${{ secrets.BOT_TOKEN }} + GH_TOKEN: ${{ secrets.BOT_TOKEN }} run: | commit=$(gh pr view $NUMBER --json mergeCommit --jq .mergeCommit.oid) title=$(gh pr view $NUMBER --json title --jq .title) branch="opentelemetrybot/backport-${NUMBER}-to-${GITHUB_REF_NAME//\//-}" + git checkout -b $branch git cherry-pick $commit - git push origin HEAD:$branch + git push --set-upstream origin $branch gh pr create --title "[$GITHUB_REF_NAME] $title" \ --body "Clean cherry-pick of #$NUMBER to the \`$GITHUB_REF_NAME\` branch." \ - --head $branch \ --base $GITHUB_REF_NAME diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index d7b7d6d44e3..d79e5f227c5 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -34,8 +34,6 @@ jobs: coverage: true steps: - uses: actions/checkout@v3 - with: - fetch-depth: 0 - id: setup-java-test name: Set up Java ${{ matrix.test-java-version }} for tests @@ -85,13 +83,12 @@ jobs: path: all/build/reports/jacoco/test/html markdown-link-check: - # release branches are excluded to avoid unnecessary maintenance if external links break + # release branches are excluded to avoid unnecessary maintenance if: ${{ !startsWith(github.ref_name, 'release/') }} uses: ./.github/workflows/reusable-markdown-link-check.yml misspell-check: - # release branches are excluded to avoid unnecessary maintenance if new misspellings are added - # to the misspell dictionary + # release branches are excluded to avoid unnecessary maintenance if: ${{ !startsWith(github.ref_name, 'release/') }} uses: ./.github/workflows/reusable-misspell-check.yml @@ -111,8 +108,6 @@ jobs: runs-on: ubuntu-20.04 steps: - uses: actions/checkout@v3 - with: - fetch-depth: 0 - id: setup-java name: Set up Java @@ -134,11 +129,11 @@ jobs: GPG_PASSWORD: ${{ secrets.GPG_PASSWORD }} required-status-check: - # markdown-link-check is not required so that pull requests will not be blocked if external - # links break - # similarly misspell-check is not required so that pull requests will not be blocked if new - # misspellings are added to the misspell dictionary - needs: build + # markdown-link-check is not required so pull requests are not blocked if external links break + # misspell-check is not required so pull requests are not blocked if the misspell dictionary is + # updated + needs: + - build runs-on: ubuntu-latest if: always() steps: diff --git a/.github/workflows/codeql-daily.yml b/.github/workflows/codeql-daily.yml index bb1ef7afe51..bbd44ad27f4 100644 --- a/.github/workflows/codeql-daily.yml +++ b/.github/workflows/codeql-daily.yml @@ -2,6 +2,7 @@ name: CodeQL (daily) on: schedule: + # Daily at 01:30 (UTC) - cron: '30 1 * * *' workflow_dispatch: @@ -33,6 +34,7 @@ jobs: open-issue-on-failure: # open an issue on failure because it can be easy to miss CI failure notifications - needs: analyze - if: failure() + needs: + - analyze + if: failure() && github.run_attempt == 1 uses: ./.github/workflows/reusable-open-issue-on-failure.yml diff --git a/.github/workflows/prepare-patch-release.yml b/.github/workflows/prepare-patch-release.yml index ac3b621770a..37c03918084 100644 --- a/.github/workflows/prepare-patch-release.yml +++ b/.github/workflows/prepare-patch-release.yml @@ -45,14 +45,14 @@ jobs: - name: Create pull request env: # not using secrets.GITHUB_TOKEN since pull requests from that token do not run workflows - GITHUB_TOKEN: ${{ secrets.BOT_TOKEN }} + GH_TOKEN: ${{ secrets.BOT_TOKEN }} run: | message="Prepare release $VERSION" branch="opentelemetrybot/prepare-release-${VERSION}" + git checkout -b $branch git commit -a -m "$message" - git push origin HEAD:$branch + git push --set-upstream origin $branch gh pr create --title "[$GITHUB_REF_NAME] $message" \ --body "$message." \ - --head $branch \ --base $GITHUB_REF_NAME diff --git a/.github/workflows/prepare-release-branch.yml b/.github/workflows/prepare-release-branch.yml index 6569c043430..41e718c2b5e 100644 --- a/.github/workflows/prepare-release-branch.yml +++ b/.github/workflows/prepare-release-branch.yml @@ -8,7 +8,8 @@ jobs: steps: - uses: actions/checkout@v3 - - run: | + - name: Verify prerequisites + run: | if [[ $GITHUB_REF_NAME != main ]]; then echo this workflow should only be run against main exit 1 @@ -21,7 +22,8 @@ jobs: create-pull-request-against-release-branch: runs-on: ubuntu-latest - needs: prereqs + needs: + - prereqs steps: - uses: actions/checkout@v3 @@ -55,21 +57,22 @@ jobs: - name: Create pull request against the release branch env: # not using secrets.GITHUB_TOKEN since pull requests from that token do not run workflows - GITHUB_TOKEN: ${{ secrets.BOT_TOKEN }} + GH_TOKEN: ${{ secrets.BOT_TOKEN }} run: | message="Prepare release $VERSION" branch="opentelemetrybot/prepare-release-${VERSION}" + git checkout -b $branch git commit -a -m "$message" - git push origin HEAD:$branch + git push --set-upstream origin $branch gh pr create --title "[$RELEASE_BRANCH_NAME] $message" \ --body "$message." \ - --head $branch \ --base $RELEASE_BRANCH_NAME create-pull-request-against-main: runs-on: ubuntu-latest - needs: prereqs + needs: + - prereqs steps: - uses: actions/checkout@v3 @@ -102,15 +105,15 @@ jobs: - name: Create pull request against main env: # not using secrets.GITHUB_TOKEN since pull requests from that token do not run workflows - GITHUB_TOKEN: ${{ secrets.BOT_TOKEN }} + GH_TOKEN: ${{ secrets.BOT_TOKEN }} run: | message="Update version to $NEXT_VERSION" body="Update version to \`$NEXT_VERSION\`." branch="opentelemetrybot/update-version-to-${NEXT_VERSION}" + git checkout -b $branch git commit -a -m "$message" - git push origin HEAD:$branch + git push --set-upstream origin $branch gh pr create --title "$message" \ --body "$body" \ - --head $branch \ --base main diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index fc3e19e101f..c7792090efd 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -4,13 +4,13 @@ on: jobs: release: + runs-on: ubuntu-20.04 outputs: version: ${{ steps.create-github-release.outputs.version }} - runs-on: ubuntu-20.04 steps: - run: | if [[ $GITHUB_REF_NAME != release/* ]]; then - echo the release workflow should only be run against release branches + echo this workflow should only be run against release branches exit 1 fi @@ -62,7 +62,8 @@ jobs: with: ref: main - - run: | + - name: Check that change log update was merged to main + run: | if [[ $VERSION == *.0 ]]; then # not making a patch release if ! grep --quiet "^## Version $VERSION " CHANGELOG.md; then @@ -79,7 +80,7 @@ jobs: - name: Generate release notes env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} run: | # conditional blocks not indented because of the heredoc if [[ $VERSION != *.0 ]]; then @@ -114,7 +115,7 @@ jobs: - id: create-github-release name: Create GitHub release env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} run: | gh release create --target $GITHUB_REF_NAME \ --title "Version $VERSION" \ @@ -124,81 +125,60 @@ jobs: echo "::set-output name=version::$VERSION" + merge-change-log-to-main: + runs-on: ubuntu-latest + needs: + - release + steps: - uses: actions/checkout@v3 - with: - # the step below is creating a pull request against main - ref: main - - name: Copy change log updates to main + - name: Copy change log section from release branch env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + VERSION: ${{ needs.release.outputs.version }} run: | - if [[ $VERSION == *.0 ]]; then - # this was not a patch release, so the version exists already in the CHANGELOG.md - - # update the release date - date=$(gh release view v$VERSION --json publishedAt --jq .publishedAt | sed 's/T.*//') - sed -Ei "s/## Version $VERSION .*/## Version $VERSION ($date)/" CHANGELOG.md - - # the entries are copied over from the release branch to support workflows - # where change log entries may be updated after preparing the release branch - - # copy the portion above the release, up to and including the heading - sed -n "0,/^## Version $VERSION ($date)/p" CHANGELOG.md > /tmp/CHANGELOG.md - - # copy the release notes - cat /tmp/CHANGELOG_SECTION.md >> /tmp/CHANGELOG.md - - # copy the portion below the release - sed -n "0,/^## Version $VERSION /d;0,/^## Version /{/^## Version/!d};p" CHANGELOG.md \ - >> /tmp/CHANGELOG.md - - # update the real CHANGELOG.md - cp /tmp/CHANGELOG.md CHANGELOG.md - else - # this was a patch release, so the version does not exist already in the CHANGELOG.md - - # copy the portion above the top-most release, not including the heading - sed -n "0,/^## Version /{ /^## Version /!p }" CHANGELOG.md > /tmp/CHANGELOG.md - - # add the heading - date=$(gh release view v$VERSION --json publishedAt --jq .publishedAt | sed 's/T.*//') - echo "## Version $VERSION ($date)" >> /tmp/CHANGELOG.md - - # copy the release notes - cat /tmp/CHANGELOG_SECTION.md >> /tmp/CHANGELOG.md + sed -n "0,/^## Version $VERSION /d;/^## Version /q;p" CHANGELOG.md \ + > /tmp/changelog-section.md - # copy the portion starting from the top-most release - sed -n "/^## Version /,\$p" CHANGELOG.md >> /tmp/CHANGELOG.md + - uses: actions/checkout@v3 + with: + ref: main - # update the real CHANGELOG.md - cp /tmp/CHANGELOG.md CHANGELOG.md - fi + - name: Merge change log to main + env: + VERSION: ${{ needs.release.outputs.version }} + GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} + run: | + release_date=$(gh release view v$VERSION --json publishedAt --jq .publishedAt | sed 's/T.*//') + RELEASE_DATE=$release_date .github/scripts/merge-change-log-after-release.sh - name: Use CLA approved github bot run: .github/scripts/use-cla-approved-github-bot.sh - name: Create pull request against main env: + VERSION: ${{ needs.release.outputs.version }} # not using secrets.GITHUB_TOKEN since pull requests from that token do not run workflows - GITHUB_TOKEN: ${{ secrets.BOT_TOKEN }} + GH_TOKEN: ${{ secrets.BOT_TOKEN }} run: | - message="Copy change log updates from $GITHUB_REF_NAME" - body="Copy log updates from \`$GITHUB_REF_NAME\`." - branch="opentelemetrybot/copy-change-log-updates-from-${GITHUB_REF_NAME//\//-}" - - if [[ $VERSION == *.0 ]]; then - if git diff --quiet; then - echo there are no updates needed to the change log on main, not creating pull request + if git diff --quiet; then + if [[ $VERSION =~ ^[0-9]+\.[0-9]+\.0 ]]; then + echo there are no updates to merge, not creating pull request exit 0 # success + else + echo patch release notes did not get applied for some reason + exit 1 # failure fi fi + message="Merge change log updates from $GITHUB_REF_NAME" + body="Merge log updates from \`$GITHUB_REF_NAME\`." + branch="opentelemetrybot/merge-change-log-updates-from-${GITHUB_REF_NAME//\//-}" + + git checkout -b $branch git commit -a -m "$message" - git push origin HEAD:$branch + git push --set-upstream origin $branch gh pr create --title "$message" \ --body "$body" \ - --head $branch \ --base main create-website-pull-request: diff --git a/.github/workflows/reusable-misspell-check.yml b/.github/workflows/reusable-misspell-check.yml index 24f3a2c71be..105649c8197 100644 --- a/.github/workflows/reusable-misspell-check.yml +++ b/.github/workflows/reusable-misspell-check.yml @@ -11,7 +11,7 @@ jobs: - name: Install misspell run: | - curl -L -o ./install-misspell.sh https://git.io/misspell + curl -L -o install-misspell.sh https://git.io/misspell sh ./install-misspell.sh - name: Run misspell diff --git a/.github/workflows/reusable-open-issue-on-failure.yml b/.github/workflows/reusable-open-issue-on-failure.yml index 31f81f979d4..6814c162878 100644 --- a/.github/workflows/reusable-open-issue-on-failure.yml +++ b/.github/workflows/reusable-open-issue-on-failure.yml @@ -1,4 +1,4 @@ -name: Reusable - Open issue on failure +name: Reusable - Open issue on workflow failure on: workflow_call: @@ -11,7 +11,7 @@ jobs: - name: Open issue env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} run: | gh issue create --title "$GITHUB_WORKFLOW #$GITHUB_RUN_NUMBER failed" \ --label bug \ From 44975c2853eaa122d9cd6f9cef560d1696193211 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Fri, 25 Nov 2022 13:11:45 -0800 Subject: [PATCH 55/68] Bump spotless-plugin-gradle from 6.11.0 to 6.12.0 (#4987) Bumps [spotless-plugin-gradle](https://github.com/diffplug/spotless) from 6.11.0 to 6.12.0. - [Release notes](https://github.com/diffplug/spotless/releases) - [Changelog](https://github.com/diffplug/spotless/blob/main/CHANGES.md) - [Commits](https://github.com/diffplug/spotless/compare/gradle/6.11.0...gradle/6.12.0) --- updated-dependencies: - dependency-name: com.diffplug.spotless:spotless-plugin-gradle dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> --- buildSrc/build.gradle.kts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/buildSrc/build.gradle.kts b/buildSrc/build.gradle.kts index 4a483ed5f35..517ec938c58 100644 --- a/buildSrc/build.gradle.kts +++ b/buildSrc/build.gradle.kts @@ -14,7 +14,7 @@ repositories { dependencies { implementation("com.google.auto.value:auto-value-annotations:1.10.1") // When updating, update above in plugins too - implementation("com.diffplug.spotless:spotless-plugin-gradle:6.11.0") + implementation("com.diffplug.spotless:spotless-plugin-gradle:6.12.0") // Needed for japicmp but not automatically brought in for some reason. implementation("com.google.guava:guava:31.1-jre") implementation("com.squareup:javapoet:1.13.0") From c2947bf0468e3c3258ea4770f0c76c88e75624ad Mon Sep 17 00:00:00 2001 From: jack-berg <34418638+jack-berg@users.noreply.github.com> Date: Sat, 26 Nov 2022 09:10:35 -0600 Subject: [PATCH 56/68] Add toString implementation to various log SDK components (#4979) --- .../io/opentelemetry/sdk/OpenTelemetrySdk.java | 4 +++- .../opentelemetry/sdk/OpenTelemetrySdkTest.java | 17 +++++++++++++++++ .../sdk/logs/SdkLoggerProvider.java | 14 ++++++++++++++ .../logs/export/BatchLogRecordProcessor.java | 14 ++++++++++++++ .../sdk/logs/export/MultiLogRecordExporter.java | 13 +++++++++++-- .../logs/export/SimpleLogRecordProcessor.java | 5 +++++ .../sdk/logs/SdkLoggerProviderTest.java | 13 +++++++++++++ .../export/BatchLogRecordProcessorTest.java | 8 ++++++++ .../logs/export/MultiLogRecordExporterTest.java | 9 +++++++++ .../export/SimpleLogRecordProcessorTest.java | 7 +++++++ 10 files changed, 101 insertions(+), 3 deletions(-) diff --git a/sdk/all/src/main/java/io/opentelemetry/sdk/OpenTelemetrySdk.java b/sdk/all/src/main/java/io/opentelemetry/sdk/OpenTelemetrySdk.java index 78263217384..79c264759d4 100644 --- a/sdk/all/src/main/java/io/opentelemetry/sdk/OpenTelemetrySdk.java +++ b/sdk/all/src/main/java/io/opentelemetry/sdk/OpenTelemetrySdk.java @@ -80,12 +80,14 @@ public ContextPropagators getPropagators() { @Override public String toString() { - // TODO(anuraaga): Add logs / propagators + // TODO(anuraaga): Add propagators return "OpenTelemetrySdk{" + "tracerProvider=" + tracerProvider.unobfuscate() + ", meterProvider=" + meterProvider.unobfuscate() + + ", loggerProvider=" + + loggerProvider + "}"; } diff --git a/sdk/all/src/test/java/io/opentelemetry/sdk/OpenTelemetrySdkTest.java b/sdk/all/src/test/java/io/opentelemetry/sdk/OpenTelemetrySdkTest.java index a65080bb6c7..3a9228d9c8c 100644 --- a/sdk/all/src/test/java/io/opentelemetry/sdk/OpenTelemetrySdkTest.java +++ b/sdk/all/src/test/java/io/opentelemetry/sdk/OpenTelemetrySdkTest.java @@ -19,6 +19,8 @@ import io.opentelemetry.context.propagation.TextMapPropagator; import io.opentelemetry.sdk.common.Clock; import io.opentelemetry.sdk.logs.SdkLoggerProvider; +import io.opentelemetry.sdk.logs.export.LogRecordExporter; +import io.opentelemetry.sdk.logs.export.SimpleLogRecordProcessor; import io.opentelemetry.sdk.metrics.Aggregation; import io.opentelemetry.sdk.metrics.InstrumentSelector; import io.opentelemetry.sdk.metrics.InstrumentType; @@ -322,6 +324,8 @@ void stringRepresentation() { when(spanExporter.toString()).thenReturn("MockSpanExporter{}"); when(metricExporter.getDefaultAggregation(any())).thenCallRealMethod(); when(metricExporter.toString()).thenReturn("MockMetricExporter{}"); + LogRecordExporter logRecordExporter = mock(LogRecordExporter.class); + when(logRecordExporter.toString()).thenReturn("MockLogRecordExporter{}"); Resource resource = Resource.builder().put(AttributeKey.stringKey("service.name"), "otel-test").build(); OpenTelemetrySdk sdk = @@ -341,6 +345,13 @@ void stringRepresentation() { InstrumentSelector.builder().setName("instrument").build(), View.builder().setName("new-instrument").build()) .build()) + .setLoggerProvider( + SdkLoggerProvider.builder() + .setResource(resource) + .addLogRecordProcessor( + SimpleLogRecordProcessor.create( + LogRecordExporter.composite(logRecordExporter, logRecordExporter))) + .build()) .build(); assertThat(sdk.toString()) @@ -359,6 +370,12 @@ void stringRepresentation() { + "resource=Resource{schemaUrl=null, attributes={service.name=\"otel-test\"}}, " + "metricReaders=[PeriodicMetricReader{exporter=MockMetricExporter{}, intervalNanos=60000000000}], " + "views=[RegisteredView{instrumentSelector=InstrumentSelector{instrumentName=instrument}, view=View{name=new-instrument, aggregation=DefaultAggregation, attributesProcessor=NoopAttributesProcessor{}}}]" + + "}, " + + "loggerProvider=SdkLoggerProvider{" + + "clock=SystemClock{}, " + + "resource=Resource{schemaUrl=null, attributes={service.name=\"otel-test\"}}, " + + "logLimits=LogLimits{maxNumberOfAttributes=128, maxAttributeValueLength=2147483647}, " + + "logRecordProcessor=SimpleLogRecordProcessor{logRecordExporter=MultiLogRecordExporter{logRecordExporters=[MockLogRecordExporter{}, MockLogRecordExporter{}]}}" + "}" + "}"); } diff --git a/sdk/logs/src/main/java/io/opentelemetry/sdk/logs/SdkLoggerProvider.java b/sdk/logs/src/main/java/io/opentelemetry/sdk/logs/SdkLoggerProvider.java index 478700742d6..d7b35c9ed86 100644 --- a/sdk/logs/src/main/java/io/opentelemetry/sdk/logs/SdkLoggerProvider.java +++ b/sdk/logs/src/main/java/io/opentelemetry/sdk/logs/SdkLoggerProvider.java @@ -117,4 +117,18 @@ public CompletableResultCode shutdown() { public void close() { shutdown().join(10, TimeUnit.SECONDS); } + + @Override + public String toString() { + return "SdkLoggerProvider{" + + "clock=" + + sharedState.getClock() + + ", resource=" + + sharedState.getResource() + + ", logLimits=" + + sharedState.getLogLimits() + + ", logRecordProcessor=" + + sharedState.getLogRecordProcessor() + + '}'; + } } diff --git a/sdk/logs/src/main/java/io/opentelemetry/sdk/logs/export/BatchLogRecordProcessor.java b/sdk/logs/src/main/java/io/opentelemetry/sdk/logs/export/BatchLogRecordProcessor.java index f327b3b4acc..01b5effc7fa 100644 --- a/sdk/logs/src/main/java/io/opentelemetry/sdk/logs/export/BatchLogRecordProcessor.java +++ b/sdk/logs/src/main/java/io/opentelemetry/sdk/logs/export/BatchLogRecordProcessor.java @@ -107,6 +107,20 @@ ArrayList getBatch() { return worker.batch; } + @Override + public String toString() { + return "BatchLogRecordProcessor{" + + "logRecordExporter=" + + worker.logRecordExporter + + ", scheduleDelayNanos=" + + worker.scheduleDelayNanos + + ", maxExportBatchSize=" + + worker.maxExportBatchSize + + ", exporterTimeoutNanos=" + + worker.exporterTimeoutNanos + + '}'; + } + // Worker is a thread that batches multiple logs and calls the registered LogRecordExporter to // export // the data. diff --git a/sdk/logs/src/main/java/io/opentelemetry/sdk/logs/export/MultiLogRecordExporter.java b/sdk/logs/src/main/java/io/opentelemetry/sdk/logs/export/MultiLogRecordExporter.java index f7676d7580c..33d1a1b726a 100644 --- a/sdk/logs/src/main/java/io/opentelemetry/sdk/logs/export/MultiLogRecordExporter.java +++ b/sdk/logs/src/main/java/io/opentelemetry/sdk/logs/export/MultiLogRecordExporter.java @@ -8,6 +8,7 @@ import io.opentelemetry.sdk.common.CompletableResultCode; import io.opentelemetry.sdk.logs.data.LogRecordData; import java.util.ArrayList; +import java.util.Arrays; import java.util.Collection; import java.util.List; import java.util.logging.Level; @@ -24,6 +25,10 @@ final class MultiLogRecordExporter implements LogRecordExporter { private final LogRecordExporter[] logRecordExporters; + private MultiLogRecordExporter(LogRecordExporter[] logRecordExporters) { + this.logRecordExporters = logRecordExporters; + } + /** * Constructs and returns an instance of this class. * @@ -93,7 +98,11 @@ public CompletableResultCode shutdown() { return CompletableResultCode.ofAll(results); } - private MultiLogRecordExporter(LogRecordExporter[] logRecordExporters) { - this.logRecordExporters = logRecordExporters; + @Override + public String toString() { + return "MultiLogRecordExporter{" + + "logRecordExporters=" + + Arrays.toString(logRecordExporters) + + '}'; } } diff --git a/sdk/logs/src/main/java/io/opentelemetry/sdk/logs/export/SimpleLogRecordProcessor.java b/sdk/logs/src/main/java/io/opentelemetry/sdk/logs/export/SimpleLogRecordProcessor.java index 3bb510718aa..bb891e28435 100644 --- a/sdk/logs/src/main/java/io/opentelemetry/sdk/logs/export/SimpleLogRecordProcessor.java +++ b/sdk/logs/src/main/java/io/opentelemetry/sdk/logs/export/SimpleLogRecordProcessor.java @@ -104,4 +104,9 @@ public CompletableResultCode shutdown() { public CompletableResultCode forceFlush() { return CompletableResultCode.ofAll(pendingExports); } + + @Override + public String toString() { + return "SimpleLogRecordProcessor{" + "logRecordExporter=" + logRecordExporter + '}'; + } } diff --git a/sdk/logs/src/test/java/io/opentelemetry/sdk/logs/SdkLoggerProviderTest.java b/sdk/logs/src/test/java/io/opentelemetry/sdk/logs/SdkLoggerProviderTest.java index 7408fdfc8dc..b663d70de59 100644 --- a/sdk/logs/src/test/java/io/opentelemetry/sdk/logs/SdkLoggerProviderTest.java +++ b/sdk/logs/src/test/java/io/opentelemetry/sdk/logs/SdkLoggerProviderTest.java @@ -346,4 +346,17 @@ void canSetClock() { assertThat(seenLogs.size()).isEqualTo(1); assertThat(seenLogs.get(0).toLogRecordData().getEpochNanos()).isEqualTo(now); } + + @Test + void toString_Valid() { + when(logRecordProcessor.toString()).thenReturn("MockLogRecordProcessor"); + assertThat(sdkLoggerProvider.toString()) + .isEqualTo( + "SdkLoggerProvider{" + + "clock=SystemClock{}, " + + "resource=Resource{schemaUrl=null, attributes={service.name=\"unknown_service:java\", telemetry.sdk.language=\"java\", telemetry.sdk.name=\"opentelemetry\", telemetry.sdk.version=\"1.21.0-SNAPSHOT\"}}, " + + "logLimits=LogLimits{maxNumberOfAttributes=128, maxAttributeValueLength=2147483647}, " + + "logRecordProcessor=MockLogRecordProcessor" + + "}"); + } } diff --git a/sdk/logs/src/test/java/io/opentelemetry/sdk/logs/export/BatchLogRecordProcessorTest.java b/sdk/logs/src/test/java/io/opentelemetry/sdk/logs/export/BatchLogRecordProcessorTest.java index 1039b7e34bc..cf20eead2d5 100644 --- a/sdk/logs/src/test/java/io/opentelemetry/sdk/logs/export/BatchLogRecordProcessorTest.java +++ b/sdk/logs/src/test/java/io/opentelemetry/sdk/logs/export/BatchLogRecordProcessorTest.java @@ -420,6 +420,14 @@ void shutdownPropagatesFailure() { assertThat(result.isSuccess()).isFalse(); } + @Test + void toString_Valid() { + when(mockLogRecordExporter.toString()).thenReturn("MockLogRecordExporter"); + assertThat(BatchLogRecordProcessor.builder(mockLogRecordExporter).build().toString()) + .isEqualTo( + "BatchLogRecordProcessor{logRecordExporter=MockLogRecordExporter, scheduleDelayNanos=200000000, maxExportBatchSize=512, exporterTimeoutNanos=30000000000}"); + } + private static final class BlockingLogRecordExporter implements LogRecordExporter { final Object monitor = new Object(); diff --git a/sdk/logs/src/test/java/io/opentelemetry/sdk/logs/export/MultiLogRecordExporterTest.java b/sdk/logs/src/test/java/io/opentelemetry/sdk/logs/export/MultiLogRecordExporterTest.java index 1f970d6bf40..2f781e4e68b 100644 --- a/sdk/logs/src/test/java/io/opentelemetry/sdk/logs/export/MultiLogRecordExporterTest.java +++ b/sdk/logs/src/test/java/io/opentelemetry/sdk/logs/export/MultiLogRecordExporterTest.java @@ -136,4 +136,13 @@ void twoLogRecordExporter_FirstThrows() { verify(logRecordExporter1).shutdown(); verify(logRecordExporter2).shutdown(); } + + @Test + void toString_Valid() { + when(logRecordExporter1.toString()).thenReturn("LogRecordExporter1"); + when(logRecordExporter2.toString()).thenReturn("LogRecordExporter2"); + assertThat(LogRecordExporter.composite(logRecordExporter1, logRecordExporter2).toString()) + .isEqualTo( + "MultiLogRecordExporter{logRecordExporters=[LogRecordExporter1, LogRecordExporter2]}"); + } } diff --git a/sdk/logs/src/test/java/io/opentelemetry/sdk/logs/export/SimpleLogRecordProcessorTest.java b/sdk/logs/src/test/java/io/opentelemetry/sdk/logs/export/SimpleLogRecordProcessorTest.java index 1550c68b3ef..bace5bdbaf6 100644 --- a/sdk/logs/src/test/java/io/opentelemetry/sdk/logs/export/SimpleLogRecordProcessorTest.java +++ b/sdk/logs/src/test/java/io/opentelemetry/sdk/logs/export/SimpleLogRecordProcessorTest.java @@ -119,4 +119,11 @@ void shutdown() { assertThat(shutdown.isSuccess()).isTrue(); verify(logRecordExporter).shutdown(); } + + @Test + void toString_Valid() { + when(logRecordExporter.toString()).thenReturn("MockLogRecordExporter"); + assertThat(logRecordProcessor.toString()) + .isEqualTo("SimpleLogRecordProcessor{logRecordExporter=MockLogRecordExporter}"); + } } From ee2d981bdcc82780b3505cb7b051abe0456ad1ae Mon Sep 17 00:00:00 2001 From: jack-berg <34418638+jack-berg@users.noreply.github.com> Date: Sat, 26 Nov 2022 09:16:59 -0600 Subject: [PATCH 57/68] Remove support for otel.experimental.sdk.enabled (#4973) --- sdk-extensions/autoconfigure/README.md | 6 +-- ...AutoConfiguredOpenTelemetrySdkBuilder.java | 4 +- .../AutoConfiguredOpenTelemetrySdkTest.java | 51 ------------------- 3 files changed, 4 insertions(+), 57 deletions(-) diff --git a/sdk-extensions/autoconfigure/README.md b/sdk-extensions/autoconfigure/README.md index 49fa7fd350d..4ade5ab7bdf 100644 --- a/sdk-extensions/autoconfigure/README.md +++ b/sdk-extensions/autoconfigure/README.md @@ -44,9 +44,9 @@ for more details. The OpenTelemetry SDK can be disabled entirely. If disabled, `AutoConfiguredOpenTelemetrySdk#getOpenTelemetrySdk()` will return a minimally configured instance (i.e. `OpenTelemetrySdk.builder().build()`). -| System property | Environment variable | Purpose | -|-------------------|----------------------|----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------| -| otel.sdk.disabled | OTEL_SDK_DISABLED | If `true`, disable the OpenTelemetry SDK. Defaults to `false`. The now legacy property `otel.experimental.sdk.enabled` will continue to work with default `true` during a transition period. | +| System property | Environment variable | Purpose | +|-------------------|----------------------|----------------------------------------------------------------| +| otel.sdk.disabled | OTEL_SDK_DISABLED | If `true`, disable the OpenTelemetry SDK. Defaults to `false`. | ## Exporters 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 89aaf480f7b..c8d633a4b8f 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 @@ -331,9 +331,7 @@ public AutoConfiguredOpenTelemetrySdk build() { ResourceConfiguration.configureResource(config, serviceClassLoader, resourceCustomizer); OpenTelemetrySdk openTelemetrySdk = OpenTelemetrySdk.builder().build(); - boolean sdkEnabled = - !config.getBoolean( - "otel.sdk.disabled", !config.getBoolean("otel.experimental.sdk.enabled", true)); + boolean sdkEnabled = !config.getBoolean("otel.sdk.disabled", false); if (sdkEnabled) { SdkMeterProviderBuilder meterProviderBuilder = SdkMeterProvider.builder(); diff --git a/sdk-extensions/autoconfigure/src/test/java/io/opentelemetry/sdk/autoconfigure/AutoConfiguredOpenTelemetrySdkTest.java b/sdk-extensions/autoconfigure/src/test/java/io/opentelemetry/sdk/autoconfigure/AutoConfiguredOpenTelemetrySdkTest.java index fd2daacefef..7ba3a8c1493 100644 --- a/sdk-extensions/autoconfigure/src/test/java/io/opentelemetry/sdk/autoconfigure/AutoConfiguredOpenTelemetrySdkTest.java +++ b/sdk-extensions/autoconfigure/src/test/java/io/opentelemetry/sdk/autoconfigure/AutoConfiguredOpenTelemetrySdkTest.java @@ -359,31 +359,6 @@ private static Supplier> disableExportPropertySupplier() { return () -> props; } - @Test - void disableSdkLegacyProperty() { - BiFunction - traceCustomizer = getTracerProviderBuilderSpy(); - BiFunction - metricCustomizer = getMeterProviderBuilderSpy(); - BiFunction logCustomizer = - getLoggerProviderBuilderSpy(); - - AutoConfiguredOpenTelemetrySdk autoConfiguredSdk = - AutoConfiguredOpenTelemetrySdk.builder() - .addPropertiesSupplier(() -> singletonMap("otel.experimental.sdk.enabled", "false")) - .addTracerProviderCustomizer(traceCustomizer) - .addMeterProviderCustomizer(metricCustomizer) - .addLoggerProviderCustomizer(logCustomizer) - .build(); - - assertThat(autoConfiguredSdk.getOpenTelemetrySdk()).isInstanceOf(OpenTelemetrySdk.class); - - // When the SDK is disabled, configuration is skipped and none of the customizers are called - verify(traceCustomizer, never()).apply(any(), any()); - verify(metricCustomizer, never()).apply(any(), any()); - verify(logCustomizer, never()).apply(any(), any()); - } - @Test void disableSdk() { BiFunction @@ -409,32 +384,6 @@ void disableSdk() { verify(logCustomizer, never()).apply(any(), any()); } - @Test - void disableSdkNewPropertyWins() { - BiFunction - traceCustomizer = getTracerProviderBuilderSpy(); - BiFunction - metricCustomizer = getMeterProviderBuilderSpy(); - BiFunction logCustomizer = - getLoggerProviderBuilderSpy(); - - AutoConfiguredOpenTelemetrySdk autoConfiguredSdk = - AutoConfiguredOpenTelemetrySdk.builder() - .addPropertiesSupplier(() -> singletonMap("otel.sdk.disabled", "true")) - .addPropertiesSupplier(() -> singletonMap("otel.experimental.sdk.enabled", "true")) - .addTracerProviderCustomizer(traceCustomizer) - .addMeterProviderCustomizer(metricCustomizer) - .addLoggerProviderCustomizer(logCustomizer) - .build(); - - assertThat(autoConfiguredSdk.getOpenTelemetrySdk()).isInstanceOf(OpenTelemetrySdk.class); - - // When the SDK is disabled, configuration is skipped and none of the customizers are called - verify(traceCustomizer, never()).apply(any(), any()); - verify(metricCustomizer, never()).apply(any(), any()); - verify(logCustomizer, never()).apply(any(), any()); - } - @Test void tracerProviderCustomizer() { InMemorySpanExporter spanExporter = InMemorySpanExporter.create(); From cbd629c579ee0f319479b29e233ccd6a257281b7 Mon Sep 17 00:00:00 2001 From: jack-berg <34418638+jack-berg@users.noreply.github.com> Date: Mon, 28 Nov 2022 10:14:44 -0600 Subject: [PATCH 58/68] Implement logging exporter providers (#4950) --- exporters/logging/build.gradle.kts | 2 ++ .../LoggingLogRecordExporterProvider.java | 29 +++++++++++++++++++ .../LoggingMetricExporterProvider.java | 29 +++++++++++++++++++ .../internal/LoggingSpanExporterProvider.java | 29 +++++++++++++++++++ ...logs.ConfigurableLogRecordExporterProvider | 1 + ...metrics.ConfigurableMetricExporterProvider | 1 + ...pi.traces.ConfigurableSpanExporterProvider | 1 + sdk-extensions/autoconfigure/build.gradle.kts | 1 - .../LogRecordExporterConfiguration.java | 22 +++++++++----- .../MetricExporterConfiguration.java | 29 +++++++++++-------- .../SpanExporterConfiguration.java | 23 ++++++++++----- .../sdk/autoconfigure/NotOnClasspathTest.java | 12 ++++---- 12 files changed, 146 insertions(+), 33 deletions(-) create mode 100644 exporters/logging/src/main/java/io/opentelemetry/exporter/logging/internal/LoggingLogRecordExporterProvider.java create mode 100644 exporters/logging/src/main/java/io/opentelemetry/exporter/logging/internal/LoggingMetricExporterProvider.java create mode 100644 exporters/logging/src/main/java/io/opentelemetry/exporter/logging/internal/LoggingSpanExporterProvider.java create mode 100644 exporters/logging/src/main/resources/META-INF/services/io.opentelemetry.sdk.autoconfigure.spi.logs.ConfigurableLogRecordExporterProvider create mode 100644 exporters/logging/src/main/resources/META-INF/services/io.opentelemetry.sdk.autoconfigure.spi.metrics.ConfigurableMetricExporterProvider create mode 100644 exporters/logging/src/main/resources/META-INF/services/io.opentelemetry.sdk.autoconfigure.spi.traces.ConfigurableSpanExporterProvider diff --git a/exporters/logging/build.gradle.kts b/exporters/logging/build.gradle.kts index 8107ed13a9a..ca1adf08d1a 100644 --- a/exporters/logging/build.gradle.kts +++ b/exporters/logging/build.gradle.kts @@ -13,6 +13,8 @@ dependencies { api(project(":sdk:metrics")) api(project(":sdk:logs")) + implementation(project(":sdk-extensions:autoconfigure-spi")) + testImplementation(project(":sdk:testing")) testImplementation(project(":sdk:logs-testing")) } diff --git a/exporters/logging/src/main/java/io/opentelemetry/exporter/logging/internal/LoggingLogRecordExporterProvider.java b/exporters/logging/src/main/java/io/opentelemetry/exporter/logging/internal/LoggingLogRecordExporterProvider.java new file mode 100644 index 00000000000..e6fbd6fbc8d --- /dev/null +++ b/exporters/logging/src/main/java/io/opentelemetry/exporter/logging/internal/LoggingLogRecordExporterProvider.java @@ -0,0 +1,29 @@ +/* + * Copyright The OpenTelemetry Authors + * SPDX-License-Identifier: Apache-2.0 + */ + +package io.opentelemetry.exporter.logging.internal; + +import io.opentelemetry.exporter.logging.SystemOutLogRecordExporter; +import io.opentelemetry.sdk.autoconfigure.spi.ConfigProperties; +import io.opentelemetry.sdk.autoconfigure.spi.logs.ConfigurableLogRecordExporterProvider; +import io.opentelemetry.sdk.logs.export.LogRecordExporter; + +/** + * {@link LogRecordExporter} SPI implementation for {@link SystemOutLogRecordExporter}. + * + *

This class is internal and is hence not for public use. Its APIs are unstable and can change + * at any time. + */ +public class LoggingLogRecordExporterProvider implements ConfigurableLogRecordExporterProvider { + @Override + public LogRecordExporter createExporter(ConfigProperties config) { + return SystemOutLogRecordExporter.create(); + } + + @Override + public String getName() { + return "logging"; + } +} diff --git a/exporters/logging/src/main/java/io/opentelemetry/exporter/logging/internal/LoggingMetricExporterProvider.java b/exporters/logging/src/main/java/io/opentelemetry/exporter/logging/internal/LoggingMetricExporterProvider.java new file mode 100644 index 00000000000..47605ac1154 --- /dev/null +++ b/exporters/logging/src/main/java/io/opentelemetry/exporter/logging/internal/LoggingMetricExporterProvider.java @@ -0,0 +1,29 @@ +/* + * Copyright The OpenTelemetry Authors + * SPDX-License-Identifier: Apache-2.0 + */ + +package io.opentelemetry.exporter.logging.internal; + +import io.opentelemetry.exporter.logging.LoggingMetricExporter; +import io.opentelemetry.sdk.autoconfigure.spi.ConfigProperties; +import io.opentelemetry.sdk.autoconfigure.spi.metrics.ConfigurableMetricExporterProvider; +import io.opentelemetry.sdk.metrics.export.MetricExporter; + +/** + * {@link MetricExporter} SPI implementation for {@link LoggingMetricExporter}. + * + *

This class is internal and is hence not for public use. Its APIs are unstable and can change + * at any time. + */ +public class LoggingMetricExporterProvider implements ConfigurableMetricExporterProvider { + @Override + public MetricExporter createExporter(ConfigProperties config) { + return LoggingMetricExporter.create(); + } + + @Override + public String getName() { + return "logging"; + } +} diff --git a/exporters/logging/src/main/java/io/opentelemetry/exporter/logging/internal/LoggingSpanExporterProvider.java b/exporters/logging/src/main/java/io/opentelemetry/exporter/logging/internal/LoggingSpanExporterProvider.java new file mode 100644 index 00000000000..5854a12fe64 --- /dev/null +++ b/exporters/logging/src/main/java/io/opentelemetry/exporter/logging/internal/LoggingSpanExporterProvider.java @@ -0,0 +1,29 @@ +/* + * Copyright The OpenTelemetry Authors + * SPDX-License-Identifier: Apache-2.0 + */ + +package io.opentelemetry.exporter.logging.internal; + +import io.opentelemetry.exporter.logging.LoggingSpanExporter; +import io.opentelemetry.sdk.autoconfigure.spi.ConfigProperties; +import io.opentelemetry.sdk.autoconfigure.spi.traces.ConfigurableSpanExporterProvider; +import io.opentelemetry.sdk.trace.export.SpanExporter; + +/** + * {@link SpanExporter} SPI implementation for {@link LoggingSpanExporter}. + * + *

This class is internal and is hence not for public use. Its APIs are unstable and can change + * at any time. + */ +public class LoggingSpanExporterProvider implements ConfigurableSpanExporterProvider { + @Override + public SpanExporter createExporter(ConfigProperties config) { + return LoggingSpanExporter.create(); + } + + @Override + public String getName() { + return "logging"; + } +} diff --git a/exporters/logging/src/main/resources/META-INF/services/io.opentelemetry.sdk.autoconfigure.spi.logs.ConfigurableLogRecordExporterProvider b/exporters/logging/src/main/resources/META-INF/services/io.opentelemetry.sdk.autoconfigure.spi.logs.ConfigurableLogRecordExporterProvider new file mode 100644 index 00000000000..8d8842825ba --- /dev/null +++ b/exporters/logging/src/main/resources/META-INF/services/io.opentelemetry.sdk.autoconfigure.spi.logs.ConfigurableLogRecordExporterProvider @@ -0,0 +1 @@ +io.opentelemetry.exporter.logging.internal.LoggingLogRecordExporterProvider diff --git a/exporters/logging/src/main/resources/META-INF/services/io.opentelemetry.sdk.autoconfigure.spi.metrics.ConfigurableMetricExporterProvider b/exporters/logging/src/main/resources/META-INF/services/io.opentelemetry.sdk.autoconfigure.spi.metrics.ConfigurableMetricExporterProvider new file mode 100644 index 00000000000..3ad21a55ccd --- /dev/null +++ b/exporters/logging/src/main/resources/META-INF/services/io.opentelemetry.sdk.autoconfigure.spi.metrics.ConfigurableMetricExporterProvider @@ -0,0 +1 @@ +io.opentelemetry.exporter.logging.internal.LoggingMetricExporterProvider diff --git a/exporters/logging/src/main/resources/META-INF/services/io.opentelemetry.sdk.autoconfigure.spi.traces.ConfigurableSpanExporterProvider b/exporters/logging/src/main/resources/META-INF/services/io.opentelemetry.sdk.autoconfigure.spi.traces.ConfigurableSpanExporterProvider new file mode 100644 index 00000000000..8806e4b9608 --- /dev/null +++ b/exporters/logging/src/main/resources/META-INF/services/io.opentelemetry.sdk.autoconfigure.spi.traces.ConfigurableSpanExporterProvider @@ -0,0 +1 @@ +io.opentelemetry.exporter.logging.internal.LoggingSpanExporterProvider diff --git a/sdk-extensions/autoconfigure/build.gradle.kts b/sdk-extensions/autoconfigure/build.gradle.kts index 182e6389c92..6328e6785c4 100644 --- a/sdk-extensions/autoconfigure/build.gradle.kts +++ b/sdk-extensions/autoconfigure/build.gradle.kts @@ -16,7 +16,6 @@ dependencies { implementation(project(":exporters:common")) compileOnly(project(":exporters:jaeger")) - compileOnly(project(":exporters:logging")) compileOnly(project(":exporters:otlp:all")) compileOnly(project(":exporters:otlp:logs")) compileOnly(project(":exporters:otlp:common")) diff --git a/sdk-extensions/autoconfigure/src/main/java/io/opentelemetry/sdk/autoconfigure/LogRecordExporterConfiguration.java b/sdk-extensions/autoconfigure/src/main/java/io/opentelemetry/sdk/autoconfigure/LogRecordExporterConfiguration.java index 927b4eceb2f..9dd3dc19647 100644 --- a/sdk-extensions/autoconfigure/src/main/java/io/opentelemetry/sdk/autoconfigure/LogRecordExporterConfiguration.java +++ b/sdk-extensions/autoconfigure/src/main/java/io/opentelemetry/sdk/autoconfigure/LogRecordExporterConfiguration.java @@ -11,7 +11,6 @@ import io.opentelemetry.api.metrics.MeterProvider; import io.opentelemetry.exporter.internal.retry.RetryUtil; -import io.opentelemetry.exporter.logging.SystemOutLogRecordExporter; import io.opentelemetry.exporter.otlp.http.logs.OtlpHttpLogRecordExporter; import io.opentelemetry.exporter.otlp.http.logs.OtlpHttpLogRecordExporterBuilder; import io.opentelemetry.exporter.otlp.logs.OtlpGrpcLogRecordExporter; @@ -30,6 +29,12 @@ class LogRecordExporterConfiguration { private static final String EXPORTER_NONE = "none"; + private static final Map EXPORTER_ARTIFACT_ID_BY_NAME; + + static { + EXPORTER_ARTIFACT_ID_BY_NAME = new HashMap<>(); + EXPORTER_ARTIFACT_ID_BY_NAME.put("logging", "opentelemetry-exporter-logging"); + } // Visible for test static Map configureLogRecordExporters( @@ -85,15 +90,18 @@ static LogRecordExporter configureExporter( switch (name) { case "otlp": return configureOtlpLogs(config, meterProvider); - case "logging": - ClasspathUtil.checkClassExists( - "io.opentelemetry.exporter.logging.SystemOutLogRecordExporter", - "Logging Log Exporter", - "opentelemetry-exporter-logging"); - return SystemOutLogRecordExporter.create(); default: LogRecordExporter spiExporter = spiExportersManager.getByName(name); if (spiExporter == null) { + String artifactId = EXPORTER_ARTIFACT_ID_BY_NAME.get(name); + if (artifactId != null) { + throw new ConfigurationException( + "otel.logs.exporter set to \"" + + name + + "\" but " + + artifactId + + " not found on classpath. Make sure to add it as a dependency."); + } throw new ConfigurationException("Unrecognized value for otel.logs.exporter: " + name); } return spiExporter; diff --git a/sdk-extensions/autoconfigure/src/main/java/io/opentelemetry/sdk/autoconfigure/MetricExporterConfiguration.java b/sdk-extensions/autoconfigure/src/main/java/io/opentelemetry/sdk/autoconfigure/MetricExporterConfiguration.java index ac8e6784b3f..75671f8d314 100644 --- a/sdk-extensions/autoconfigure/src/main/java/io/opentelemetry/sdk/autoconfigure/MetricExporterConfiguration.java +++ b/sdk-extensions/autoconfigure/src/main/java/io/opentelemetry/sdk/autoconfigure/MetricExporterConfiguration.java @@ -10,7 +10,6 @@ import static io.opentelemetry.sdk.autoconfigure.OtlpConfigUtil.PROTOCOL_HTTP_PROTOBUF; import io.opentelemetry.exporter.internal.retry.RetryUtil; -import io.opentelemetry.exporter.logging.LoggingMetricExporter; import io.opentelemetry.exporter.otlp.http.metrics.OtlpHttpMetricExporter; import io.opentelemetry.exporter.otlp.http.metrics.OtlpHttpMetricExporterBuilder; import io.opentelemetry.exporter.otlp.metrics.OtlpGrpcMetricExporter; @@ -24,12 +23,20 @@ import io.opentelemetry.sdk.metrics.export.MetricReader; import io.opentelemetry.sdk.metrics.export.PeriodicMetricReader; import java.time.Duration; +import java.util.HashMap; +import java.util.Map; import java.util.function.BiFunction; import javax.annotation.Nullable; final class MetricExporterConfiguration { private static final Duration DEFAULT_EXPORT_INTERVAL = Duration.ofMinutes(1); + private static final Map EXPORTER_ARTIFACT_ID_BY_NAME; + + static { + EXPORTER_ARTIFACT_ID_BY_NAME = new HashMap<>(); + EXPORTER_ARTIFACT_ID_BY_NAME.put("logging", "opentelemetry-exporter-logging"); + } static MetricReader configureExporter( String name, @@ -46,12 +53,18 @@ static MetricReader configureExporter( case "otlp": metricExporter = configureOtlpMetrics(config); break; - case "logging": - metricExporter = configureLoggingExporter(); - break; default: MetricExporter spiExporter = configureSpiExporter(name, config, serviceClassLoader); if (spiExporter == null) { + String artifactId = EXPORTER_ARTIFACT_ID_BY_NAME.get(name); + if (artifactId != null) { + throw new ConfigurationException( + "otel.metrics.exporter set to \"" + + name + + "\" but " + + artifactId + + " not found on classpath. Make sure to add it as a dependency."); + } throw new ConfigurationException("Unrecognized value for otel.metrics.exporter: " + name); } metricExporter = spiExporter; @@ -61,14 +74,6 @@ static MetricReader configureExporter( return configurePeriodicMetricReader(config, metricExporter); } - private static MetricExporter configureLoggingExporter() { - ClasspathUtil.checkClassExists( - "io.opentelemetry.exporter.logging.LoggingMetricExporter", - "Logging Metrics Exporter", - "opentelemetry-exporter-logging"); - return LoggingMetricExporter.create(); - } - // Visible for testing. @Nullable static MetricExporter configureSpiExporter( diff --git a/sdk-extensions/autoconfigure/src/main/java/io/opentelemetry/sdk/autoconfigure/SpanExporterConfiguration.java b/sdk-extensions/autoconfigure/src/main/java/io/opentelemetry/sdk/autoconfigure/SpanExporterConfiguration.java index a3d2c394783..89a42620b48 100644 --- a/sdk-extensions/autoconfigure/src/main/java/io/opentelemetry/sdk/autoconfigure/SpanExporterConfiguration.java +++ b/sdk-extensions/autoconfigure/src/main/java/io/opentelemetry/sdk/autoconfigure/SpanExporterConfiguration.java @@ -14,7 +14,6 @@ import io.opentelemetry.exporter.internal.retry.RetryUtil; import io.opentelemetry.exporter.jaeger.JaegerGrpcSpanExporter; import io.opentelemetry.exporter.jaeger.JaegerGrpcSpanExporterBuilder; -import io.opentelemetry.exporter.logging.LoggingSpanExporter; import io.opentelemetry.exporter.otlp.http.trace.OtlpHttpSpanExporter; import io.opentelemetry.exporter.otlp.http.trace.OtlpHttpSpanExporterBuilder; import io.opentelemetry.exporter.otlp.trace.OtlpGrpcSpanExporter; @@ -27,6 +26,7 @@ import io.opentelemetry.sdk.trace.export.SpanExporter; import java.time.Duration; import java.util.Collections; +import java.util.HashMap; import java.util.Map; import java.util.Set; import java.util.function.BiFunction; @@ -35,6 +35,12 @@ final class SpanExporterConfiguration { private static final String EXPORTER_NONE = "none"; + private static final Map EXPORTER_ARTIFACT_ID_BY_NAME; + + static { + EXPORTER_ARTIFACT_ID_BY_NAME = new HashMap<>(); + EXPORTER_ARTIFACT_ID_BY_NAME.put("logging", "opentelemetry-exporter-logging"); + } // Visible for testing static Map configureSpanExporters( @@ -92,15 +98,18 @@ static SpanExporter configureExporter( return configureJaeger(config, meterProvider); case "zipkin": return configureZipkin(config); - case "logging": - ClasspathUtil.checkClassExists( - "io.opentelemetry.exporter.logging.LoggingSpanExporter", - "Logging Trace Exporter", - "opentelemetry-exporter-logging"); - return LoggingSpanExporter.create(); default: SpanExporter spiExporter = spiExportersManager.getByName(name); if (spiExporter == null) { + String artifactId = EXPORTER_ARTIFACT_ID_BY_NAME.get(name); + if (artifactId != null) { + throw new ConfigurationException( + "otel.traces.exporter set to \"" + + name + + "\" but " + + artifactId + + " not found on classpath. Make sure to add it as a dependency."); + } throw new ConfigurationException("Unrecognized value for otel.traces.exporter: " + name); } return spiExporter; diff --git a/sdk-extensions/autoconfigure/src/test/java/io/opentelemetry/sdk/autoconfigure/NotOnClasspathTest.java b/sdk-extensions/autoconfigure/src/test/java/io/opentelemetry/sdk/autoconfigure/NotOnClasspathTest.java index a4a476b2c62..f3c36438fd0 100644 --- a/sdk-extensions/autoconfigure/src/test/java/io/opentelemetry/sdk/autoconfigure/NotOnClasspathTest.java +++ b/sdk-extensions/autoconfigure/src/test/java/io/opentelemetry/sdk/autoconfigure/NotOnClasspathTest.java @@ -77,8 +77,8 @@ void loggingSpans() { "logging", EMPTY, NamedSpiManager.createEmpty(), MeterProvider.noop())) .isInstanceOf(ConfigurationException.class) .hasMessageContaining( - "Logging Trace Exporter enabled but opentelemetry-exporter-logging not found on " - + "classpath"); + "otel.traces.exporter set to \"logging\" but opentelemetry-exporter-logging not found on classpath." + + " Make sure to add it as a dependency."); } @Test @@ -92,8 +92,8 @@ void loggingMetrics() { (a, unused) -> a)) .isInstanceOf(ConfigurationException.class) .hasMessageContaining( - "Logging Metrics Exporter enabled but opentelemetry-exporter-logging not found on " - + "classpath"); + "otel.metrics.exporter set to \"logging\" but opentelemetry-exporter-logging not found on classpath." + + " Make sure to add it as a dependency."); } @Test @@ -104,8 +104,8 @@ void loggingLogs() { "logging", EMPTY, NamedSpiManager.createEmpty(), MeterProvider.noop())) .isInstanceOf(ConfigurationException.class) .hasMessageContaining( - "Logging Log Exporter enabled but opentelemetry-exporter-logging not found on " - + "classpath"); + "otel.logs.exporter set to \"logging\" but opentelemetry-exporter-logging not found on classpath." + + " Make sure to add it as a dependency."); } @Test From 7dd5c1ccd767227fe049a34ffd2a9e9f4200c6d6 Mon Sep 17 00:00:00 2001 From: Ben Roling Date: Mon, 28 Nov 2022 11:15:31 -0600 Subject: [PATCH 59/68] Add auto-configure support for logging-otlp (#4879) * Add autoconfigure support for logging-otlp * Add NotOnClasspath tests * Fix formatting * Declare logging-otlp as experimental, add unit test * Spotless Co-authored-by: Jack Berg --- sdk-extensions/autoconfigure/README.md | 13 ++++ sdk-extensions/autoconfigure/build.gradle.kts | 7 ++ .../LogRecordExporterConfiguration.java | 7 ++ .../MetricExporterConfiguration.java | 12 ++++ .../SpanExporterConfiguration.java | 7 ++ .../sdk/autoconfigure/NotOnClasspathTest.java | 39 +++++++++++ .../sdk/autoconfigure/LoggingOtlpTest.java | 66 +++++++++++++++++++ .../aggregator/HistogramValueGenerator.java | 2 - 8 files changed, 151 insertions(+), 2 deletions(-) create mode 100644 sdk-extensions/autoconfigure/src/testLoggingOtlp/java/io/opentelemetry/sdk/autoconfigure/LoggingOtlpTest.java diff --git a/sdk-extensions/autoconfigure/README.md b/sdk-extensions/autoconfigure/README.md index 4ade5ab7bdf..97e705be446 100644 --- a/sdk-extensions/autoconfigure/README.md +++ b/sdk-extensions/autoconfigure/README.md @@ -159,6 +159,19 @@ The logging exporter prints the name of the span along with its attributes to st | otel.metrics.exporter=logging | OTEL_METRICS_EXPORTER=logging | Select the logging exporter for metrics | | otel.logs.exporter=logging | OTEL_LOGS_EXPORTER=logging | Select the logging exporter for logs | +### Logging OTLP JSON exporter + +The logging-otlp exporter writes the telemetry data to the JUL logger in OLTP JSON form. It's a more verbose output mainly used for testing and debugging. + +| System property | Environment variable | Description | +|------------------------------------|------------------------------------|----------------------------------------------------| +| otel.traces.exporter=logging-otlp | OTEL_TRACES_EXPORTER=logging-otlp | Select the logging OTLP JSON exporter for tracing | +| otel.metrics.exporter=logging-otlp | OTEL_METRICS_EXPORTER=logging-otlp | Select the logging OTLP JSON exporter for metrics | +| otel.logs.exporter=logging-otlp | OTEL_LOGS_EXPORTER=logging-otlp | Select the logging OTLP JSON exporter for logs | + +**NOTE:** While the `OtlpJsonLogging{Signal}Exporters` are stable, specifying their use +via `otel.{signal}.exporter=logging-otlp` is experimental and subject to change or removal. + ## Propagator The propagators determine which distributed tracing header formats are used, and which baggage propagation header formats are used. diff --git a/sdk-extensions/autoconfigure/build.gradle.kts b/sdk-extensions/autoconfigure/build.gradle.kts index 6328e6785c4..7c1d6b827a3 100644 --- a/sdk-extensions/autoconfigure/build.gradle.kts +++ b/sdk-extensions/autoconfigure/build.gradle.kts @@ -16,6 +16,7 @@ dependencies { implementation(project(":exporters:common")) compileOnly(project(":exporters:jaeger")) + compileOnly(project(":exporters:logging-otlp")) compileOnly(project(":exporters:otlp:all")) compileOnly(project(":exporters:otlp:logs")) compileOnly(project(":exporters:otlp:common")) @@ -141,6 +142,12 @@ testing { } } } + val testLoggingOtlp by registering(JvmTestSuite::class) { + dependencies { + implementation(project(":exporters:logging-otlp")) + implementation("com.google.guava:guava") + } + } val testOtlp by registering(JvmTestSuite::class) { dependencies { implementation(project(":exporters:otlp:all")) diff --git a/sdk-extensions/autoconfigure/src/main/java/io/opentelemetry/sdk/autoconfigure/LogRecordExporterConfiguration.java b/sdk-extensions/autoconfigure/src/main/java/io/opentelemetry/sdk/autoconfigure/LogRecordExporterConfiguration.java index 9dd3dc19647..693aa3303f8 100644 --- a/sdk-extensions/autoconfigure/src/main/java/io/opentelemetry/sdk/autoconfigure/LogRecordExporterConfiguration.java +++ b/sdk-extensions/autoconfigure/src/main/java/io/opentelemetry/sdk/autoconfigure/LogRecordExporterConfiguration.java @@ -11,6 +11,7 @@ import io.opentelemetry.api.metrics.MeterProvider; import io.opentelemetry.exporter.internal.retry.RetryUtil; +import io.opentelemetry.exporter.logging.otlp.OtlpJsonLoggingLogRecordExporter; import io.opentelemetry.exporter.otlp.http.logs.OtlpHttpLogRecordExporter; import io.opentelemetry.exporter.otlp.http.logs.OtlpHttpLogRecordExporterBuilder; import io.opentelemetry.exporter.otlp.logs.OtlpGrpcLogRecordExporter; @@ -90,6 +91,12 @@ static LogRecordExporter configureExporter( switch (name) { case "otlp": return configureOtlpLogs(config, meterProvider); + case "logging-otlp": + ClasspathUtil.checkClassExists( + "io.opentelemetry.exporter.logging.otlp.OtlpJsonLoggingLogRecordExporter", + "OTLP JSON Logging Log Exporter", + "opentelemetry-exporter-logging-otlp"); + return OtlpJsonLoggingLogRecordExporter.create(); default: LogRecordExporter spiExporter = spiExportersManager.getByName(name); if (spiExporter == null) { diff --git a/sdk-extensions/autoconfigure/src/main/java/io/opentelemetry/sdk/autoconfigure/MetricExporterConfiguration.java b/sdk-extensions/autoconfigure/src/main/java/io/opentelemetry/sdk/autoconfigure/MetricExporterConfiguration.java index 75671f8d314..a82cc6c5cb1 100644 --- a/sdk-extensions/autoconfigure/src/main/java/io/opentelemetry/sdk/autoconfigure/MetricExporterConfiguration.java +++ b/sdk-extensions/autoconfigure/src/main/java/io/opentelemetry/sdk/autoconfigure/MetricExporterConfiguration.java @@ -10,6 +10,7 @@ import static io.opentelemetry.sdk.autoconfigure.OtlpConfigUtil.PROTOCOL_HTTP_PROTOBUF; import io.opentelemetry.exporter.internal.retry.RetryUtil; +import io.opentelemetry.exporter.logging.otlp.OtlpJsonLoggingMetricExporter; import io.opentelemetry.exporter.otlp.http.metrics.OtlpHttpMetricExporter; import io.opentelemetry.exporter.otlp.http.metrics.OtlpHttpMetricExporterBuilder; import io.opentelemetry.exporter.otlp.metrics.OtlpGrpcMetricExporter; @@ -53,6 +54,9 @@ static MetricReader configureExporter( case "otlp": metricExporter = configureOtlpMetrics(config); break; + case "logging-otlp": + metricExporter = configureLoggingOtlpExporter(); + break; default: MetricExporter spiExporter = configureSpiExporter(name, config, serviceClassLoader); if (spiExporter == null) { @@ -74,6 +78,14 @@ static MetricReader configureExporter( return configurePeriodicMetricReader(config, metricExporter); } + private static MetricExporter configureLoggingOtlpExporter() { + ClasspathUtil.checkClassExists( + "io.opentelemetry.exporter.logging.otlp.OtlpJsonLoggingMetricExporter", + "OTLP JSON Logging Metrics Exporter", + "opentelemetry-exporter-logging-otlp"); + return OtlpJsonLoggingMetricExporter.create(); + } + // Visible for testing. @Nullable static MetricExporter configureSpiExporter( diff --git a/sdk-extensions/autoconfigure/src/main/java/io/opentelemetry/sdk/autoconfigure/SpanExporterConfiguration.java b/sdk-extensions/autoconfigure/src/main/java/io/opentelemetry/sdk/autoconfigure/SpanExporterConfiguration.java index 89a42620b48..380cc3c5eaf 100644 --- a/sdk-extensions/autoconfigure/src/main/java/io/opentelemetry/sdk/autoconfigure/SpanExporterConfiguration.java +++ b/sdk-extensions/autoconfigure/src/main/java/io/opentelemetry/sdk/autoconfigure/SpanExporterConfiguration.java @@ -14,6 +14,7 @@ import io.opentelemetry.exporter.internal.retry.RetryUtil; import io.opentelemetry.exporter.jaeger.JaegerGrpcSpanExporter; import io.opentelemetry.exporter.jaeger.JaegerGrpcSpanExporterBuilder; +import io.opentelemetry.exporter.logging.otlp.OtlpJsonLoggingSpanExporter; import io.opentelemetry.exporter.otlp.http.trace.OtlpHttpSpanExporter; import io.opentelemetry.exporter.otlp.http.trace.OtlpHttpSpanExporterBuilder; import io.opentelemetry.exporter.otlp.trace.OtlpGrpcSpanExporter; @@ -98,6 +99,12 @@ static SpanExporter configureExporter( return configureJaeger(config, meterProvider); case "zipkin": return configureZipkin(config); + case "logging-otlp": + ClasspathUtil.checkClassExists( + "io.opentelemetry.exporter.logging.otlp.OtlpJsonLoggingSpanExporter", + "OTLP JSON Logging Trace Exporter", + "opentelemetry-exporter-logging-otlp"); + return OtlpJsonLoggingSpanExporter.create(); default: SpanExporter spiExporter = spiExportersManager.getByName(name); if (spiExporter == null) { diff --git a/sdk-extensions/autoconfigure/src/test/java/io/opentelemetry/sdk/autoconfigure/NotOnClasspathTest.java b/sdk-extensions/autoconfigure/src/test/java/io/opentelemetry/sdk/autoconfigure/NotOnClasspathTest.java index f3c36438fd0..06d971c8fc6 100644 --- a/sdk-extensions/autoconfigure/src/test/java/io/opentelemetry/sdk/autoconfigure/NotOnClasspathTest.java +++ b/sdk-extensions/autoconfigure/src/test/java/io/opentelemetry/sdk/autoconfigure/NotOnClasspathTest.java @@ -81,6 +81,18 @@ void loggingSpans() { + " Make sure to add it as a dependency."); } + @Test + void loggingSpansOtlp() { + assertThatThrownBy( + () -> + SpanExporterConfiguration.configureExporter( + "logging-otlp", EMPTY, NamedSpiManager.createEmpty(), MeterProvider.noop())) + .isInstanceOf(ConfigurationException.class) + .hasMessageContaining( + "OTLP JSON Logging Trace Exporter enabled but opentelemetry-exporter-logging-otlp not found on " + + "classpath"); + } + @Test void loggingMetrics() { assertThatThrownBy( @@ -96,6 +108,21 @@ void loggingMetrics() { + " Make sure to add it as a dependency."); } + @Test + void loggingMetricsOtlp() { + assertThatThrownBy( + () -> + MetricExporterConfiguration.configureExporter( + "logging-otlp", + EMPTY, + MetricExporterConfiguration.class.getClassLoader(), + (a, unused) -> a)) + .isInstanceOf(ConfigurationException.class) + .hasMessageContaining( + "OTLP JSON Logging Metrics Exporter enabled but opentelemetry-exporter-logging-otlp not found on " + + "classpath"); + } + @Test void loggingLogs() { assertThatThrownBy( @@ -108,6 +135,18 @@ void loggingLogs() { + " Make sure to add it as a dependency."); } + @Test + void loggingLogsOtlp() { + assertThatThrownBy( + () -> + LogRecordExporterConfiguration.configureExporter( + "logging-otlp", EMPTY, NamedSpiManager.createEmpty(), MeterProvider.noop())) + .isInstanceOf(ConfigurationException.class) + .hasMessageContaining( + "OTLP JSON Logging Log Exporter enabled but opentelemetry-exporter-logging-otlp not found on " + + "classpath"); + } + @Test void otlpGrpcMetrics() { assertThatCode( diff --git a/sdk-extensions/autoconfigure/src/testLoggingOtlp/java/io/opentelemetry/sdk/autoconfigure/LoggingOtlpTest.java b/sdk-extensions/autoconfigure/src/testLoggingOtlp/java/io/opentelemetry/sdk/autoconfigure/LoggingOtlpTest.java new file mode 100644 index 00000000000..aba93ae800e --- /dev/null +++ b/sdk-extensions/autoconfigure/src/testLoggingOtlp/java/io/opentelemetry/sdk/autoconfigure/LoggingOtlpTest.java @@ -0,0 +1,66 @@ +/* + * Copyright The OpenTelemetry Authors + * SPDX-License-Identifier: Apache-2.0 + */ + +package io.opentelemetry.sdk.autoconfigure; + +import static org.assertj.core.api.Assertions.assertThat; +import static org.awaitility.Awaitility.await; + +import com.google.common.collect.ImmutableMap; +import io.github.netmikey.logunit.api.LogCapturer; +import io.opentelemetry.exporter.logging.otlp.OtlpJsonLoggingLogRecordExporter; +import io.opentelemetry.exporter.logging.otlp.OtlpJsonLoggingMetricExporter; +import io.opentelemetry.exporter.logging.otlp.OtlpJsonLoggingSpanExporter; +import io.opentelemetry.sdk.OpenTelemetrySdk; +import java.util.concurrent.TimeUnit; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.RegisterExtension; + +class LoggingOtlpTest { + + @RegisterExtension + LogCapturer spansCapturer = + LogCapturer.create().captureForType(OtlpJsonLoggingSpanExporter.class); + + @RegisterExtension + LogCapturer metricsCapturer = + LogCapturer.create().captureForType(OtlpJsonLoggingMetricExporter.class); + + @RegisterExtension + LogCapturer logsCapturer = + LogCapturer.create().captureForType(OtlpJsonLoggingLogRecordExporter.class); + + @Test + void configures() { + OpenTelemetrySdk sdk = + AutoConfiguredOpenTelemetrySdk.builder() + .setConfig( + DefaultConfigProperties.createForTest( + ImmutableMap.of( + "otel.traces.exporter", "logging-otlp", + "otel.metrics.exporter", "logging-otlp", + "otel.logs.exporter", "logging-otlp"))) + .setResultAsGlobal(false) + .build() + .getOpenTelemetrySdk(); + + sdk.getTracerProvider().get("tracer").spanBuilder("test").startSpan().end(); + sdk.getMeterProvider().get("meter").counterBuilder("counter").build().add(10); + sdk.getSdkLoggerProvider().get("logger").logRecordBuilder().setBody("message").emit(); + + sdk.getSdkLoggerProvider().forceFlush().join(10, TimeUnit.SECONDS); + sdk.getSdkMeterProvider().forceFlush().join(10, TimeUnit.SECONDS); + sdk.getSdkLoggerProvider().forceFlush().join(10, TimeUnit.SECONDS); + + await() + .untilAsserted( + () -> assertThat(spansCapturer.getEvents().size()).isGreaterThanOrEqualTo(1)); + await() + .untilAsserted( + () -> assertThat(metricsCapturer.getEvents().size()).isGreaterThanOrEqualTo(1)); + await() + .untilAsserted(() -> assertThat(logsCapturer.getEvents().size()).isGreaterThanOrEqualTo(1)); + } +} diff --git a/sdk/metrics/src/jmh/java/io/opentelemetry/sdk/metrics/internal/aggregator/HistogramValueGenerator.java b/sdk/metrics/src/jmh/java/io/opentelemetry/sdk/metrics/internal/aggregator/HistogramValueGenerator.java index cbe48550dc6..aa603878640 100644 --- a/sdk/metrics/src/jmh/java/io/opentelemetry/sdk/metrics/internal/aggregator/HistogramValueGenerator.java +++ b/sdk/metrics/src/jmh/java/io/opentelemetry/sdk/metrics/internal/aggregator/HistogramValueGenerator.java @@ -61,8 +61,6 @@ public double getAsDouble() { /** Constructs a pool using explicit bucket histogram boundaries. */ private static double[] explicitDefaultBucketPool() { List fixedBoundaries = new ArrayList(); - // Add minimal recording value. - fixedBoundaries.add(0.0); // Add the bucket LE bucket boundaries (starts at 5). fixedBoundaries.addAll(ExplicitBucketHistogramUtils.DEFAULT_HISTOGRAM_BUCKET_BOUNDARIES); // Add Double max value as our other extreme. From 0fc41d4c307d56f87fc4f0ffd42aa78b90feb70c Mon Sep 17 00:00:00 2001 From: jack-berg <34418638+jack-berg@users.noreply.github.com> Date: Mon, 28 Nov 2022 14:08:13 -0600 Subject: [PATCH 60/68] Implement zipkin exporter provider (#4991) --- exporters/zipkin/build.gradle.kts | 1 + .../internal/ZipkinSpanExporterProvider.java | 43 +++++++++++++++++++ ...pi.traces.ConfigurableSpanExporterProvider | 1 + sdk-extensions/autoconfigure/build.gradle.kts | 1 - .../SpanExporterConfiguration.java | 43 ++++++------------- .../sdk/autoconfigure/NotOnClasspathTest.java | 3 +- .../SpanExporterConfigurationTest.java | 10 +++-- 7 files changed, 67 insertions(+), 35 deletions(-) create mode 100644 exporters/zipkin/src/main/java/io/opentelemetry/exporter/zipkin/internal/ZipkinSpanExporterProvider.java create mode 100644 exporters/zipkin/src/main/resources/META-INF/services/io.opentelemetry.sdk.autoconfigure.spi.traces.ConfigurableSpanExporterProvider diff --git a/exporters/zipkin/build.gradle.kts b/exporters/zipkin/build.gradle.kts index 69d95fad01e..77343900a19 100644 --- a/exporters/zipkin/build.gradle.kts +++ b/exporters/zipkin/build.gradle.kts @@ -15,6 +15,7 @@ dependencies { implementation(project(":exporters:common")) implementation(project(":semconv")) + implementation(project(":sdk-extensions:autoconfigure-spi")) implementation("io.zipkin.reporter2:zipkin-sender-okhttp3") diff --git a/exporters/zipkin/src/main/java/io/opentelemetry/exporter/zipkin/internal/ZipkinSpanExporterProvider.java b/exporters/zipkin/src/main/java/io/opentelemetry/exporter/zipkin/internal/ZipkinSpanExporterProvider.java new file mode 100644 index 00000000000..cbd55d386dc --- /dev/null +++ b/exporters/zipkin/src/main/java/io/opentelemetry/exporter/zipkin/internal/ZipkinSpanExporterProvider.java @@ -0,0 +1,43 @@ +/* + * Copyright The OpenTelemetry Authors + * SPDX-License-Identifier: Apache-2.0 + */ + +package io.opentelemetry.exporter.zipkin.internal; + +import io.opentelemetry.exporter.zipkin.ZipkinSpanExporter; +import io.opentelemetry.exporter.zipkin.ZipkinSpanExporterBuilder; +import io.opentelemetry.sdk.autoconfigure.spi.ConfigProperties; +import io.opentelemetry.sdk.autoconfigure.spi.traces.ConfigurableSpanExporterProvider; +import io.opentelemetry.sdk.trace.export.SpanExporter; +import java.time.Duration; + +/** + * {@link SpanExporter} SPI implementation for {@link ZipkinSpanExporter}. + * + *

This class is internal and is hence not for public use. Its APIs are unstable and can change + * at any time. + */ +public class ZipkinSpanExporterProvider implements ConfigurableSpanExporterProvider { + @Override + public String getName() { + return "zipkin"; + } + + @Override + public SpanExporter createExporter(ConfigProperties config) { + ZipkinSpanExporterBuilder builder = ZipkinSpanExporter.builder(); + + String endpoint = config.getString("otel.exporter.zipkin.endpoint"); + if (endpoint != null) { + builder.setEndpoint(endpoint); + } + + Duration timeout = config.getDuration("otel.exporter.zipkin.timeout"); + if (timeout != null) { + builder.setReadTimeout(timeout); + } + + return builder.build(); + } +} diff --git a/exporters/zipkin/src/main/resources/META-INF/services/io.opentelemetry.sdk.autoconfigure.spi.traces.ConfigurableSpanExporterProvider b/exporters/zipkin/src/main/resources/META-INF/services/io.opentelemetry.sdk.autoconfigure.spi.traces.ConfigurableSpanExporterProvider new file mode 100644 index 00000000000..8a45b6fab18 --- /dev/null +++ b/exporters/zipkin/src/main/resources/META-INF/services/io.opentelemetry.sdk.autoconfigure.spi.traces.ConfigurableSpanExporterProvider @@ -0,0 +1 @@ +io.opentelemetry.exporter.zipkin.internal.ZipkinSpanExporterProvider diff --git a/sdk-extensions/autoconfigure/build.gradle.kts b/sdk-extensions/autoconfigure/build.gradle.kts index 7c1d6b827a3..0f9fc1295ec 100644 --- a/sdk-extensions/autoconfigure/build.gradle.kts +++ b/sdk-extensions/autoconfigure/build.gradle.kts @@ -21,7 +21,6 @@ dependencies { compileOnly(project(":exporters:otlp:logs")) compileOnly(project(":exporters:otlp:common")) compileOnly(project(":exporters:prometheus")) - compileOnly(project(":exporters:zipkin")) annotationProcessor("com.google.auto.value:auto-value") diff --git a/sdk-extensions/autoconfigure/src/main/java/io/opentelemetry/sdk/autoconfigure/SpanExporterConfiguration.java b/sdk-extensions/autoconfigure/src/main/java/io/opentelemetry/sdk/autoconfigure/SpanExporterConfiguration.java index 380cc3c5eaf..7c19a82f45c 100644 --- a/sdk-extensions/autoconfigure/src/main/java/io/opentelemetry/sdk/autoconfigure/SpanExporterConfiguration.java +++ b/sdk-extensions/autoconfigure/src/main/java/io/opentelemetry/sdk/autoconfigure/SpanExporterConfiguration.java @@ -19,8 +19,6 @@ import io.opentelemetry.exporter.otlp.http.trace.OtlpHttpSpanExporterBuilder; import io.opentelemetry.exporter.otlp.trace.OtlpGrpcSpanExporter; import io.opentelemetry.exporter.otlp.trace.OtlpGrpcSpanExporterBuilder; -import io.opentelemetry.exporter.zipkin.ZipkinSpanExporter; -import io.opentelemetry.exporter.zipkin.ZipkinSpanExporterBuilder; import io.opentelemetry.sdk.autoconfigure.spi.ConfigProperties; import io.opentelemetry.sdk.autoconfigure.spi.ConfigurationException; import io.opentelemetry.sdk.autoconfigure.spi.traces.ConfigurableSpanExporterProvider; @@ -41,6 +39,7 @@ final class SpanExporterConfiguration { static { EXPORTER_ARTIFACT_ID_BY_NAME = new HashMap<>(); EXPORTER_ARTIFACT_ID_BY_NAME.put("logging", "opentelemetry-exporter-logging"); + EXPORTER_ARTIFACT_ID_BY_NAME.put("zipkin", "opentelemetry-exporter-zipkin"); } // Visible for testing @@ -69,12 +68,7 @@ static Map configureSpanExporters( } NamedSpiManager spiExportersManager = - SpiUtil.loadConfigurable( - ConfigurableSpanExporterProvider.class, - ConfigurableSpanExporterProvider::getName, - ConfigurableSpanExporterProvider::createExporter, - config, - serviceClassLoader); + spanExporterSpiManager(config, serviceClassLoader); return exporterNames.stream() .collect( @@ -86,6 +80,17 @@ static Map configureSpanExporters( config))); } + // Visible for testing + static NamedSpiManager spanExporterSpiManager( + ConfigProperties config, ClassLoader serviceClassLoader) { + return SpiUtil.loadConfigurable( + ConfigurableSpanExporterProvider.class, + ConfigurableSpanExporterProvider::getName, + ConfigurableSpanExporterProvider::createExporter, + config, + serviceClassLoader); + } + // Visible for testing static SpanExporter configureExporter( String name, @@ -97,8 +102,6 @@ static SpanExporter configureExporter( return configureOtlp(config, meterProvider); case "jaeger": return configureJaeger(config, meterProvider); - case "zipkin": - return configureZipkin(config); case "logging-otlp": ClasspathUtil.checkClassExists( "io.opentelemetry.exporter.logging.otlp.OtlpJsonLoggingSpanExporter", @@ -196,25 +199,5 @@ private static SpanExporter configureJaeger( return builder.build(); } - private static SpanExporter configureZipkin(ConfigProperties config) { - ClasspathUtil.checkClassExists( - "io.opentelemetry.exporter.zipkin.ZipkinSpanExporter", - "Zipkin Exporter", - "opentelemetry-exporter-zipkin"); - ZipkinSpanExporterBuilder builder = ZipkinSpanExporter.builder(); - - String endpoint = config.getString("otel.exporter.zipkin.endpoint"); - if (endpoint != null) { - builder.setEndpoint(endpoint); - } - - Duration timeout = config.getDuration("otel.exporter.zipkin.timeout"); - if (timeout != null) { - builder.setReadTimeout(timeout); - } - - return builder.build(); - } - private SpanExporterConfiguration() {} } diff --git a/sdk-extensions/autoconfigure/src/test/java/io/opentelemetry/sdk/autoconfigure/NotOnClasspathTest.java b/sdk-extensions/autoconfigure/src/test/java/io/opentelemetry/sdk/autoconfigure/NotOnClasspathTest.java index 06d971c8fc6..2abb4617b7e 100644 --- a/sdk-extensions/autoconfigure/src/test/java/io/opentelemetry/sdk/autoconfigure/NotOnClasspathTest.java +++ b/sdk-extensions/autoconfigure/src/test/java/io/opentelemetry/sdk/autoconfigure/NotOnClasspathTest.java @@ -66,7 +66,8 @@ void zipkin() { "zipkin", EMPTY, NamedSpiManager.createEmpty(), MeterProvider.noop())) .isInstanceOf(ConfigurationException.class) .hasMessageContaining( - "Zipkin Exporter enabled but opentelemetry-exporter-zipkin not found on classpath"); + "otel.traces.exporter set to \"zipkin\" but opentelemetry-exporter-zipkin not found on classpath." + + " Make sure to add it as a dependency."); } @Test diff --git a/sdk-extensions/autoconfigure/src/testFullConfig/java/io/opentelemetry/sdk/autoconfigure/SpanExporterConfigurationTest.java b/sdk-extensions/autoconfigure/src/testFullConfig/java/io/opentelemetry/sdk/autoconfigure/SpanExporterConfigurationTest.java index 8622f8f6a10..5bc04ef890f 100644 --- a/sdk-extensions/autoconfigure/src/testFullConfig/java/io/opentelemetry/sdk/autoconfigure/SpanExporterConfigurationTest.java +++ b/sdk-extensions/autoconfigure/src/testFullConfig/java/io/opentelemetry/sdk/autoconfigure/SpanExporterConfigurationTest.java @@ -12,6 +12,7 @@ import io.opentelemetry.api.metrics.MeterProvider; import io.opentelemetry.exporter.jaeger.JaegerGrpcSpanExporter; import io.opentelemetry.exporter.otlp.trace.OtlpGrpcSpanExporter; +import io.opentelemetry.sdk.autoconfigure.spi.ConfigProperties; import io.opentelemetry.sdk.autoconfigure.spi.ConfigurationException; import io.opentelemetry.sdk.trace.export.SpanExporter; import java.util.Collections; @@ -76,12 +77,15 @@ void configureJaegerTimeout() { // Timeout difficult to test using real exports so just check that things don't blow up. @Test void configureZipkinTimeout() { + ConfigProperties config = + DefaultConfigProperties.createForTest( + Collections.singletonMap("otel.exporter.zipkin.timeout", "5s")); SpanExporter exporter = SpanExporterConfiguration.configureExporter( "zipkin", - DefaultConfigProperties.createForTest( - Collections.singletonMap("otel.exporter.zipkin.timeout", "5s")), - NamedSpiManager.createEmpty(), + config, + SpanExporterConfiguration.spanExporterSpiManager( + config, SpanExporterConfigurationTest.class.getClassLoader()), MeterProvider.noop()); try { assertThat(exporter).isNotNull(); From df74d4cca5ffc1afe315bef473b50dbb3d9858ea Mon Sep 17 00:00:00 2001 From: Jonatan Ivanov Date: Mon, 28 Nov 2022 12:16:14 -0800 Subject: [PATCH 61/68] Populate Zipkin remoteEndpoint (#4933) * Populate Zipkin remoteEndpoint fixes gh-4932 * Add conditions for creating zipkin remote endpoint * Parameterize remote endpoint tests with span kind * Verify INTERNAL span kind too --- .../zipkin/OtelToZipkinSpanTransformer.java | 35 ++- .../OtelToZipkinSpanTransformerTest.java | 204 +++++++++++++++++- .../exporter/zipkin/ZipkinTestUtil.java | 5 +- 3 files changed, 234 insertions(+), 10 deletions(-) diff --git a/exporters/zipkin/src/main/java/io/opentelemetry/exporter/zipkin/OtelToZipkinSpanTransformer.java b/exporters/zipkin/src/main/java/io/opentelemetry/exporter/zipkin/OtelToZipkinSpanTransformer.java index 5fb82c7389f..a67731e99d0 100644 --- a/exporters/zipkin/src/main/java/io/opentelemetry/exporter/zipkin/OtelToZipkinSpanTransformer.java +++ b/exporters/zipkin/src/main/java/io/opentelemetry/exporter/zipkin/OtelToZipkinSpanTransformer.java @@ -6,11 +6,15 @@ package io.opentelemetry.exporter.zipkin; import static io.opentelemetry.api.common.AttributeKey.stringKey; +import static io.opentelemetry.semconv.trace.attributes.SemanticAttributes.NET_PEER_PORT; +import static io.opentelemetry.semconv.trace.attributes.SemanticAttributes.NET_SOCK_PEER_ADDR; +import static io.opentelemetry.semconv.trace.attributes.SemanticAttributes.PEER_SERVICE; import static java.util.concurrent.TimeUnit.NANOSECONDS; import io.opentelemetry.api.common.AttributeKey; import io.opentelemetry.api.common.AttributeType; import io.opentelemetry.api.common.Attributes; +import io.opentelemetry.api.trace.SpanKind; import io.opentelemetry.api.trace.StatusCode; import io.opentelemetry.sdk.common.InstrumentationScopeInfo; import io.opentelemetry.sdk.resources.Resource; @@ -71,8 +75,6 @@ private OtelToZipkinSpanTransformer(Supplier ipAddressSupplier) { * @return a new Zipkin Span */ Span generateSpan(SpanData spanData) { - Endpoint endpoint = getEndpoint(spanData); - long startTimestamp = toEpochMicros(spanData.getStartEpochNanos()); long endTimestamp = toEpochMicros(spanData.getEndEpochNanos()); @@ -84,7 +86,8 @@ Span generateSpan(SpanData spanData) { .name(spanData.getName()) .timestamp(toEpochMicros(spanData.getStartEpochNanos())) .duration(Math.max(1, endTimestamp - startTimestamp)) - .localEndpoint(endpoint); + .localEndpoint(getLocalEndpoint(spanData)) + .remoteEndpoint(getRemoteEndpoint(spanData)); if (spanData.getParentSpanContext().isValid()) { spanBuilder.parentId(spanData.getParentSpanId()); @@ -140,7 +143,7 @@ private static String nullToEmpty(@Nullable String value) { return value != null ? value : ""; } - private Endpoint getEndpoint(SpanData spanData) { + private Endpoint getLocalEndpoint(SpanData spanData) { Attributes resourceAttributes = spanData.getResource().getAttributes(); Endpoint.Builder endpoint = Endpoint.newBuilder(); @@ -158,6 +161,30 @@ private Endpoint getEndpoint(SpanData spanData) { return endpoint.build(); } + @Nullable + private static Endpoint getRemoteEndpoint(SpanData spanData) { + if (spanData.getKind() == SpanKind.CLIENT || spanData.getKind() == SpanKind.PRODUCER) { + // TODO: Implement fallback mechanism: + // https://opentelemetry.io/docs/reference/specification/trace/sdk_exporters/zipkin/#otlp---zipkin + Attributes attributes = spanData.getAttributes(); + String serviceName = attributes.get(PEER_SERVICE); + + if (serviceName != null) { + Endpoint.Builder endpoint = Endpoint.newBuilder(); + endpoint.serviceName(serviceName); + endpoint.ip(attributes.get(NET_SOCK_PEER_ADDR)); + Long port = attributes.get(NET_PEER_PORT); + if (port != null) { + endpoint.port(port.intValue()); + } + + return endpoint.build(); + } + } + + return null; + } + @Nullable private static Span.Kind toSpanKind(SpanData spanData) { switch (spanData.getKind()) { diff --git a/exporters/zipkin/src/test/java/io/opentelemetry/exporter/zipkin/OtelToZipkinSpanTransformerTest.java b/exporters/zipkin/src/test/java/io/opentelemetry/exporter/zipkin/OtelToZipkinSpanTransformerTest.java index b47b23e5d2d..230ab38894c 100644 --- a/exporters/zipkin/src/test/java/io/opentelemetry/exporter/zipkin/OtelToZipkinSpanTransformerTest.java +++ b/exporters/zipkin/src/test/java/io/opentelemetry/exporter/zipkin/OtelToZipkinSpanTransformerTest.java @@ -16,6 +16,9 @@ import static io.opentelemetry.exporter.zipkin.ZipkinTestUtil.spanBuilder; import static io.opentelemetry.exporter.zipkin.ZipkinTestUtil.zipkinSpan; import static io.opentelemetry.exporter.zipkin.ZipkinTestUtil.zipkinSpanBuilder; +import static io.opentelemetry.semconv.trace.attributes.SemanticAttributes.NET_PEER_PORT; +import static io.opentelemetry.semconv.trace.attributes.SemanticAttributes.NET_SOCK_PEER_ADDR; +import static io.opentelemetry.semconv.trace.attributes.SemanticAttributes.PEER_SERVICE; import static org.assertj.core.api.Assertions.assertThat; import static org.mockito.Mockito.mock; @@ -31,8 +34,11 @@ import java.net.InetAddress; import java.util.Arrays; import java.util.Collections; +import javax.annotation.Nullable; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.EnumSource; import zipkin2.Endpoint; import zipkin2.Span; @@ -135,11 +141,11 @@ void generateSpan_ResourceServiceNameMapping() { Resource.create(Attributes.of(ResourceAttributes.SERVICE_NAME, "super-zipkin-service")); SpanData data = spanBuilder().setResource(resource).build(); - Endpoint expectedEndpoint = + Endpoint expectedLocalEndpoint = Endpoint.newBuilder().serviceName("super-zipkin-service").ip(localIp).build(); Span expectedZipkinSpan = zipkinSpan(Span.Kind.SERVER, localIp).toBuilder() - .localEndpoint(expectedEndpoint) + .localEndpoint(expectedLocalEndpoint) .putTag(OtelToZipkinSpanTransformer.OTEL_STATUS_CODE, "OK") .build(); assertThat(transformer.generateSpan(data)).isEqualTo(expectedZipkinSpan); @@ -149,19 +155,204 @@ void generateSpan_ResourceServiceNameMapping() { void generateSpan_defaultResourceServiceName() { SpanData data = spanBuilder().setResource(Resource.empty()).build(); - Endpoint expectedEndpoint = + Endpoint expectedLocalEndpoint = Endpoint.newBuilder() .serviceName(Resource.getDefault().getAttribute(ResourceAttributes.SERVICE_NAME)) .ip(localIp) .build(); Span expectedZipkinSpan = zipkinSpan(Span.Kind.SERVER, localIp).toBuilder() - .localEndpoint(expectedEndpoint) + .localEndpoint(expectedLocalEndpoint) .putTag(OtelToZipkinSpanTransformer.OTEL_STATUS_CODE, "OK") .build(); assertThat(transformer.generateSpan(data)).isEqualTo(expectedZipkinSpan); } + @ParameterizedTest + @EnumSource( + value = SpanKind.class, + names = {"CLIENT", "PRODUCER"}) + void generateSpan_RemoteEndpointMapping(SpanKind spanKind) { + Attributes attributes = + Attributes.builder() + .put(PEER_SERVICE, "remote-test-service") + .put(NET_SOCK_PEER_ADDR, "8.8.8.8") + .put(NET_PEER_PORT, 42L) + .build(); + + SpanData spanData = + spanBuilder() + .setKind(spanKind) + .setResource(Resource.empty()) + .setAttributes(attributes) + .build(); + + Endpoint expectedLocalEndpoint = + Endpoint.newBuilder() + .serviceName(Resource.getDefault().getAttribute(ResourceAttributes.SERVICE_NAME)) + .ip(localIp) + .build(); + + Endpoint expectedRemoteEndpoint = + Endpoint.newBuilder().serviceName("remote-test-service").ip("8.8.8.8").port(42).build(); + + Span expectedSpan = + zipkinSpan(toZipkinSpanKind(spanKind), localIp).toBuilder() + .localEndpoint(expectedLocalEndpoint) + .remoteEndpoint(expectedRemoteEndpoint) + .putTag(PEER_SERVICE.getKey(), "remote-test-service") + .putTag(NET_SOCK_PEER_ADDR.getKey(), "8.8.8.8") + .putTag(NET_PEER_PORT.getKey(), "42") + .putTag(OtelToZipkinSpanTransformer.OTEL_STATUS_CODE, "OK") + .build(); + + assertThat(transformer.generateSpan(spanData)).isEqualTo(expectedSpan); + } + + @ParameterizedTest + @EnumSource( + value = SpanKind.class, + names = {"SERVER", "CONSUMER", "INTERNAL"}) + void generateSpan_RemoteEndpointMappingWhenKindIsNotClientOrProducer(SpanKind spanKind) { + Attributes attributes = + Attributes.builder() + .put(PEER_SERVICE, "remote-test-service") + .put(NET_SOCK_PEER_ADDR, "8.8.8.8") + .put(NET_PEER_PORT, 42L) + .build(); + + SpanData spanData = + spanBuilder() + .setKind(spanKind) + .setResource(Resource.empty()) + .setAttributes(attributes) + .build(); + + Endpoint expectedLocalEndpoint = + Endpoint.newBuilder() + .serviceName(Resource.getDefault().getAttribute(ResourceAttributes.SERVICE_NAME)) + .ip(localIp) + .build(); + + Span expectedSpan = + zipkinSpan(toZipkinSpanKind(spanKind), localIp).toBuilder() + .localEndpoint(expectedLocalEndpoint) + .remoteEndpoint(null) + .putTag(PEER_SERVICE.getKey(), "remote-test-service") + .putTag(NET_SOCK_PEER_ADDR.getKey(), "8.8.8.8") + .putTag(NET_PEER_PORT.getKey(), "42") + .putTag(OtelToZipkinSpanTransformer.OTEL_STATUS_CODE, "OK") + .build(); + + assertThat(transformer.generateSpan(spanData)).isEqualTo(expectedSpan); + } + + @ParameterizedTest + @EnumSource( + value = SpanKind.class, + names = {"CLIENT", "PRODUCER"}) + void generateSpan_RemoteEndpointMappingWhenServiceNameIsMissing(SpanKind spanKind) { + Attributes attributes = + Attributes.builder().put(NET_SOCK_PEER_ADDR, "8.8.8.8").put(NET_PEER_PORT, 42L).build(); + + SpanData spanData = + spanBuilder() + .setKind(spanKind) + .setResource(Resource.empty()) + .setAttributes(attributes) + .build(); + + Endpoint expectedLocalEndpoint = + Endpoint.newBuilder() + .serviceName(Resource.getDefault().getAttribute(ResourceAttributes.SERVICE_NAME)) + .ip(localIp) + .build(); + + Span expectedSpan = + zipkinSpan(toZipkinSpanKind(spanKind), localIp).toBuilder() + .localEndpoint(expectedLocalEndpoint) + .remoteEndpoint(null) + .putTag(NET_SOCK_PEER_ADDR.getKey(), "8.8.8.8") + .putTag(NET_PEER_PORT.getKey(), "42") + .putTag(OtelToZipkinSpanTransformer.OTEL_STATUS_CODE, "OK") + .build(); + + assertThat(transformer.generateSpan(spanData)).isEqualTo(expectedSpan); + } + + @ParameterizedTest + @EnumSource( + value = SpanKind.class, + names = {"CLIENT", "PRODUCER"}) + void generateSpan_RemoteEndpointMappingWhenPortIsMissing(SpanKind spanKind) { + Attributes attributes = + Attributes.builder() + .put(PEER_SERVICE, "remote-test-service") + .put(NET_SOCK_PEER_ADDR, "8.8.8.8") + .build(); + + SpanData spanData = + spanBuilder() + .setKind(spanKind) + .setResource(Resource.empty()) + .setAttributes(attributes) + .build(); + + Endpoint expectedLocalEndpoint = + Endpoint.newBuilder() + .serviceName(Resource.getDefault().getAttribute(ResourceAttributes.SERVICE_NAME)) + .ip(localIp) + .build(); + + Endpoint expectedRemoteEndpoint = + Endpoint.newBuilder().serviceName("remote-test-service").ip("8.8.8.8").build(); + + Span expectedSpan = + zipkinSpan(toZipkinSpanKind(spanKind), localIp).toBuilder() + .localEndpoint(expectedLocalEndpoint) + .remoteEndpoint(expectedRemoteEndpoint) + .putTag(PEER_SERVICE.getKey(), "remote-test-service") + .putTag(NET_SOCK_PEER_ADDR.getKey(), "8.8.8.8") + .putTag(OtelToZipkinSpanTransformer.OTEL_STATUS_CODE, "OK") + .build(); + + assertThat(transformer.generateSpan(spanData)).isEqualTo(expectedSpan); + } + + @ParameterizedTest + @EnumSource( + value = SpanKind.class, + names = {"CLIENT", "PRODUCER"}) + void generateSpan_RemoteEndpointMappingWhenIpAndPortAreMissing(SpanKind spanKind) { + Attributes attributes = Attributes.builder().put(PEER_SERVICE, "remote-test-service").build(); + + SpanData spanData = + spanBuilder() + .setKind(spanKind) + .setResource(Resource.empty()) + .setAttributes(attributes) + .build(); + + Endpoint expectedLocalEndpoint = + Endpoint.newBuilder() + .serviceName(Resource.getDefault().getAttribute(ResourceAttributes.SERVICE_NAME)) + .ip(localIp) + .build(); + + Endpoint expectedRemoteEndpoint = + Endpoint.newBuilder().serviceName("remote-test-service").build(); + + Span expectedSpan = + zipkinSpan(toZipkinSpanKind(spanKind), localIp).toBuilder() + .localEndpoint(expectedLocalEndpoint) + .remoteEndpoint(expectedRemoteEndpoint) + .putTag(PEER_SERVICE.getKey(), "remote-test-service") + .putTag(OtelToZipkinSpanTransformer.OTEL_STATUS_CODE, "OK") + .build(); + + assertThat(transformer.generateSpan(spanData)).isEqualTo(expectedSpan); + } + @Test void generateSpan_WithAttributes() { Attributes attributes = @@ -304,4 +495,9 @@ void generateSpan_WithRpcUnsetStatus() { .putTag(SemanticAttributes.RPC_SERVICE.getKey(), "my service name") .build()); } + + @Nullable + private static Span.Kind toZipkinSpanKind(SpanKind spanKind) { + return spanKind != SpanKind.INTERNAL ? Span.Kind.valueOf(spanKind.name()) : null; + } } diff --git a/exporters/zipkin/src/test/java/io/opentelemetry/exporter/zipkin/ZipkinTestUtil.java b/exporters/zipkin/src/test/java/io/opentelemetry/exporter/zipkin/ZipkinTestUtil.java index 5f8ffe8c4a9..2f303a7943f 100644 --- a/exporters/zipkin/src/test/java/io/opentelemetry/exporter/zipkin/ZipkinTestUtil.java +++ b/exporters/zipkin/src/test/java/io/opentelemetry/exporter/zipkin/ZipkinTestUtil.java @@ -19,6 +19,7 @@ import java.util.Arrays; import java.util.Collections; import java.util.List; +import javax.annotation.Nullable; import zipkin2.Endpoint; import zipkin2.Span; @@ -60,11 +61,11 @@ static TestSpanData.Builder spanBuilder() { .setHasEnded(true); } - static Span zipkinSpan(Span.Kind kind, InetAddress localIp) { + static Span zipkinSpan(@Nullable Span.Kind kind, InetAddress localIp) { return zipkinSpanBuilder(kind, localIp).build(); } - static Span.Builder zipkinSpanBuilder(Span.Kind kind, InetAddress localIp) { + static Span.Builder zipkinSpanBuilder(@Nullable Span.Kind kind, InetAddress localIp) { return Span.newBuilder() .traceId(TRACE_ID) .parentId(PARENT_SPAN_ID) From 5442ea0b30d8d32b34a8bde62dfbb1e2f9c6449a Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Tue, 29 Nov 2022 06:31:35 -0800 Subject: [PATCH 62/68] Bump org.jetbrains.kotlin.jvm from 1.7.21 to 1.7.22 (#4997) --- settings.gradle.kts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/settings.gradle.kts b/settings.gradle.kts index 3dcb6964cab..9963fa9b833 100644 --- a/settings.gradle.kts +++ b/settings.gradle.kts @@ -4,7 +4,7 @@ pluginManagement { id("com.github.johnrengelman.shadow") version "7.1.2" id("com.gradle.enterprise") version "3.11.4" id("io.github.gradle-nexus.publish-plugin") version "1.1.0" - id("org.jetbrains.kotlin.jvm") version "1.7.21" + id("org.jetbrains.kotlin.jvm") version "1.7.22" id("org.graalvm.buildtools.native") version "0.9.18" } } From 5fb50c1d5e314b61a5beca367d736f6136b59a36 Mon Sep 17 00:00:00 2001 From: jack-berg <34418638+jack-berg@users.noreply.github.com> Date: Tue, 29 Nov 2022 10:37:31 -0600 Subject: [PATCH 63/68] Add toString implementation to various propagator components (#4996) --- .../propagation/W3CBaggagePropagator.java | 5 ++++ .../W3CTraceContextPropagator.java | 5 ++++ .../propagation/W3CBaggagePropagatorTest.java | 5 ++++ .../W3CTraceContextPropagatorTest.java | 5 ++++ .../DefaultContextPropagators.java | 5 ++++ .../propagation/MultiTextMapPropagator.java | 23 +++++++++++-------- .../propagation/NoopTextMapPropagator.java | 5 ++++ .../MultiTextMapPropagatorTest.java | 6 +++++ .../NoopTextMapPropagatorTest.java | 5 ++++ .../current_vs_latest/opentelemetry-api.txt | 7 +++++- ...ntelemetry-extension-trace-propagators.txt | 10 +++++++- .../propagation/PassThroughPropagator.java | 5 ++++ .../PassThroughPropagatorTest.java | 5 ++++ .../trace/propagation/B3Propagator.java | 5 ++++ .../B3PropagatorInjectorMultipleHeaders.java | 5 ++++ .../B3PropagatorInjectorSingleHeader.java | 5 ++++ .../trace/propagation/JaegerPropagator.java | 5 ++++ .../trace/propagation/OtTracePropagator.java | 5 ++++ .../trace/propagation/B3PropagatorTest.java | 8 +++++++ .../propagation/JaegerPropagatorTest.java | 5 ++++ .../propagation/OtTracePropagatorTest.java | 5 ++++ .../opentelemetry/sdk/OpenTelemetrySdk.java | 3 ++- .../sdk/OpenTelemetrySdkTest.java | 6 ++++- 23 files changed, 130 insertions(+), 13 deletions(-) diff --git a/api/all/src/main/java/io/opentelemetry/api/baggage/propagation/W3CBaggagePropagator.java b/api/all/src/main/java/io/opentelemetry/api/baggage/propagation/W3CBaggagePropagator.java index 5c1a8b3425f..9701214e506 100644 --- a/api/all/src/main/java/io/opentelemetry/api/baggage/propagation/W3CBaggagePropagator.java +++ b/api/all/src/main/java/io/opentelemetry/api/baggage/propagation/W3CBaggagePropagator.java @@ -139,4 +139,9 @@ private static boolean isValidBaggageKey(String name) { private static boolean isValidBaggageValue(String value) { return value != null; } + + @Override + public String toString() { + return "W3CBaggagePropagator"; + } } diff --git a/api/all/src/main/java/io/opentelemetry/api/trace/propagation/W3CTraceContextPropagator.java b/api/all/src/main/java/io/opentelemetry/api/trace/propagation/W3CTraceContextPropagator.java index 91414e9412a..efcd2476b2c 100644 --- a/api/all/src/main/java/io/opentelemetry/api/trace/propagation/W3CTraceContextPropagator.java +++ b/api/all/src/main/java/io/opentelemetry/api/trace/propagation/W3CTraceContextPropagator.java @@ -213,4 +213,9 @@ private static SpanContext extractContextFromTraceParent(String traceparent) { OtelEncodingUtils.byteFromBase16(firstTraceFlagsChar, secondTraceFlagsChar)); return SpanContext.createFromRemoteParent(traceId, spanId, traceFlags, TraceState.getDefault()); } + + @Override + public String toString() { + return "W3CTraceContextPropagator"; + } } diff --git a/api/all/src/test/java/io/opentelemetry/api/baggage/propagation/W3CBaggagePropagatorTest.java b/api/all/src/test/java/io/opentelemetry/api/baggage/propagation/W3CBaggagePropagatorTest.java index 44ba8ecd7bf..3fbf7bf5297 100644 --- a/api/all/src/test/java/io/opentelemetry/api/baggage/propagation/W3CBaggagePropagatorTest.java +++ b/api/all/src/test/java/io/opentelemetry/api/baggage/propagation/W3CBaggagePropagatorTest.java @@ -473,4 +473,9 @@ void inject_nullSetter() { W3CBaggagePropagator.getInstance().inject(context, carrier, null); assertThat(carrier).isEmpty(); } + + @Test + void toString_Valid() { + assertThat(W3CBaggagePropagator.getInstance().toString()).isEqualTo("W3CBaggagePropagator"); + } } diff --git a/api/all/src/test/java/io/opentelemetry/api/trace/propagation/W3CTraceContextPropagatorTest.java b/api/all/src/test/java/io/opentelemetry/api/trace/propagation/W3CTraceContextPropagatorTest.java index b394eb37061..32b90e6277f 100644 --- a/api/all/src/test/java/io/opentelemetry/api/trace/propagation/W3CTraceContextPropagatorTest.java +++ b/api/all/src/test/java/io/opentelemetry/api/trace/propagation/W3CTraceContextPropagatorTest.java @@ -528,6 +528,11 @@ void extract_nullGetter() { .isSameAs(context); } + @Test + void toString_Valid() { + assertThat(w3cTraceContextPropagator.toString()).isEqualTo("W3CTraceContextPropagator"); + } + // Tests transplanted from the w3c test suite @ParameterizedTest diff --git a/context/src/main/java/io/opentelemetry/context/propagation/DefaultContextPropagators.java b/context/src/main/java/io/opentelemetry/context/propagation/DefaultContextPropagators.java index 28e41ed9893..dd1b8983891 100644 --- a/context/src/main/java/io/opentelemetry/context/propagation/DefaultContextPropagators.java +++ b/context/src/main/java/io/opentelemetry/context/propagation/DefaultContextPropagators.java @@ -33,4 +33,9 @@ public TextMapPropagator getTextMapPropagator() { DefaultContextPropagators(TextMapPropagator textMapPropagator) { this.textMapPropagator = textMapPropagator; } + + @Override + public String toString() { + return "DefaultContextPropagators{textMapPropagator=" + textMapPropagator + "}"; + } } diff --git a/context/src/main/java/io/opentelemetry/context/propagation/MultiTextMapPropagator.java b/context/src/main/java/io/opentelemetry/context/propagation/MultiTextMapPropagator.java index ce2cecb165c..cee960af923 100644 --- a/context/src/main/java/io/opentelemetry/context/propagation/MultiTextMapPropagator.java +++ b/context/src/main/java/io/opentelemetry/context/propagation/MultiTextMapPropagator.java @@ -16,17 +16,17 @@ import javax.annotation.Nullable; final class MultiTextMapPropagator implements TextMapPropagator { - private final TextMapPropagator[] textPropagators; + private final TextMapPropagator[] textMapPropagators; private final Collection allFields; - MultiTextMapPropagator(TextMapPropagator... textPropagators) { - this(Arrays.asList(textPropagators)); + MultiTextMapPropagator(TextMapPropagator... textMapPropagators) { + this(Arrays.asList(textMapPropagators)); } - MultiTextMapPropagator(List textPropagators) { - this.textPropagators = new TextMapPropagator[textPropagators.size()]; - textPropagators.toArray(this.textPropagators); - this.allFields = Collections.unmodifiableList(getAllFields(this.textPropagators)); + MultiTextMapPropagator(List textMapPropagators) { + this.textMapPropagators = new TextMapPropagator[textMapPropagators.size()]; + textMapPropagators.toArray(this.textMapPropagators); + this.allFields = Collections.unmodifiableList(getAllFields(this.textMapPropagators)); } @Override @@ -48,7 +48,7 @@ public void inject(Context context, @Nullable C carrier, TextMapSetter se if (context == null || setter == null) { return; } - for (TextMapPropagator textPropagator : textPropagators) { + for (TextMapPropagator textPropagator : textMapPropagators) { textPropagator.inject(context, carrier, setter); } } @@ -61,9 +61,14 @@ public Context extract(Context context, @Nullable C carrier, TextMapGetter> { INSTANCE; diff --git a/docs/apidiffs/current_vs_latest/opentelemetry-api.txt b/docs/apidiffs/current_vs_latest/opentelemetry-api.txt index df26146497b..f29157f7b32 100644 --- a/docs/apidiffs/current_vs_latest/opentelemetry-api.txt +++ b/docs/apidiffs/current_vs_latest/opentelemetry-api.txt @@ -1,2 +1,7 @@ Comparing source compatibility of against -No changes. \ No newline at end of file +*** MODIFIED CLASS: PUBLIC FINAL io.opentelemetry.api.baggage.propagation.W3CBaggagePropagator (not serializable) + === CLASS FILE FORMAT VERSION: 52.0 <- 52.0 + +++ NEW METHOD: PUBLIC(+) java.lang.String toString() +*** MODIFIED CLASS: PUBLIC FINAL io.opentelemetry.api.trace.propagation.W3CTraceContextPropagator (not serializable) + === CLASS FILE FORMAT VERSION: 52.0 <- 52.0 + +++ NEW METHOD: PUBLIC(+) java.lang.String toString() diff --git a/docs/apidiffs/current_vs_latest/opentelemetry-extension-trace-propagators.txt b/docs/apidiffs/current_vs_latest/opentelemetry-extension-trace-propagators.txt index df26146497b..62ccbdb194c 100644 --- a/docs/apidiffs/current_vs_latest/opentelemetry-extension-trace-propagators.txt +++ b/docs/apidiffs/current_vs_latest/opentelemetry-extension-trace-propagators.txt @@ -1,2 +1,10 @@ Comparing source compatibility of against -No changes. \ No newline at end of file +*** MODIFIED CLASS: PUBLIC FINAL io.opentelemetry.extension.trace.propagation.B3Propagator (not serializable) + === CLASS FILE FORMAT VERSION: 52.0 <- 52.0 + +++ NEW METHOD: PUBLIC(+) java.lang.String toString() +*** MODIFIED CLASS: PUBLIC FINAL io.opentelemetry.extension.trace.propagation.JaegerPropagator (not serializable) + === CLASS FILE FORMAT VERSION: 52.0 <- 52.0 + +++ NEW METHOD: PUBLIC(+) java.lang.String toString() +*** MODIFIED CLASS: PUBLIC FINAL io.opentelemetry.extension.trace.propagation.OtTracePropagator (not serializable) + === CLASS FILE FORMAT VERSION: 52.0 <- 52.0 + +++ NEW METHOD: PUBLIC(+) java.lang.String toString() diff --git a/extensions/incubator/src/main/java/io/opentelemetry/extension/incubator/propagation/PassThroughPropagator.java b/extensions/incubator/src/main/java/io/opentelemetry/extension/incubator/propagation/PassThroughPropagator.java index 64e6e40b1b5..37b41248df5 100644 --- a/extensions/incubator/src/main/java/io/opentelemetry/extension/incubator/propagation/PassThroughPropagator.java +++ b/extensions/incubator/src/main/java/io/opentelemetry/extension/incubator/propagation/PassThroughPropagator.java @@ -99,4 +99,9 @@ public Context extract(Context context, @Nullable C carrier, TextMapGetter Context extract(Context context, @Nullable C carrier, TextMapGetter void inject(Context context, @Nullable C carrier, TextMapSetter se public Collection fields() { return FIELDS; } + + @Override + public String toString() { + return "B3PropagatorInjectorMultipleHeaders"; + } } diff --git a/extensions/trace-propagators/src/main/java/io/opentelemetry/extension/trace/propagation/B3PropagatorInjectorSingleHeader.java b/extensions/trace-propagators/src/main/java/io/opentelemetry/extension/trace/propagation/B3PropagatorInjectorSingleHeader.java index ea7df623157..09f5fc67e04 100644 --- a/extensions/trace-propagators/src/main/java/io/opentelemetry/extension/trace/propagation/B3PropagatorInjectorSingleHeader.java +++ b/extensions/trace-propagators/src/main/java/io/opentelemetry/extension/trace/propagation/B3PropagatorInjectorSingleHeader.java @@ -67,4 +67,9 @@ public void inject(Context context, @Nullable C carrier, TextMapSetter se public Collection fields() { return FIELDS; } + + @Override + public String toString() { + return "B3PropagatorInjectorSingleHeader"; + } } diff --git a/extensions/trace-propagators/src/main/java/io/opentelemetry/extension/trace/propagation/JaegerPropagator.java b/extensions/trace-propagators/src/main/java/io/opentelemetry/extension/trace/propagation/JaegerPropagator.java index 61f207d852b..290a62bef0e 100644 --- a/extensions/trace-propagators/src/main/java/io/opentelemetry/extension/trace/propagation/JaegerPropagator.java +++ b/extensions/trace-propagators/src/main/java/io/opentelemetry/extension/trace/propagation/JaegerPropagator.java @@ -145,6 +145,11 @@ public Context extract(Context context, @Nullable C carrier, TextMapGetter SpanContext getSpanContextFromHeader( @Nullable C carrier, TextMapGetter getter) { String value = getter.get(carrier, PROPAGATION_HEADER); diff --git a/extensions/trace-propagators/src/main/java/io/opentelemetry/extension/trace/propagation/OtTracePropagator.java b/extensions/trace-propagators/src/main/java/io/opentelemetry/extension/trace/propagation/OtTracePropagator.java index fb51ccf4f14..3bd0ed771fe 100644 --- a/extensions/trace-propagators/src/main/java/io/opentelemetry/extension/trace/propagation/OtTracePropagator.java +++ b/extensions/trace-propagators/src/main/java/io/opentelemetry/extension/trace/propagation/OtTracePropagator.java @@ -133,4 +133,9 @@ private static SpanContext buildSpanContext( } return Common.buildSpanContext(traceId, spanId, sampled); } + + @Override + public String toString() { + return "OtTracePropagator"; + } } diff --git a/extensions/trace-propagators/src/test/java/io/opentelemetry/extension/trace/propagation/B3PropagatorTest.java b/extensions/trace-propagators/src/test/java/io/opentelemetry/extension/trace/propagation/B3PropagatorTest.java index 6c71cb2cc69..af2f4de33c7 100644 --- a/extensions/trace-propagators/src/test/java/io/opentelemetry/extension/trace/propagation/B3PropagatorTest.java +++ b/extensions/trace-propagators/src/test/java/io/opentelemetry/extension/trace/propagation/B3PropagatorTest.java @@ -724,4 +724,12 @@ void inject_DebugContext_SingleHeader() { B3Propagator.COMBINED_HEADER, TRACE_ID + "-" + SPAN_ID + "-" + B3Propagator.SINGLE_HEADER_DEBUG); } + + @Test + void toString_Valid() { + assertThat(b3Propagator.toString()) + .isEqualTo("B3Propagator{b3PropagatorInjector=B3PropagatorInjectorMultipleHeaders}"); + assertThat(b3PropagatorSingleHeader.toString()) + .isEqualTo("B3Propagator{b3PropagatorInjector=B3PropagatorInjectorSingleHeader}"); + } } diff --git a/extensions/trace-propagators/src/test/java/io/opentelemetry/extension/trace/propagation/JaegerPropagatorTest.java b/extensions/trace-propagators/src/test/java/io/opentelemetry/extension/trace/propagation/JaegerPropagatorTest.java index 73a2552a66a..4dbadd6c183 100644 --- a/extensions/trace-propagators/src/test/java/io/opentelemetry/extension/trace/propagation/JaegerPropagatorTest.java +++ b/extensions/trace-propagators/src/test/java/io/opentelemetry/extension/trace/propagation/JaegerPropagatorTest.java @@ -460,6 +460,11 @@ void extract_nullGetter() { assertThat(jaegerPropagator.extract(context, Collections.emptyMap(), null)).isSameAs(context); } + @Test + void toString_Valid() { + assertThat(jaegerPropagator.toString()).isEqualTo("JaegerPropagator"); + } + private static String generateTraceIdHeaderValue( String traceId, String spanId, char parentSpan, String sampled) { return traceId diff --git a/extensions/trace-propagators/src/test/java/io/opentelemetry/extension/trace/propagation/OtTracePropagatorTest.java b/extensions/trace-propagators/src/test/java/io/opentelemetry/extension/trace/propagation/OtTracePropagatorTest.java index 5c2fa5a9d4e..39e4bbfc0d7 100644 --- a/extensions/trace-propagators/src/test/java/io/opentelemetry/extension/trace/propagation/OtTracePropagatorTest.java +++ b/extensions/trace-propagators/src/test/java/io/opentelemetry/extension/trace/propagation/OtTracePropagatorTest.java @@ -340,4 +340,9 @@ void extract_nullGetter() { Context.current()); assertThat(propagator.extract(context, Collections.emptyMap(), null)).isSameAs(context); } + + @Test + void toString_Valid() { + assertThat(propagator.toString()).isEqualTo("OtTracePropagator"); + } } diff --git a/sdk/all/src/main/java/io/opentelemetry/sdk/OpenTelemetrySdk.java b/sdk/all/src/main/java/io/opentelemetry/sdk/OpenTelemetrySdk.java index 79c264759d4..c15ffae9058 100644 --- a/sdk/all/src/main/java/io/opentelemetry/sdk/OpenTelemetrySdk.java +++ b/sdk/all/src/main/java/io/opentelemetry/sdk/OpenTelemetrySdk.java @@ -80,7 +80,6 @@ public ContextPropagators getPropagators() { @Override public String toString() { - // TODO(anuraaga): Add propagators return "OpenTelemetrySdk{" + "tracerProvider=" + tracerProvider.unobfuscate() @@ -88,6 +87,8 @@ public String toString() { + meterProvider.unobfuscate() + ", loggerProvider=" + loggerProvider + + ", propagators=" + + propagators + "}"; } diff --git a/sdk/all/src/test/java/io/opentelemetry/sdk/OpenTelemetrySdkTest.java b/sdk/all/src/test/java/io/opentelemetry/sdk/OpenTelemetrySdkTest.java index 3a9228d9c8c..6323293eee2 100644 --- a/sdk/all/src/test/java/io/opentelemetry/sdk/OpenTelemetrySdkTest.java +++ b/sdk/all/src/test/java/io/opentelemetry/sdk/OpenTelemetrySdkTest.java @@ -326,6 +326,8 @@ void stringRepresentation() { when(metricExporter.toString()).thenReturn("MockMetricExporter{}"); LogRecordExporter logRecordExporter = mock(LogRecordExporter.class); when(logRecordExporter.toString()).thenReturn("MockLogRecordExporter{}"); + TextMapPropagator propagator = mock(TextMapPropagator.class); + when(propagator.toString()).thenReturn("MockTextMapPropagator{}"); Resource resource = Resource.builder().put(AttributeKey.stringKey("service.name"), "otel-test").build(); OpenTelemetrySdk sdk = @@ -352,6 +354,7 @@ void stringRepresentation() { SimpleLogRecordProcessor.create( LogRecordExporter.composite(logRecordExporter, logRecordExporter))) .build()) + .setPropagators(ContextPropagators.create(propagator)) .build(); assertThat(sdk.toString()) @@ -376,7 +379,8 @@ void stringRepresentation() { + "resource=Resource{schemaUrl=null, attributes={service.name=\"otel-test\"}}, " + "logLimits=LogLimits{maxNumberOfAttributes=128, maxAttributeValueLength=2147483647}, " + "logRecordProcessor=SimpleLogRecordProcessor{logRecordExporter=MultiLogRecordExporter{logRecordExporters=[MockLogRecordExporter{}, MockLogRecordExporter{}]}}" - + "}" + + "}, " + + "propagators=DefaultContextPropagators{textMapPropagator=MockTextMapPropagator{}}" + "}"); } } From 0973a7c426e65ebf3083adddd8ad08fce77950e2 Mon Sep 17 00:00:00 2001 From: jack-berg <34418638+jack-berg@users.noreply.github.com> Date: Tue, 29 Nov 2022 10:38:37 -0600 Subject: [PATCH 64/68] Fix out of date zipkin exporter docs (#4995) --- exporters/zipkin/README.md | 28 ---------------------------- 1 file changed, 28 deletions(-) diff --git a/exporters/zipkin/README.md b/exporters/zipkin/README.md index b398569d435..21c27587ac0 100644 --- a/exporters/zipkin/README.md +++ b/exporters/zipkin/README.md @@ -21,37 +21,9 @@ spans will be sent to a Zipkin endpoint running on `localhost`: ZipkinSpanExporter exporter = ZipkinSpanExporter.builder() .setEndpoint("http://localhost/api/v2/spans") - .setServiceName("my-service") .build(); ``` -Service name and Endpoint can be also configured via environment variables or system properties. - -```java -// Using environment variables -ZipkinSpanExporter exporter = - ZipkinSpanExporter.builder() - .readEnvironmentVariables() - .build() -``` - -```java -// Using system properties -ZipkinSpanExporter exporter = - ZipkinSpanExporter.builder() - .readSystemProperties() - .build() -``` - -The Zipkin span exporter will look for the following environment variables / system properties: -* `OTEL_ZIPKIN_SERVICE_NAME` / `otel.zipkin.service.name` -* `OTEL_ZIPKIN_ENDPOINT` / `otel.zipkin.endpoint` - - -## Compatibility - -As with the OpenTelemetry SDK itself, this exporter is compatible with Java 8+ and Android API level 24+. - ## Attribution The code in this module is based on the [OpenCensus Zipkin exporter][oc-origin] code. From e79aad8dcd29a1083c8c62082605da6791d3c8f0 Mon Sep 17 00:00:00 2001 From: jack-berg <34418638+jack-berg@users.noreply.github.com> Date: Tue, 29 Nov 2022 10:39:35 -0600 Subject: [PATCH 65/68] Implement logging-otlp exporter providers (#4992) --- exporters/logging-otlp/build.gradle.kts | 1 + .../LoggingLogRecordExporterProvider.java | 29 +++++++++++++++++++ .../LoggingMetricExporterProvider.java | 29 +++++++++++++++++++ .../internal/LoggingSpanExporterProvider.java | 29 +++++++++++++++++++ ...logs.ConfigurableLogRecordExporterProvider | 1 + ...metrics.ConfigurableMetricExporterProvider | 1 + ...pi.traces.ConfigurableSpanExporterProvider | 1 + sdk-extensions/autoconfigure/build.gradle.kts | 1 - .../LogRecordExporterConfiguration.java | 26 ++++++++--------- .../MetricExporterConfiguration.java | 13 +-------- .../SpanExporterConfiguration.java | 8 +---- .../sdk/autoconfigure/NotOnClasspathTest.java | 26 ++++++++++++----- 12 files changed, 124 insertions(+), 41 deletions(-) create mode 100644 exporters/logging-otlp/src/main/java/io/opentelemetry/exporter/logging/otlp/internal/LoggingLogRecordExporterProvider.java create mode 100644 exporters/logging-otlp/src/main/java/io/opentelemetry/exporter/logging/otlp/internal/LoggingMetricExporterProvider.java create mode 100644 exporters/logging-otlp/src/main/java/io/opentelemetry/exporter/logging/otlp/internal/LoggingSpanExporterProvider.java create mode 100644 exporters/logging-otlp/src/main/resources/META-INF/services/io.opentelemetry.sdk.autoconfigure.spi.logs.ConfigurableLogRecordExporterProvider create mode 100644 exporters/logging-otlp/src/main/resources/META-INF/services/io.opentelemetry.sdk.autoconfigure.spi.metrics.ConfigurableMetricExporterProvider create mode 100644 exporters/logging-otlp/src/main/resources/META-INF/services/io.opentelemetry.sdk.autoconfigure.spi.traces.ConfigurableSpanExporterProvider diff --git a/exporters/logging-otlp/build.gradle.kts b/exporters/logging-otlp/build.gradle.kts index 6dcb66aed88..4034af4a489 100644 --- a/exporters/logging-otlp/build.gradle.kts +++ b/exporters/logging-otlp/build.gradle.kts @@ -14,6 +14,7 @@ dependencies { compileOnly(project(":sdk:logs")) implementation(project(":exporters:otlp:common")) + implementation(project(":sdk-extensions:autoconfigure-spi")) implementation("com.fasterxml.jackson.core:jackson-core") diff --git a/exporters/logging-otlp/src/main/java/io/opentelemetry/exporter/logging/otlp/internal/LoggingLogRecordExporterProvider.java b/exporters/logging-otlp/src/main/java/io/opentelemetry/exporter/logging/otlp/internal/LoggingLogRecordExporterProvider.java new file mode 100644 index 00000000000..ebb0d2d0865 --- /dev/null +++ b/exporters/logging-otlp/src/main/java/io/opentelemetry/exporter/logging/otlp/internal/LoggingLogRecordExporterProvider.java @@ -0,0 +1,29 @@ +/* + * Copyright The OpenTelemetry Authors + * SPDX-License-Identifier: Apache-2.0 + */ + +package io.opentelemetry.exporter.logging.otlp.internal; + +import io.opentelemetry.exporter.logging.otlp.OtlpJsonLoggingLogRecordExporter; +import io.opentelemetry.sdk.autoconfigure.spi.ConfigProperties; +import io.opentelemetry.sdk.autoconfigure.spi.logs.ConfigurableLogRecordExporterProvider; +import io.opentelemetry.sdk.logs.export.LogRecordExporter; + +/** + * {@link LogRecordExporter} SPI implementation for {@link OtlpJsonLoggingLogRecordExporter}. + * + *

This class is internal and is hence not for public use. Its APIs are unstable and can change + * at any time. + */ +public class LoggingLogRecordExporterProvider implements ConfigurableLogRecordExporterProvider { + @Override + public LogRecordExporter createExporter(ConfigProperties config) { + return OtlpJsonLoggingLogRecordExporter.create(); + } + + @Override + public String getName() { + return "logging-otlp"; + } +} diff --git a/exporters/logging-otlp/src/main/java/io/opentelemetry/exporter/logging/otlp/internal/LoggingMetricExporterProvider.java b/exporters/logging-otlp/src/main/java/io/opentelemetry/exporter/logging/otlp/internal/LoggingMetricExporterProvider.java new file mode 100644 index 00000000000..b5669b5426a --- /dev/null +++ b/exporters/logging-otlp/src/main/java/io/opentelemetry/exporter/logging/otlp/internal/LoggingMetricExporterProvider.java @@ -0,0 +1,29 @@ +/* + * Copyright The OpenTelemetry Authors + * SPDX-License-Identifier: Apache-2.0 + */ + +package io.opentelemetry.exporter.logging.otlp.internal; + +import io.opentelemetry.exporter.logging.otlp.OtlpJsonLoggingMetricExporter; +import io.opentelemetry.sdk.autoconfigure.spi.ConfigProperties; +import io.opentelemetry.sdk.autoconfigure.spi.metrics.ConfigurableMetricExporterProvider; +import io.opentelemetry.sdk.metrics.export.MetricExporter; + +/** + * {@link MetricExporter} SPI implementation for {@link OtlpJsonLoggingMetricExporter}. + * + *

This class is internal and is hence not for public use. Its APIs are unstable and can change + * at any time. + */ +public class LoggingMetricExporterProvider implements ConfigurableMetricExporterProvider { + @Override + public MetricExporter createExporter(ConfigProperties config) { + return OtlpJsonLoggingMetricExporter.create(); + } + + @Override + public String getName() { + return "logging-otlp"; + } +} diff --git a/exporters/logging-otlp/src/main/java/io/opentelemetry/exporter/logging/otlp/internal/LoggingSpanExporterProvider.java b/exporters/logging-otlp/src/main/java/io/opentelemetry/exporter/logging/otlp/internal/LoggingSpanExporterProvider.java new file mode 100644 index 00000000000..6ce1856a894 --- /dev/null +++ b/exporters/logging-otlp/src/main/java/io/opentelemetry/exporter/logging/otlp/internal/LoggingSpanExporterProvider.java @@ -0,0 +1,29 @@ +/* + * Copyright The OpenTelemetry Authors + * SPDX-License-Identifier: Apache-2.0 + */ + +package io.opentelemetry.exporter.logging.otlp.internal; + +import io.opentelemetry.exporter.logging.otlp.OtlpJsonLoggingSpanExporter; +import io.opentelemetry.sdk.autoconfigure.spi.ConfigProperties; +import io.opentelemetry.sdk.autoconfigure.spi.traces.ConfigurableSpanExporterProvider; +import io.opentelemetry.sdk.trace.export.SpanExporter; + +/** + * {@link SpanExporter} SPI implementation for {@link OtlpJsonLoggingSpanExporter}. + * + *

This class is internal and is hence not for public use. Its APIs are unstable and can change + * at any time. + */ +public class LoggingSpanExporterProvider implements ConfigurableSpanExporterProvider { + @Override + public SpanExporter createExporter(ConfigProperties config) { + return OtlpJsonLoggingSpanExporter.create(); + } + + @Override + public String getName() { + return "logging-otlp"; + } +} diff --git a/exporters/logging-otlp/src/main/resources/META-INF/services/io.opentelemetry.sdk.autoconfigure.spi.logs.ConfigurableLogRecordExporterProvider b/exporters/logging-otlp/src/main/resources/META-INF/services/io.opentelemetry.sdk.autoconfigure.spi.logs.ConfigurableLogRecordExporterProvider new file mode 100644 index 00000000000..9119f54ef00 --- /dev/null +++ b/exporters/logging-otlp/src/main/resources/META-INF/services/io.opentelemetry.sdk.autoconfigure.spi.logs.ConfigurableLogRecordExporterProvider @@ -0,0 +1 @@ +io.opentelemetry.exporter.logging.otlp.internal.LoggingLogRecordExporterProvider diff --git a/exporters/logging-otlp/src/main/resources/META-INF/services/io.opentelemetry.sdk.autoconfigure.spi.metrics.ConfigurableMetricExporterProvider b/exporters/logging-otlp/src/main/resources/META-INF/services/io.opentelemetry.sdk.autoconfigure.spi.metrics.ConfigurableMetricExporterProvider new file mode 100644 index 00000000000..2b532ca9a38 --- /dev/null +++ b/exporters/logging-otlp/src/main/resources/META-INF/services/io.opentelemetry.sdk.autoconfigure.spi.metrics.ConfigurableMetricExporterProvider @@ -0,0 +1 @@ +io.opentelemetry.exporter.logging.otlp.internal.LoggingMetricExporterProvider diff --git a/exporters/logging-otlp/src/main/resources/META-INF/services/io.opentelemetry.sdk.autoconfigure.spi.traces.ConfigurableSpanExporterProvider b/exporters/logging-otlp/src/main/resources/META-INF/services/io.opentelemetry.sdk.autoconfigure.spi.traces.ConfigurableSpanExporterProvider new file mode 100644 index 00000000000..fe444f4acf3 --- /dev/null +++ b/exporters/logging-otlp/src/main/resources/META-INF/services/io.opentelemetry.sdk.autoconfigure.spi.traces.ConfigurableSpanExporterProvider @@ -0,0 +1 @@ +io.opentelemetry.exporter.logging.otlp.internal.LoggingSpanExporterProvider diff --git a/sdk-extensions/autoconfigure/build.gradle.kts b/sdk-extensions/autoconfigure/build.gradle.kts index 0f9fc1295ec..984dd1ae24c 100644 --- a/sdk-extensions/autoconfigure/build.gradle.kts +++ b/sdk-extensions/autoconfigure/build.gradle.kts @@ -16,7 +16,6 @@ dependencies { implementation(project(":exporters:common")) compileOnly(project(":exporters:jaeger")) - compileOnly(project(":exporters:logging-otlp")) compileOnly(project(":exporters:otlp:all")) compileOnly(project(":exporters:otlp:logs")) compileOnly(project(":exporters:otlp:common")) diff --git a/sdk-extensions/autoconfigure/src/main/java/io/opentelemetry/sdk/autoconfigure/LogRecordExporterConfiguration.java b/sdk-extensions/autoconfigure/src/main/java/io/opentelemetry/sdk/autoconfigure/LogRecordExporterConfiguration.java index 693aa3303f8..981ff3740d7 100644 --- a/sdk-extensions/autoconfigure/src/main/java/io/opentelemetry/sdk/autoconfigure/LogRecordExporterConfiguration.java +++ b/sdk-extensions/autoconfigure/src/main/java/io/opentelemetry/sdk/autoconfigure/LogRecordExporterConfiguration.java @@ -11,7 +11,6 @@ import io.opentelemetry.api.metrics.MeterProvider; import io.opentelemetry.exporter.internal.retry.RetryUtil; -import io.opentelemetry.exporter.logging.otlp.OtlpJsonLoggingLogRecordExporter; import io.opentelemetry.exporter.otlp.http.logs.OtlpHttpLogRecordExporter; import io.opentelemetry.exporter.otlp.http.logs.OtlpHttpLogRecordExporterBuilder; import io.opentelemetry.exporter.otlp.logs.OtlpGrpcLogRecordExporter; @@ -35,6 +34,7 @@ class LogRecordExporterConfiguration { static { EXPORTER_ARTIFACT_ID_BY_NAME = new HashMap<>(); EXPORTER_ARTIFACT_ID_BY_NAME.put("logging", "opentelemetry-exporter-logging"); + EXPORTER_ARTIFACT_ID_BY_NAME.put("logging-otlp", "opentelemetry-exporter-logging-otlp"); } // Visible for test @@ -60,12 +60,7 @@ static Map configureLogRecordExporters( } NamedSpiManager spiExportersManager = - SpiUtil.loadConfigurable( - ConfigurableLogRecordExporterProvider.class, - ConfigurableLogRecordExporterProvider::getName, - ConfigurableLogRecordExporterProvider::createExporter, - config, - serviceClassLoader); + logRecordExporterSpiManager(config, serviceClassLoader); Map exportersByName = new HashMap<>(); for (String name : exporterNames) { @@ -81,6 +76,17 @@ static Map configureLogRecordExporters( return Collections.unmodifiableMap(exportersByName); } + // Visible for testing + static NamedSpiManager logRecordExporterSpiManager( + ConfigProperties config, ClassLoader serviceClassLoader) { + return SpiUtil.loadConfigurable( + ConfigurableLogRecordExporterProvider.class, + ConfigurableLogRecordExporterProvider::getName, + ConfigurableLogRecordExporterProvider::createExporter, + config, + serviceClassLoader); + } + // Visible for testing @Nullable static LogRecordExporter configureExporter( @@ -91,12 +97,6 @@ static LogRecordExporter configureExporter( switch (name) { case "otlp": return configureOtlpLogs(config, meterProvider); - case "logging-otlp": - ClasspathUtil.checkClassExists( - "io.opentelemetry.exporter.logging.otlp.OtlpJsonLoggingLogRecordExporter", - "OTLP JSON Logging Log Exporter", - "opentelemetry-exporter-logging-otlp"); - return OtlpJsonLoggingLogRecordExporter.create(); default: LogRecordExporter spiExporter = spiExportersManager.getByName(name); if (spiExporter == null) { diff --git a/sdk-extensions/autoconfigure/src/main/java/io/opentelemetry/sdk/autoconfigure/MetricExporterConfiguration.java b/sdk-extensions/autoconfigure/src/main/java/io/opentelemetry/sdk/autoconfigure/MetricExporterConfiguration.java index a82cc6c5cb1..11d9d45061d 100644 --- a/sdk-extensions/autoconfigure/src/main/java/io/opentelemetry/sdk/autoconfigure/MetricExporterConfiguration.java +++ b/sdk-extensions/autoconfigure/src/main/java/io/opentelemetry/sdk/autoconfigure/MetricExporterConfiguration.java @@ -10,7 +10,6 @@ import static io.opentelemetry.sdk.autoconfigure.OtlpConfigUtil.PROTOCOL_HTTP_PROTOBUF; import io.opentelemetry.exporter.internal.retry.RetryUtil; -import io.opentelemetry.exporter.logging.otlp.OtlpJsonLoggingMetricExporter; import io.opentelemetry.exporter.otlp.http.metrics.OtlpHttpMetricExporter; import io.opentelemetry.exporter.otlp.http.metrics.OtlpHttpMetricExporterBuilder; import io.opentelemetry.exporter.otlp.metrics.OtlpGrpcMetricExporter; @@ -37,6 +36,7 @@ final class MetricExporterConfiguration { static { EXPORTER_ARTIFACT_ID_BY_NAME = new HashMap<>(); EXPORTER_ARTIFACT_ID_BY_NAME.put("logging", "opentelemetry-exporter-logging"); + EXPORTER_ARTIFACT_ID_BY_NAME.put("logging-otlp", "opentelemetry-exporter-logging-otlp"); } static MetricReader configureExporter( @@ -54,9 +54,6 @@ static MetricReader configureExporter( case "otlp": metricExporter = configureOtlpMetrics(config); break; - case "logging-otlp": - metricExporter = configureLoggingOtlpExporter(); - break; default: MetricExporter spiExporter = configureSpiExporter(name, config, serviceClassLoader); if (spiExporter == null) { @@ -78,14 +75,6 @@ static MetricReader configureExporter( return configurePeriodicMetricReader(config, metricExporter); } - private static MetricExporter configureLoggingOtlpExporter() { - ClasspathUtil.checkClassExists( - "io.opentelemetry.exporter.logging.otlp.OtlpJsonLoggingMetricExporter", - "OTLP JSON Logging Metrics Exporter", - "opentelemetry-exporter-logging-otlp"); - return OtlpJsonLoggingMetricExporter.create(); - } - // Visible for testing. @Nullable static MetricExporter configureSpiExporter( diff --git a/sdk-extensions/autoconfigure/src/main/java/io/opentelemetry/sdk/autoconfigure/SpanExporterConfiguration.java b/sdk-extensions/autoconfigure/src/main/java/io/opentelemetry/sdk/autoconfigure/SpanExporterConfiguration.java index 7c19a82f45c..f9b5608826b 100644 --- a/sdk-extensions/autoconfigure/src/main/java/io/opentelemetry/sdk/autoconfigure/SpanExporterConfiguration.java +++ b/sdk-extensions/autoconfigure/src/main/java/io/opentelemetry/sdk/autoconfigure/SpanExporterConfiguration.java @@ -14,7 +14,6 @@ import io.opentelemetry.exporter.internal.retry.RetryUtil; import io.opentelemetry.exporter.jaeger.JaegerGrpcSpanExporter; import io.opentelemetry.exporter.jaeger.JaegerGrpcSpanExporterBuilder; -import io.opentelemetry.exporter.logging.otlp.OtlpJsonLoggingSpanExporter; import io.opentelemetry.exporter.otlp.http.trace.OtlpHttpSpanExporter; import io.opentelemetry.exporter.otlp.http.trace.OtlpHttpSpanExporterBuilder; import io.opentelemetry.exporter.otlp.trace.OtlpGrpcSpanExporter; @@ -39,6 +38,7 @@ final class SpanExporterConfiguration { static { EXPORTER_ARTIFACT_ID_BY_NAME = new HashMap<>(); EXPORTER_ARTIFACT_ID_BY_NAME.put("logging", "opentelemetry-exporter-logging"); + EXPORTER_ARTIFACT_ID_BY_NAME.put("logging-otlp", "opentelemetry-exporter-logging-otlp"); EXPORTER_ARTIFACT_ID_BY_NAME.put("zipkin", "opentelemetry-exporter-zipkin"); } @@ -102,12 +102,6 @@ static SpanExporter configureExporter( return configureOtlp(config, meterProvider); case "jaeger": return configureJaeger(config, meterProvider); - case "logging-otlp": - ClasspathUtil.checkClassExists( - "io.opentelemetry.exporter.logging.otlp.OtlpJsonLoggingSpanExporter", - "OTLP JSON Logging Trace Exporter", - "opentelemetry-exporter-logging-otlp"); - return OtlpJsonLoggingSpanExporter.create(); default: SpanExporter spiExporter = spiExportersManager.getByName(name); if (spiExporter == null) { diff --git a/sdk-extensions/autoconfigure/src/test/java/io/opentelemetry/sdk/autoconfigure/NotOnClasspathTest.java b/sdk-extensions/autoconfigure/src/test/java/io/opentelemetry/sdk/autoconfigure/NotOnClasspathTest.java index 2abb4617b7e..6ae928b6607 100644 --- a/sdk-extensions/autoconfigure/src/test/java/io/opentelemetry/sdk/autoconfigure/NotOnClasspathTest.java +++ b/sdk-extensions/autoconfigure/src/test/java/io/opentelemetry/sdk/autoconfigure/NotOnClasspathTest.java @@ -87,11 +87,16 @@ void loggingSpansOtlp() { assertThatThrownBy( () -> SpanExporterConfiguration.configureExporter( - "logging-otlp", EMPTY, NamedSpiManager.createEmpty(), MeterProvider.noop())) + "logging-otlp", + EMPTY, + SpanExporterConfiguration.spanExporterSpiManager( + DefaultConfigProperties.createForTest(Collections.emptyMap()), + NotOnClasspathTest.class.getClassLoader()), + MeterProvider.noop())) .isInstanceOf(ConfigurationException.class) .hasMessageContaining( - "OTLP JSON Logging Trace Exporter enabled but opentelemetry-exporter-logging-otlp not found on " - + "classpath"); + "otel.traces.exporter set to \"logging-otlp\" but opentelemetry-exporter-logging-otlp not found on classpath." + + " Make sure to add it as a dependency."); } @Test @@ -120,8 +125,8 @@ void loggingMetricsOtlp() { (a, unused) -> a)) .isInstanceOf(ConfigurationException.class) .hasMessageContaining( - "OTLP JSON Logging Metrics Exporter enabled but opentelemetry-exporter-logging-otlp not found on " - + "classpath"); + "otel.metrics.exporter set to \"logging-otlp\" but opentelemetry-exporter-logging-otlp not found on classpath." + + " Make sure to add it as a dependency."); } @Test @@ -141,11 +146,16 @@ void loggingLogsOtlp() { assertThatThrownBy( () -> LogRecordExporterConfiguration.configureExporter( - "logging-otlp", EMPTY, NamedSpiManager.createEmpty(), MeterProvider.noop())) + "logging-otlp", + EMPTY, + LogRecordExporterConfiguration.logRecordExporterSpiManager( + DefaultConfigProperties.createForTest(Collections.emptyMap()), + NotOnClasspathTest.class.getClassLoader()), + MeterProvider.noop())) .isInstanceOf(ConfigurationException.class) .hasMessageContaining( - "OTLP JSON Logging Log Exporter enabled but opentelemetry-exporter-logging-otlp not found on " - + "classpath"); + "otel.logs.exporter set to \"logging-otlp\" but opentelemetry-exporter-logging-otlp not found on classpath." + + " Make sure to add it as a dependency."); } @Test From ac2ba4a2dfaea44c1b6990d85ba95d263b18de51 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=81ukasz=20Monkiewicz?= Date: Tue, 29 Nov 2022 20:47:15 +0100 Subject: [PATCH 66/68] =?UTF-8?q?Adjustment=20of=20behaviour=20of=20hasXAt?= =?UTF-8?q?tributesSatisfying=20and=20hasXAttribute=E2=80=A6=20(#4882)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Adjustment of behaviour of hasXAttributesSatisfying and hasXAttributesSatisfyingExactly assertions * Cleanup * Additional test coverage for new assertion method * Added javadoc on assertions Co-authored-by: Trask Stalnaker Co-authored-by: Trask Stalnaker --- .../opentelemetry-sdk-testing.txt | 23 ++++- .../testing/assertj/LogRecordDataAssert.java | 40 ++++++++ .../testing/assertj/LogAssertionsTest.java | 27 ++++++ .../testing/assertj/AbstractPointAssert.java | 28 +++++- .../sdk/testing/assertj/AssertUtil.java | 28 +++++- .../testing/assertj/DoubleExemplarAssert.java | 31 ++++++- .../sdk/testing/assertj/EventDataAssert.java | 40 ++++++++ .../testing/assertj/LongExemplarAssert.java | 31 ++++++- .../sdk/testing/assertj/SpanDataAssert.java | 49 ++++++---- .../sdk/testing/assertj/AssertUtilTest.java | 85 +++++++++++++++++ .../testing/assertj/MetricAssertionsTest.java | 92 +++++++++++++++++-- .../testing/assertj/TraceAssertionsTest.java | 23 +++++ 12 files changed, 460 insertions(+), 37 deletions(-) create mode 100644 sdk/testing/src/test/java/io/opentelemetry/sdk/testing/assertj/AssertUtilTest.java diff --git a/docs/apidiffs/current_vs_latest/opentelemetry-sdk-testing.txt b/docs/apidiffs/current_vs_latest/opentelemetry-sdk-testing.txt index df26146497b..6fa6fca8c60 100644 --- a/docs/apidiffs/current_vs_latest/opentelemetry-sdk-testing.txt +++ b/docs/apidiffs/current_vs_latest/opentelemetry-sdk-testing.txt @@ -1,2 +1,23 @@ Comparing source compatibility of against -No changes. \ No newline at end of file +*** MODIFIED CLASS: PUBLIC ABSTRACT io.opentelemetry.sdk.testing.assertj.AbstractPointAssert (not serializable) + === CLASS FILE FORMAT VERSION: 52.0 <- 52.0 + +++ NEW METHOD: PUBLIC(+) FINAL(+) io.opentelemetry.sdk.testing.assertj.AbstractPointAssert hasAttributesSatisfyingExactly(io.opentelemetry.sdk.testing.assertj.AttributeAssertion[]) + +++ NEW METHOD: PUBLIC(+) FINAL(+) io.opentelemetry.sdk.testing.assertj.AbstractPointAssert hasAttributesSatisfyingExactly(java.lang.Iterable) +*** MODIFIED CLASS: PUBLIC FINAL io.opentelemetry.sdk.testing.assertj.DoubleExemplarAssert (not serializable) + === CLASS FILE FORMAT VERSION: 52.0 <- 52.0 + +++ NEW METHOD: PUBLIC(+) io.opentelemetry.sdk.testing.assertj.DoubleExemplarAssert hasFilteredAttributesSatisfyingExactly(io.opentelemetry.sdk.testing.assertj.AttributeAssertion[]) + +++ NEW METHOD: PUBLIC(+) io.opentelemetry.sdk.testing.assertj.DoubleExemplarAssert hasFilteredAttributesSatisfyingExactly(java.lang.Iterable) +*** MODIFIED CLASS: PUBLIC FINAL io.opentelemetry.sdk.testing.assertj.EventDataAssert (not serializable) + === CLASS FILE FORMAT VERSION: 52.0 <- 52.0 + +++ NEW METHOD: PUBLIC(+) io.opentelemetry.sdk.testing.assertj.EventDataAssert hasAttributesSatisfying(io.opentelemetry.sdk.testing.assertj.AttributeAssertion[]) + +++ NEW METHOD: PUBLIC(+) io.opentelemetry.sdk.testing.assertj.EventDataAssert hasAttributesSatisfying(java.lang.Iterable) + +++ NEW METHOD: PUBLIC(+) io.opentelemetry.sdk.testing.assertj.EventDataAssert hasAttributesSatisfyingExactly(io.opentelemetry.sdk.testing.assertj.AttributeAssertion[]) + +++ NEW METHOD: PUBLIC(+) io.opentelemetry.sdk.testing.assertj.EventDataAssert hasAttributesSatisfyingExactly(java.lang.Iterable) +*** MODIFIED CLASS: PUBLIC FINAL io.opentelemetry.sdk.testing.assertj.LongExemplarAssert (not serializable) + === CLASS FILE FORMAT VERSION: 52.0 <- 52.0 + +++ NEW METHOD: PUBLIC(+) io.opentelemetry.sdk.testing.assertj.LongExemplarAssert hasFilteredAttributesSatisfyingExactly(io.opentelemetry.sdk.testing.assertj.AttributeAssertion[]) + +++ NEW METHOD: PUBLIC(+) io.opentelemetry.sdk.testing.assertj.LongExemplarAssert hasFilteredAttributesSatisfyingExactly(java.lang.Iterable) +*** MODIFIED CLASS: PUBLIC FINAL io.opentelemetry.sdk.testing.assertj.SpanDataAssert (not serializable) + === CLASS FILE FORMAT VERSION: 52.0 <- 52.0 + +++ NEW METHOD: PUBLIC(+) io.opentelemetry.sdk.testing.assertj.SpanDataAssert hasAttributesSatisfying(io.opentelemetry.sdk.testing.assertj.AttributeAssertion[]) + +++ NEW METHOD: PUBLIC(+) io.opentelemetry.sdk.testing.assertj.SpanDataAssert hasAttributesSatisfying(java.lang.Iterable) diff --git a/sdk/logs-testing/src/main/java/io/opentelemetry/sdk/testing/assertj/LogRecordDataAssert.java b/sdk/logs-testing/src/main/java/io/opentelemetry/sdk/testing/assertj/LogRecordDataAssert.java index cb0eb83722f..d23b6e97424 100644 --- a/sdk/logs-testing/src/main/java/io/opentelemetry/sdk/testing/assertj/LogRecordDataAssert.java +++ b/sdk/logs-testing/src/main/java/io/opentelemetry/sdk/testing/assertj/LogRecordDataAssert.java @@ -15,6 +15,7 @@ import io.opentelemetry.sdk.common.InstrumentationScopeInfo; import io.opentelemetry.sdk.logs.data.LogRecordData; import io.opentelemetry.sdk.resources.Resource; +import java.util.Arrays; import java.util.Map; import java.util.function.Consumer; import org.assertj.core.api.AbstractAssert; @@ -160,6 +161,45 @@ public LogRecordDataAssert hasAttributesSatisfying(Consumer attribut return this; } + /** + * Asserts the log has attributes matching all {@code assertions}. Assertions can be created using + * methods like {@link OpenTelemetryAssertions#satisfies(AttributeKey, + * OpenTelemetryAssertions.LongAssertConsumer)}. + */ + public LogRecordDataAssert hasAttributesSatisfying(AttributeAssertion... assertions) { + return hasAttributesSatisfying(Arrays.asList(assertions)); + } + + /** + * Asserts the log has attributes matching all {@code assertions}. Assertions can be created using + * methods like {@link OpenTelemetryAssertions#satisfies(AttributeKey, + * OpenTelemetryAssertions.LongAssertConsumer)}. + */ + public LogRecordDataAssert hasAttributesSatisfying(Iterable assertions) { + AssertUtil.assertAttributes(actual.getAttributes(), assertions); + return myself; + } + + /** + * Asserts the log has attributes matching all {@code assertions} and no more. Assertions can be + * created using methods like {@link OpenTelemetryAssertions#satisfies(AttributeKey, + * OpenTelemetryAssertions.LongAssertConsumer)}. + */ + public LogRecordDataAssert hasAttributesSatisfyingExactly(AttributeAssertion... assertions) { + return hasAttributesSatisfyingExactly(Arrays.asList(assertions)); + } + + /** + * Asserts the log has attributes matching all {@code assertions} and no more. Assertions can be + * created using methods like {@link OpenTelemetryAssertions#satisfies(AttributeKey, + * OpenTelemetryAssertions.LongAssertConsumer)}. + */ + public LogRecordDataAssert hasAttributesSatisfyingExactly( + Iterable assertions) { + AssertUtil.assertAttributesExactly(actual.getAttributes(), assertions); + return myself; + } + private boolean attributesAreEqual(Attributes attributes) { // compare as maps, since implementations do not have equals that work correctly across // implementations. diff --git a/sdk/logs-testing/src/test/java/io/opentelemetry/sdk/testing/assertj/LogAssertionsTest.java b/sdk/logs-testing/src/test/java/io/opentelemetry/sdk/testing/assertj/LogAssertionsTest.java index 750f6e59221..54f1afa67a3 100644 --- a/sdk/logs-testing/src/test/java/io/opentelemetry/sdk/testing/assertj/LogAssertionsTest.java +++ b/sdk/logs-testing/src/test/java/io/opentelemetry/sdk/testing/assertj/LogAssertionsTest.java @@ -8,6 +8,7 @@ import static io.opentelemetry.api.common.AttributeKey.stringKey; import static io.opentelemetry.sdk.testing.assertj.LogAssertions.assertThat; import static io.opentelemetry.sdk.testing.assertj.OpenTelemetryAssertions.attributeEntry; +import static io.opentelemetry.sdk.testing.assertj.OpenTelemetryAssertions.equalTo; import static org.assertj.core.api.Assertions.assertThatThrownBy; import io.opentelemetry.api.common.AttributeKey; @@ -111,6 +112,18 @@ void passing() { attributeEntry("conditions", false, true), attributeEntry("scores", 0L, 1L), attributeEntry("coins", 0.01, 0.05, 0.1))) + .hasAttributesSatisfying( + equalTo(AttributeKey.stringKey("bear"), "mya"), + equalTo(AttributeKey.booleanArrayKey("conditions"), Arrays.asList(false, true))) + .hasAttributesSatisfyingExactly( + equalTo(AttributeKey.stringKey("bear"), "mya"), + equalTo(AttributeKey.booleanKey("warm"), true), + equalTo(AttributeKey.longKey("temperature"), 30L), + equalTo(AttributeKey.doubleKey("length"), 1.2), + equalTo(AttributeKey.stringArrayKey("colors"), Arrays.asList("red", "blue")), + equalTo(AttributeKey.booleanArrayKey("conditions"), Arrays.asList(false, true)), + equalTo(AttributeKey.longArrayKey("scores"), Arrays.asList(0L, 1L)), + equalTo(AttributeKey.doubleArrayKey("coins"), Arrays.asList(0.01, 0.05, 0.1))) .hasTotalAttributeCount(999); } @@ -181,6 +194,20 @@ void failure() { AttributeKey.stringKey("bear"), value -> assertThat(value).hasSize(2)))) .isInstanceOf(AssertionError.class); + assertThatThrownBy( + () -> + assertThat(LOG_DATA) + .hasAttributesSatisfying(equalTo(AttributeKey.stringKey("bear"), "moo"))) + .isInstanceOf(AssertionError.class); + assertThatThrownBy( + () -> + assertThat(LOG_DATA) + .hasAttributesSatisfyingExactly( + equalTo(AttributeKey.stringKey("bear"), "mya"), + equalTo(AttributeKey.booleanKey("warm"), true), + equalTo(AttributeKey.longKey("temperature"), 30L), + equalTo(AttributeKey.doubleKey("length"), 1.2))) + .isInstanceOf(AssertionError.class); assertThatThrownBy(() -> assertThat(LOG_DATA).hasTotalAttributeCount(11)) .isInstanceOf(AssertionError.class); } diff --git a/sdk/testing/src/main/java/io/opentelemetry/sdk/testing/assertj/AbstractPointAssert.java b/sdk/testing/src/main/java/io/opentelemetry/sdk/testing/assertj/AbstractPointAssert.java index 528f6136ff1..80c70416e61 100644 --- a/sdk/testing/src/main/java/io/opentelemetry/sdk/testing/assertj/AbstractPointAssert.java +++ b/sdk/testing/src/main/java/io/opentelemetry/sdk/testing/assertj/AbstractPointAssert.java @@ -93,8 +93,8 @@ public final PointAssertT hasAttributes(Map.Entry, ?>. } /** - * Asserts the point has attributes matching all {@code assertions} and no more. Assertions can be - * created using methods like {@link OpenTelemetryAssertions#satisfies(AttributeKey, + * Asserts the point has attributes matching all {@code assertions}. Assertions can be created + * using methods like {@link OpenTelemetryAssertions#satisfies(AttributeKey, * OpenTelemetryAssertions.LongAssertConsumer)}. */ public final PointAssertT hasAttributesSatisfying(AttributeAssertion... assertions) { @@ -102,12 +102,32 @@ public final PointAssertT hasAttributesSatisfying(AttributeAssertion... assertio } /** - * Asserts the point has attributes matching all {@code assertions} and no more. Assertions can be - * created using methods like {@link OpenTelemetryAssertions#satisfies(AttributeKey, + * Asserts the point has attributes matching all {@code assertions}. Assertions can be created + * using methods like {@link OpenTelemetryAssertions#satisfies(AttributeKey, * OpenTelemetryAssertions.LongAssertConsumer)}. */ public final PointAssertT hasAttributesSatisfying(Iterable assertions) { AssertUtil.assertAttributes(actual.getAttributes(), assertions); return myself; } + + /** + * Asserts the point has attributes matching all {@code assertions} and no more. Assertions can be + * created using methods like {@link OpenTelemetryAssertions#satisfies(AttributeKey, + * OpenTelemetryAssertions.LongAssertConsumer)}. + */ + public final PointAssertT hasAttributesSatisfyingExactly(AttributeAssertion... assertions) { + return hasAttributesSatisfyingExactly(Arrays.asList(assertions)); + } + + /** + * Asserts the point has attributes matching all {@code assertions} and no more. Assertions can be + * created using methods like {@link OpenTelemetryAssertions#satisfies(AttributeKey, + * OpenTelemetryAssertions.LongAssertConsumer)}. + */ + public final PointAssertT hasAttributesSatisfyingExactly( + Iterable assertions) { + AssertUtil.assertAttributesExactly(actual.getAttributes(), assertions); + return myself; + } } diff --git a/sdk/testing/src/main/java/io/opentelemetry/sdk/testing/assertj/AssertUtil.java b/sdk/testing/src/main/java/io/opentelemetry/sdk/testing/assertj/AssertUtil.java index b605cdabcb5..5ff3d40f14b 100644 --- a/sdk/testing/src/main/java/io/opentelemetry/sdk/testing/assertj/AssertUtil.java +++ b/sdk/testing/src/main/java/io/opentelemetry/sdk/testing/assertj/AssertUtil.java @@ -34,6 +34,32 @@ static > Consumer[] toConsumers( } static void assertAttributes(Attributes actual, Iterable assertions) { + assertAttributes(actual, assertions, "attribute keys"); + } + + static void assertAttributes( + Attributes actual, Iterable assertions, String name) { + Set> actualKeys = actual.asMap().keySet(); + Set> checkedKeys = new HashSet<>(); + for (AttributeAssertion attributeAssertion : assertions) { + AttributeKey key = attributeAssertion.getKey(); + Object value = actual.get(key); + if (value != null) { + checkedKeys.add(key); + } + AbstractAssert assertion = AttributeAssertion.attributeValueAssertion(key, value); + attributeAssertion.getAssertion().accept(assertion); + } + + assertThat(actualKeys).as(name).containsAll(checkedKeys); + } + + static void assertAttributesExactly(Attributes actual, Iterable assertions) { + assertAttributesExactly(actual, assertions, "attribute keys"); + } + + static void assertAttributesExactly( + Attributes actual, Iterable assertions, String name) { Set> actualKeys = actual.asMap().keySet(); Set> checkedKeys = new HashSet<>(); for (AttributeAssertion attributeAssertion : assertions) { @@ -46,7 +72,7 @@ static void assertAttributes(Attributes actual, Iterable ass attributeAssertion.getAssertion().accept(assertion); } - assertThat(actualKeys).as("attribute keys").containsExactlyInAnyOrderElementsOf(checkedKeys); + assertThat(actualKeys).as(name).containsExactlyInAnyOrderElementsOf(checkedKeys); } /** diff --git a/sdk/testing/src/main/java/io/opentelemetry/sdk/testing/assertj/DoubleExemplarAssert.java b/sdk/testing/src/main/java/io/opentelemetry/sdk/testing/assertj/DoubleExemplarAssert.java index 31645e2d081..fea4d74eb26 100644 --- a/sdk/testing/src/main/java/io/opentelemetry/sdk/testing/assertj/DoubleExemplarAssert.java +++ b/sdk/testing/src/main/java/io/opentelemetry/sdk/testing/assertj/DoubleExemplarAssert.java @@ -97,19 +97,44 @@ public final DoubleExemplarAssert hasFilteredAttributes( return hasFilteredAttributes(attributes); } - /** Asserts the exemplar has filtered attributes matching all {@code assertions} and no more. */ + /** + * Asserts the exemplar has filtered attributes matching all {@code assertions}. Assertions can be + * created using methods like {@link OpenTelemetryAssertions#satisfies(AttributeKey, + * OpenTelemetryAssertions.LongAssertConsumer)}. + */ public DoubleExemplarAssert hasFilteredAttributesSatisfying(AttributeAssertion... assertions) { return hasFilteredAttributesSatisfying(Arrays.asList(assertions)); } + /** + * Asserts the exemplar has filtered attributes matching all {@code assertions}. Assertions can be + * created using methods like {@link OpenTelemetryAssertions#satisfies(AttributeKey, + * OpenTelemetryAssertions.LongAssertConsumer)}. + */ + public DoubleExemplarAssert hasFilteredAttributesSatisfying( + Iterable assertions) { + AssertUtil.assertAttributes(actual.getFilteredAttributes(), assertions); + return myself; + } + /** * Asserts the exemplar has filtered attributes matching all {@code assertions} and no more. * Assertions can be created using methods like {@link * OpenTelemetryAssertions#satisfies(AttributeKey, OpenTelemetryAssertions.LongAssertConsumer)}. */ - public DoubleExemplarAssert hasFilteredAttributesSatisfying( + public DoubleExemplarAssert hasFilteredAttributesSatisfyingExactly( + AttributeAssertion... assertions) { + return hasFilteredAttributesSatisfyingExactly(Arrays.asList(assertions)); + } + + /** + * Asserts the exemplar has filtered attributes matching all {@code assertions} and no more. + * Assertions can be created using methods like {@link + * OpenTelemetryAssertions#satisfies(AttributeKey, OpenTelemetryAssertions.LongAssertConsumer)}. + */ + public DoubleExemplarAssert hasFilteredAttributesSatisfyingExactly( Iterable assertions) { - AssertUtil.assertAttributes(actual.getFilteredAttributes(), assertions); + AssertUtil.assertAttributesExactly(actual.getFilteredAttributes(), assertions); return myself; } } diff --git a/sdk/testing/src/main/java/io/opentelemetry/sdk/testing/assertj/EventDataAssert.java b/sdk/testing/src/main/java/io/opentelemetry/sdk/testing/assertj/EventDataAssert.java index 9dd24e8c59a..d232a8360e9 100644 --- a/sdk/testing/src/main/java/io/opentelemetry/sdk/testing/assertj/EventDataAssert.java +++ b/sdk/testing/src/main/java/io/opentelemetry/sdk/testing/assertj/EventDataAssert.java @@ -7,9 +7,11 @@ import static org.assertj.core.api.Assertions.assertThat; +import io.opentelemetry.api.common.AttributeKey; import io.opentelemetry.api.common.Attributes; import io.opentelemetry.sdk.trace.data.EventData; import java.time.Instant; +import java.util.Arrays; import java.util.concurrent.TimeUnit; import java.util.function.Consumer; import javax.annotation.Nullable; @@ -82,4 +84,42 @@ public EventDataAssert hasAttributesSatisfying(Consumer attributes) assertThat(actual.getAttributes()).as("attributes").satisfies(attributes); return this; } + + /** + * Asserts the event has attributes matching all {@code assertions}. Assertions can be created + * using methods like {@link OpenTelemetryAssertions#satisfies(AttributeKey, + * OpenTelemetryAssertions.LongAssertConsumer)}. + */ + public EventDataAssert hasAttributesSatisfying(AttributeAssertion... assertions) { + return hasAttributesSatisfying(Arrays.asList(assertions)); + } + + /** + * Asserts the event has attributes matching all {@code assertions}. Assertions can be created + * using methods like {@link OpenTelemetryAssertions#satisfies(AttributeKey, + * OpenTelemetryAssertions.LongAssertConsumer)}. + */ + public EventDataAssert hasAttributesSatisfying(Iterable assertions) { + AssertUtil.assertAttributes(actual.getAttributes(), assertions); + return this; + } + + /** + * Asserts the event has attributes matching all {@code assertions} and no more. Assertions can be + * created using methods like {@link OpenTelemetryAssertions#satisfies(AttributeKey, + * OpenTelemetryAssertions.LongAssertConsumer)}. + */ + public EventDataAssert hasAttributesSatisfyingExactly(AttributeAssertion... assertions) { + return hasAttributesSatisfyingExactly(Arrays.asList(assertions)); + } + + /** + * Asserts the event has attributes matching all {@code assertions} and no more. Assertions can be + * created using methods like {@link OpenTelemetryAssertions#satisfies(AttributeKey, + * OpenTelemetryAssertions.LongAssertConsumer)}. + */ + public EventDataAssert hasAttributesSatisfyingExactly(Iterable assertions) { + AssertUtil.assertAttributesExactly(actual.getAttributes(), assertions); + return this; + } } diff --git a/sdk/testing/src/main/java/io/opentelemetry/sdk/testing/assertj/LongExemplarAssert.java b/sdk/testing/src/main/java/io/opentelemetry/sdk/testing/assertj/LongExemplarAssert.java index 88340854ee5..6fa6659c796 100644 --- a/sdk/testing/src/main/java/io/opentelemetry/sdk/testing/assertj/LongExemplarAssert.java +++ b/sdk/testing/src/main/java/io/opentelemetry/sdk/testing/assertj/LongExemplarAssert.java @@ -96,19 +96,44 @@ public final LongExemplarAssert hasFilteredAttributes( return hasFilteredAttributes(attributes); } - /** Asserts the exemplar has filtered attributes matching all {@code assertions} and no more. */ + /** + * Asserts the exemplar has filtered attributes matching all {@code assertions}. Assertions can be + * created using methods like {@link OpenTelemetryAssertions#satisfies(AttributeKey, + * OpenTelemetryAssertions.LongAssertConsumer)}. + */ public LongExemplarAssert hasFilteredAttributesSatisfying(AttributeAssertion... assertions) { return hasFilteredAttributesSatisfying(Arrays.asList(assertions)); } + /** + * Asserts the exemplar has filtered attributes matching all {@code assertions}. Assertions can be + * created using methods like {@link OpenTelemetryAssertions#satisfies(AttributeKey, + * OpenTelemetryAssertions.LongAssertConsumer)}. + */ + public LongExemplarAssert hasFilteredAttributesSatisfying( + Iterable assertions) { + AssertUtil.assertAttributes(actual.getFilteredAttributes(), assertions); + return myself; + } + + /** + * Asserts the exemplar has filtered attributes matching all {@code assertions} and no more. + * Assertions can be created using methods like {@link + * OpenTelemetryAssertions#satisfies(AttributeKey, OpenTelemetryAssertions.LongAssertConsumer)}. + */ + public LongExemplarAssert hasFilteredAttributesSatisfyingExactly( + AttributeAssertion... assertions) { + return hasFilteredAttributesSatisfying(Arrays.asList(assertions)); + } + /** * Asserts the exemplar has filtered attributes matching all {@code assertions} and no more. * Assertions can be created using methods like {@link * OpenTelemetryAssertions#satisfies(AttributeKey, OpenTelemetryAssertions.LongAssertConsumer)}. */ - public LongExemplarAssert hasFilteredAttributesSatisfying( + public LongExemplarAssert hasFilteredAttributesSatisfyingExactly( Iterable assertions) { - AssertUtil.assertAttributes(actual.getFilteredAttributes(), assertions); + AssertUtil.assertAttributesExactly(actual.getFilteredAttributes(), assertions); return myself; } } 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 3582b0b1129..bde4d9cd27c 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 @@ -22,7 +22,6 @@ import io.opentelemetry.semconv.trace.attributes.SemanticAttributes; import java.time.Instant; import java.util.Arrays; -import java.util.HashSet; import java.util.List; import java.util.Map; import java.util.Set; @@ -307,7 +306,33 @@ public SpanDataAssert hasAttributesSatisfying(Consumer attributes) { return this; } - /** Asserts the span has attributes matching all {@code assertions} and no more. */ + /** + * Asserts the event has attributes matching all {@code assertions}. Assertions can be created + * using methods like {@link OpenTelemetryAssertions#satisfies(AttributeKey, + * OpenTelemetryAssertions.LongAssertConsumer)}. + */ + public SpanDataAssert hasAttributesSatisfying(AttributeAssertion... assertions) { + return hasAttributesSatisfying(Arrays.asList(assertions)); + } + + /** + * Asserts the event has attributes matching all {@code assertions}. Assertions can be created + * using methods like {@link OpenTelemetryAssertions#satisfies(AttributeKey, + * OpenTelemetryAssertions.LongAssertConsumer)}. + */ + public SpanDataAssert hasAttributesSatisfying(Iterable assertions) { + AssertUtil.assertAttributes( + actual.getAttributes(), + assertions, + String.format("span [%s] attribute keys", actual.getName())); + return this; + } + + /** + * Asserts the span has attributes matching all {@code assertions} and no more. Assertions can be + * created using methods like {@link OpenTelemetryAssertions#satisfies(AttributeKey, + * OpenTelemetryAssertions.LongAssertConsumer)}. + */ public SpanDataAssert hasAttributesSatisfyingExactly(AttributeAssertion... assertions) { return hasAttributesSatisfyingExactly(Arrays.asList(assertions)); } @@ -318,22 +343,10 @@ public SpanDataAssert hasAttributesSatisfyingExactly(AttributeAssertion... asser * OpenTelemetryAssertions.LongAssertConsumer)}. */ public SpanDataAssert hasAttributesSatisfyingExactly(Iterable assertions) { - Set> actualKeys = actual.getAttributes().asMap().keySet(); - Set> checkedKeys = new HashSet<>(); - for (AttributeAssertion attributeAssertion : assertions) { - AttributeKey key = attributeAssertion.getKey(); - Object value = actual.getAttributes().get(key); - if (value != null) { - checkedKeys.add(key); - } - AbstractAssert assertion = AttributeAssertion.attributeValueAssertion(key, value); - attributeAssertion.getAssertion().accept(assertion); - } - - assertThat(actualKeys) - .as("span [%s] attribute keys", actual.getName()) - .containsExactlyInAnyOrderElementsOf(checkedKeys); - + AssertUtil.assertAttributesExactly( + actual.getAttributes(), + assertions, + String.format("span [%s] attribute keys", actual.getName())); return this; } diff --git a/sdk/testing/src/test/java/io/opentelemetry/sdk/testing/assertj/AssertUtilTest.java b/sdk/testing/src/test/java/io/opentelemetry/sdk/testing/assertj/AssertUtilTest.java new file mode 100644 index 00000000000..d2f66094057 --- /dev/null +++ b/sdk/testing/src/test/java/io/opentelemetry/sdk/testing/assertj/AssertUtilTest.java @@ -0,0 +1,85 @@ +/* + * Copyright The OpenTelemetry Authors + * SPDX-License-Identifier: Apache-2.0 + */ + +package io.opentelemetry.sdk.testing.assertj; + +import static io.opentelemetry.sdk.testing.assertj.OpenTelemetryAssertions.equalTo; +import static org.assertj.core.api.Assertions.assertThatThrownBy; + +import io.opentelemetry.api.common.AttributeKey; +import io.opentelemetry.api.common.Attributes; +import java.util.Arrays; +import java.util.List; +import org.junit.jupiter.api.Test; + +class AssertUtilTest { + private static final AttributeKey WARM = AttributeKey.booleanKey("warm"); + private static final AttributeKey TEMPERATURE = AttributeKey.longKey("temperature"); + private static final AttributeKey LENGTH = AttributeKey.doubleKey("length"); + private static final AttributeKey> COLORS = AttributeKey.stringArrayKey("colors"); + + private static final Attributes ATTRIBUTES = + Attributes.builder() + .put(WARM, true) + .put(TEMPERATURE, 30) + .put(LENGTH, 1.2) + .put(COLORS, Arrays.asList("red", "blue")) + .build(); + + @Test + void assertAttributesShouldThrowIfNoAttributeMatch() { + List assertions = Arrays.asList(equalTo(WARM, false)); + + assertThatThrownBy(() -> AssertUtil.assertAttributes(ATTRIBUTES, assertions)) + .isInstanceOf(AssertionError.class); + } + + @Test + void assertAttributesShouldNotThrowIfSomeAttributesMatch() { + List assertions = Arrays.asList(equalTo(WARM, true)); + + AssertUtil.assertAttributes(ATTRIBUTES, assertions); + } + + @Test + void assertAttributesShouldNotThrowIfAllAttributesMatch() { + List assertions = + Arrays.asList( + equalTo(WARM, true), + equalTo(TEMPERATURE, 30L), + equalTo(LENGTH, 1.2), + equalTo(COLORS, Arrays.asList("red", "blue"))); + + AssertUtil.assertAttributes(ATTRIBUTES, assertions); + } + + @Test + void assertAttributesExactlyShouldThrowIfNoAttributeMatch() { + List assertions = Arrays.asList(equalTo(WARM, false)); + + assertThatThrownBy(() -> AssertUtil.assertAttributesExactly(ATTRIBUTES, assertions)) + .isInstanceOf(AssertionError.class); + } + + @Test + void assertAttributesExactlyShouldThrowIfSomeAttributesMatch() { + List assertions = Arrays.asList(equalTo(WARM, true)); + + assertThatThrownBy(() -> AssertUtil.assertAttributesExactly(ATTRIBUTES, assertions)) + .isInstanceOf(AssertionError.class); + } + + @Test + void assertAttributesExactlyShouldNotThrowIfAllAttributesMatch() { + List assertions = + Arrays.asList( + equalTo(WARM, true), + equalTo(TEMPERATURE, 30L), + equalTo(LENGTH, 1.2), + equalTo(COLORS, Arrays.asList("red", "blue"))); + + AssertUtil.assertAttributesExactly(ATTRIBUTES, assertions); + } +} diff --git a/sdk/testing/src/test/java/io/opentelemetry/sdk/testing/assertj/MetricAssertionsTest.java b/sdk/testing/src/test/java/io/opentelemetry/sdk/testing/assertj/MetricAssertionsTest.java index b2b68f38539..c8a2e5afd3f 100644 --- a/sdk/testing/src/test/java/io/opentelemetry/sdk/testing/assertj/MetricAssertionsTest.java +++ b/sdk/testing/src/test/java/io/opentelemetry/sdk/testing/assertj/MetricAssertionsTest.java @@ -299,11 +299,7 @@ void doubleGauge() { equalTo(BEAR, "mya"), equalTo(WARM, true), equalTo(TEMPERATURE, 30), - equalTo(LENGTH, 1.2), - equalTo(COLORS, Arrays.asList("red", "blue")), - equalTo(CONDITIONS, Arrays.asList(false, true)), - equalTo(SCORES, Arrays.asList(0L, 1L)), - equalTo(COINS, Arrays.asList(0.01, 0.05, 0.1))) + equalTo(LENGTH, 1.2)) .hasFilteredAttributesSatisfying( satisfies(BEAR, val -> val.startsWith("mya")), satisfies(WARM, val -> val.isTrue()), @@ -321,6 +317,10 @@ void doubleGauge() { // Demonstrates common usage of many exact matches and one // needing a loose one. .hasFilteredAttributesSatisfying( + equalTo(BEAR, "mya"), + equalTo(COLORS, Arrays.asList("red", "blue")), + satisfies(LENGTH, val -> val.isCloseTo(1, offset(0.3)))) + .hasFilteredAttributesSatisfyingExactly( equalTo(BEAR, "mya"), equalTo(WARM, true), equalTo(TEMPERATURE, 30L), @@ -548,6 +548,37 @@ void doubleGaugeFailure() { exemplar -> {}), point -> {}))) .isInstanceOf(AssertionError.class); + assertThatThrownBy( + () -> + assertThat(DOUBLE_GAUGE_METRIC) + .hasDoubleGaugeSatisfying( + gauge -> + gauge.hasPointsSatisfying( + point -> + point.hasExemplarsSatisfying( + exemplar -> + // Extra CAT + exemplar.hasFilteredAttributesSatisfyingExactly( + satisfies(WARM, val -> val.isTrue()), + satisfies( + TEMPERATURE, + val -> val.isGreaterThanOrEqualTo(30)), + satisfies( + LENGTH, val -> val.isCloseTo(1, offset(0.3))), + satisfies( + COLORS, + val -> val.containsExactly("red", "blue")), + satisfies( + CONDITIONS, + val -> val.containsExactly(false, true)), + satisfies( + SCORES, val -> val.containsExactly(0L, 1L)), + satisfies( + COINS, + val -> val.containsExactly(0.01, 0.05, 0.1))), + exemplar -> {}), + point -> {}))) + .isInstanceOf(AssertionError.class); assertThatThrownBy( () -> assertThat(DOUBLE_GAUGE_METRIC) @@ -606,7 +637,26 @@ void longGauge() { point .hasValue(Long.MAX_VALUE) .hasExemplarsSatisfying( - exemplar -> exemplar.hasValue(2), exemplar -> exemplar.hasValue(1)), + exemplar -> exemplar.hasValue(2), + exemplar -> + exemplar + .hasValue(1) + .hasFilteredAttributesSatisfying( + equalTo(BEAR, "mya"), + equalTo(WARM, true), + equalTo(TEMPERATURE, 30L), + equalTo(COLORS, Arrays.asList("red", "blue")), + satisfies(LENGTH, val -> val.isCloseTo(1, offset(0.3)))) + .hasFilteredAttributesSatisfyingExactly( + equalTo(BEAR, "mya"), + equalTo(WARM, true), + equalTo(TEMPERATURE, 30L), + equalTo(COLORS, Arrays.asList("red", "blue")), + equalTo(CONDITIONS, Arrays.asList(false, true)), + equalTo(SCORES, Arrays.asList(0L, 1L)), + equalTo(COINS, Arrays.asList(0.01, 0.05, 0.1)), + satisfies( + LENGTH, val -> val.isCloseTo(1, offset(0.3))))), point -> point.hasValue(1))); } @@ -651,10 +701,38 @@ void longGaugeFailure() { exemplar -> exemplar.hasValue(100), exemplar -> {}), point -> point.hasValue(1)))) .isInstanceOf(AssertionError.class); + assertThatThrownBy( + () -> + assertThat(LONG_GAUGE_METRIC) + .hasLongGaugeSatisfying( + gauge -> + gauge.hasPointsSatisfying( + point -> + point.hasExemplarsSatisfying( + exemplar -> + exemplar.hasFilteredAttributesSatisfying( + equalTo(CAT, "mya"), equalTo(WARM, true)))))) + .isInstanceOf(AssertionError.class); + assertThatThrownBy( + () -> + assertThat(LONG_GAUGE_METRIC) + .hasLongGaugeSatisfying( + gauge -> + gauge.hasPointsSatisfying( + point -> + point.hasExemplarsSatisfying( + exemplar -> + exemplar.hasFilteredAttributesSatisfyingExactly( + equalTo(BEAR, "mya"), + equalTo(WARM, true), + satisfies( + LENGTH, + val -> val.isCloseTo(1, offset(0.3)))))))) + .isInstanceOf(AssertionError.class); } @Test - void duobleSum() { + void doubleSum() { assertThat(DOUBLE_SUM_METRIC) .hasDoubleSumSatisfying( sum -> sum.isMonotonic().isCumulative().hasPointsSatisfying(point -> {}, point -> {})); diff --git a/sdk/testing/src/test/java/io/opentelemetry/sdk/testing/assertj/TraceAssertionsTest.java b/sdk/testing/src/test/java/io/opentelemetry/sdk/testing/assertj/TraceAssertionsTest.java index 58b26fe65ef..d13689a38b0 100644 --- a/sdk/testing/src/test/java/io/opentelemetry/sdk/testing/assertj/TraceAssertionsTest.java +++ b/sdk/testing/src/test/java/io/opentelemetry/sdk/testing/assertj/TraceAssertionsTest.java @@ -158,6 +158,8 @@ void passing() { attributeEntry("conditions", false, true), attributeEntry("scores", 0L, 1L), attributeEntry("coins", 0.01, 0.05, 0.1)) + .hasAttributesSatisfying( + equalTo(BEAR, "mya"), equalTo(WARM, true), equalTo(TEMPERATURE, 30)) .hasAttributesSatisfyingExactly( equalTo(BEAR, "mya"), equalTo(WARM, true), @@ -234,6 +236,15 @@ void passing() { .hasAttributesSatisfying( attributes -> assertThat(attributes).isEqualTo(Attributes.empty())) .hasAttributesSatisfying(attributes -> assertThat(attributes).isEmpty()); + assertThat(events.get(2)) + .hasAttributesSatisfying( + equalTo( + SemanticAttributes.EXCEPTION_TYPE, "java.lang.IllegalArgumentException")) + .hasAttributesSatisfyingExactly( + equalTo( + SemanticAttributes.EXCEPTION_TYPE, "java.lang.IllegalArgumentException"), + equalTo(SemanticAttributes.EXCEPTION_MESSAGE, "bad argument"), + equalTo(SemanticAttributes.EXCEPTION_STACKTRACE, "some obfuscated stack")); }) .hasEventsSatisfyingExactly( event -> event.hasName("event"), @@ -435,6 +446,18 @@ void failure() { attributes -> assertThat(attributes).containsEntry("dogs", "meow")))) .isInstanceOf(AssertionError.class); + assertThatThrownBy( + () -> + assertThat(SPAN1) + .hasEventsSatisfying( + events -> + assertThat(events.get(2)) + .hasAttributesSatisfyingExactly( + equalTo( + SemanticAttributes.EXCEPTION_TYPE, + "java.lang.IllegalArgumentException"), + equalTo(SemanticAttributes.EXCEPTION_MESSAGE, "bad argument")))) + .isInstanceOf(AssertionError.class); assertThatThrownBy( () -> assertThat(SPAN1).hasException(new IllegalStateException("bad argument"))) .isInstanceOf(AssertionError.class); From 568bdb41be45e4f85f8a243c5e4c3c37cd08b564 Mon Sep 17 00:00:00 2001 From: Matt Spataro Date: Tue, 29 Nov 2022 13:31:31 -0700 Subject: [PATCH 67/68] handle noop (#4968) Co-authored-by: Jack Berg --- dependencyManagement/build.gradle.kts | 1 + opentracing-shim/build.gradle.kts | 1 + .../opentracingshim/SpanBuilderShim.java | 5 ++--- .../opentracingshim/SpanBuilderShimTest.java | 15 +++++++++++++++ 4 files changed, 19 insertions(+), 3 deletions(-) diff --git a/dependencyManagement/build.gradle.kts b/dependencyManagement/build.gradle.kts index e8f36e59e4a..26a85b367ca 100644 --- a/dependencyManagement/build.gradle.kts +++ b/dependencyManagement/build.gradle.kts @@ -90,6 +90,7 @@ val DEPENDENCIES = listOf( "io.jaegertracing:jaeger-client:1.8.1", "io.opentelemetry.proto:opentelemetry-proto:0.19.0-alpha", "io.opentracing:opentracing-api:0.33.0", + "io.opentracing:opentracing-noop:0.33.0", "junit:junit:4.13.2", "nl.jqno.equalsverifier:equalsverifier:3.11.1", "org.assertj:assertj-core:3.23.1", diff --git a/opentracing-shim/build.gradle.kts b/opentracing-shim/build.gradle.kts index 98129994fbc..56dac7d0ce8 100644 --- a/opentracing-shim/build.gradle.kts +++ b/opentracing-shim/build.gradle.kts @@ -11,6 +11,7 @@ dependencies { api("io.opentracing:opentracing-api") implementation(project(":semconv")) + implementation("io.opentracing:opentracing-noop:0.33.0") annotationProcessor("com.google.auto.value:auto-value") diff --git a/opentracing-shim/src/main/java/io/opentelemetry/opentracingshim/SpanBuilderShim.java b/opentracing-shim/src/main/java/io/opentelemetry/opentracingshim/SpanBuilderShim.java index 2551e83d7d8..64cf4f0a19d 100644 --- a/opentracing-shim/src/main/java/io/opentelemetry/opentracingshim/SpanBuilderShim.java +++ b/opentracing-shim/src/main/java/io/opentelemetry/opentracingshim/SpanBuilderShim.java @@ -23,6 +23,7 @@ import io.opentracing.Span; import io.opentracing.SpanContext; import io.opentracing.Tracer.SpanBuilder; +import io.opentracing.noop.NoopSpan; import io.opentracing.tag.Tag; import io.opentracing.tag.Tags; import java.util.ArrayList; @@ -63,11 +64,9 @@ public SpanBuilderShim(TelemetryInfo telemetryInfo, String spanName) { @Override public SpanBuilder asChildOf(Span parent) { - if (parent == null) { + if (parent == null || parent instanceof NoopSpan) { return this; } - - // TODO - Verify we handle a no-op Span SpanShim spanShim = ShimUtil.getSpanShim(parent); return addReference(References.CHILD_OF, spanShim.context()); } 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 a915cee1272..ce92600d23c 100644 --- a/opentracing-shim/src/test/java/io/opentelemetry/opentracingshim/SpanBuilderShimTest.java +++ b/opentracing-shim/src/test/java/io/opentelemetry/opentracingshim/SpanBuilderShimTest.java @@ -12,6 +12,7 @@ import io.opentelemetry.api.common.AttributeKey; import io.opentelemetry.api.common.Attributes; import io.opentelemetry.api.trace.SpanContext; +import io.opentelemetry.api.trace.SpanId; import io.opentelemetry.api.trace.SpanKind; import io.opentelemetry.api.trace.Tracer; import io.opentelemetry.context.Context; @@ -24,6 +25,7 @@ import io.opentelemetry.sdk.trace.samplers.SamplingResult; import io.opentelemetry.semconv.trace.attributes.SemanticAttributes; import io.opentracing.References; +import io.opentracing.noop.NoopSpan; import io.opentracing.tag.Tags; import java.math.BigInteger; import java.util.List; @@ -79,6 +81,19 @@ void parent_single() { } } + @Test + void noop_parent_span() { + SpanShim childSpan = + (SpanShim) + new SpanBuilderShim(telemetryInfo, SPAN_NAME).asChildOf(NoopSpan.INSTANCE).start(); + try { + SpanData spanData = ((ReadableSpan) childSpan.getSpan()).toSpanData(); + assertThat(SpanId.isValid(spanData.getParentSpanId())).isFalse(); + } finally { + childSpan.finish(); + } + } + @Test void parent_multipleFollowsFrom() { SpanShim parentSpan1 = (SpanShim) new SpanBuilderShim(telemetryInfo, SPAN_NAME).start(); From 2a231d76f80110bb5292eb4856f17c06a4a2972c Mon Sep 17 00:00:00 2001 From: jack-berg <34418638+jack-berg@users.noreply.github.com> Date: Wed, 30 Nov 2022 10:18:53 -0600 Subject: [PATCH 68/68] Move DefaultConfigProperties to autoconfigure-spi (#5001) --- .../internal}/DefaultConfigProperties.java | 43 +++++++++++++------ ...AutoConfiguredOpenTelemetrySdkBuilder.java | 5 ++- .../LogRecordExporterConfiguration.java | 1 + .../MeterProviderConfiguration.java | 1 + .../SpanExporterConfiguration.java | 1 + .../autoconfigure/ConfigPropertiesTest.java | 7 +-- .../LogRecordExporterConfigurationTest.java | 1 + .../LoggerProviderConfigurationTest.java | 1 + .../sdk/autoconfigure/NotOnClasspathTest.java | 1 + .../PropagatorConfigurationTest.java | 1 + .../ResourceConfigurationFuzzTest.java | 1 + .../ResourceConfigurationTest.java | 3 +- .../sdk/autoconfigure/SpiUtilTest.java | 1 + .../TracerProviderConfigurationTest.java | 1 + .../ConfigurableLogRecordExporterTest.java | 1 + .../ConfigurableMetricExporterTest.java | 1 + .../ConfigurableSamplerTest.java | 1 + .../ConfigurableSpanExporterTest.java | 1 + .../LoggerProviderConfigurationTest.java | 1 + .../MetricExporterConfigurationTest.java | 1 + .../sdk/autoconfigure/OtlpConfigUtilTest.java | 1 + .../ResourceConfigurationTest.java | 11 ++--- .../SpanExporterConfigurationTest.java | 1 + .../sdk/autoconfigure/LoggingOtlpTest.java | 1 + .../sdk/autoconfigure/OtlpGrpcConfigTest.java | 1 + .../sdk/autoconfigure/OtlpGrpcRetryTest.java | 1 + .../sdk/autoconfigure/OtlpHttpConfigTest.java | 1 + .../sdk/autoconfigure/OtlpHttpRetryTest.java | 1 + 28 files changed, 67 insertions(+), 25 deletions(-) rename sdk-extensions/{autoconfigure/src/main/java/io/opentelemetry/sdk/autoconfigure => autoconfigure-spi/src/main/java/io/opentelemetry/sdk/autoconfigure/spi/internal}/DefaultConfigProperties.java (85%) diff --git a/sdk-extensions/autoconfigure/src/main/java/io/opentelemetry/sdk/autoconfigure/DefaultConfigProperties.java b/sdk-extensions/autoconfigure-spi/src/main/java/io/opentelemetry/sdk/autoconfigure/spi/internal/DefaultConfigProperties.java similarity index 85% rename from sdk-extensions/autoconfigure/src/main/java/io/opentelemetry/sdk/autoconfigure/DefaultConfigProperties.java rename to sdk-extensions/autoconfigure-spi/src/main/java/io/opentelemetry/sdk/autoconfigure/spi/internal/DefaultConfigProperties.java index 48ec584367f..a696f6f4797 100644 --- a/sdk-extensions/autoconfigure/src/main/java/io/opentelemetry/sdk/autoconfigure/DefaultConfigProperties.java +++ b/sdk-extensions/autoconfigure-spi/src/main/java/io/opentelemetry/sdk/autoconfigure/spi/internal/DefaultConfigProperties.java @@ -3,7 +3,7 @@ * SPDX-License-Identifier: Apache-2.0 */ -package io.opentelemetry.sdk.autoconfigure; +package io.opentelemetry.sdk.autoconfigure.spi.internal; import static java.util.stream.Collectors.groupingBy; import static java.util.stream.Collectors.joining; @@ -27,26 +27,33 @@ import javax.annotation.Nullable; /** - * Properties to be used for auto-configuration of the OpenTelemetry SDK components. These - * properties will be a combination of system properties and environment variables. The properties - * for both of these will be normalized to be all lower case, and underscores will be replaced with + * Properties are normalized to The properties for both of these will be normalized to be all lower + * case, dashses are replaces with periods, and environment variable underscores are replaces with * periods. + * + *

This class is internal and is hence not for public use. Its APIs are unstable and can change + * at any time. */ -final class DefaultConfigProperties implements ConfigProperties { +public final class DefaultConfigProperties implements ConfigProperties { private final Map config; - static DefaultConfigProperties get(Map defaultProperties) { + /** + * Creates a {@link DefaultConfigProperties} by merging system properties, environment variables, + * and the {@code defaultProperties}. + * + *

Environment variables take priority over {@code defaultProperties}. System properties take + * priority over system properties. + */ + public static DefaultConfigProperties create(Map defaultProperties) { return new DefaultConfigProperties(System.getProperties(), System.getenv(), defaultProperties); } - static DefaultConfigProperties customize( - DefaultConfigProperties previousProperties, Map overrides) { - return new DefaultConfigProperties(previousProperties, overrides); - } - - // Visible for testing - static ConfigProperties createForTest(Map properties) { + /** + * Create a {@link DefaultConfigProperties} from the {@code properties}, ignoring system + * properties and environment variables. + */ + public static DefaultConfigProperties createForTest(Map properties) { return new DefaultConfigProperties(properties, Collections.emptyMap(), Collections.emptyMap()); } @@ -180,7 +187,7 @@ public List getList(String name) { * * @throws ConfigurationException if {@code name} contains duplicate entries */ - static Set getSet(ConfigProperties config, String name) { + public static Set getSet(ConfigProperties config, String name) { List list = config.getList(normalize(name)); Set set = new HashSet<>(list); if (set.size() != list.size()) { @@ -217,6 +224,14 @@ public Map getMap(String name) { Map.Entry::getKey, Map.Entry::getValue, (first, next) -> next, LinkedHashMap::new)); } + /** + * Return a new {@link DefaultConfigProperties} by overriding the {@code previousProperties} with + * the {@code overrides}. + */ + public DefaultConfigProperties withOverrides(Map overrides) { + return new DefaultConfigProperties(this, overrides); + } + private static ConfigurationException newInvalidPropertyException( String name, String value, String type) { throw new ConfigurationException( 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 c8d633a4b8f..5ba094b91e0 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 @@ -16,6 +16,7 @@ import io.opentelemetry.sdk.autoconfigure.spi.AutoConfigurationCustomizer; import io.opentelemetry.sdk.autoconfigure.spi.AutoConfigurationCustomizerProvider; import io.opentelemetry.sdk.autoconfigure.spi.ConfigProperties; +import io.opentelemetry.sdk.autoconfigure.spi.internal.DefaultConfigProperties; import io.opentelemetry.sdk.common.CompletableResultCode; import io.opentelemetry.sdk.logs.SdkLoggerProvider; import io.opentelemetry.sdk.logs.SdkLoggerProviderBuilder; @@ -424,10 +425,10 @@ private ConfigProperties getConfig() { } private ConfigProperties computeConfigProperties() { - DefaultConfigProperties properties = DefaultConfigProperties.get(propertiesSupplier.get()); + DefaultConfigProperties properties = DefaultConfigProperties.create(propertiesSupplier.get()); for (Function> customizer : propertiesCustomizers) { Map overrides = customizer.apply(properties); - properties = DefaultConfigProperties.customize(properties, overrides); + properties = properties.withOverrides(overrides); } return properties; } diff --git a/sdk-extensions/autoconfigure/src/main/java/io/opentelemetry/sdk/autoconfigure/LogRecordExporterConfiguration.java b/sdk-extensions/autoconfigure/src/main/java/io/opentelemetry/sdk/autoconfigure/LogRecordExporterConfiguration.java index 981ff3740d7..0d7a38b3097 100644 --- a/sdk-extensions/autoconfigure/src/main/java/io/opentelemetry/sdk/autoconfigure/LogRecordExporterConfiguration.java +++ b/sdk-extensions/autoconfigure/src/main/java/io/opentelemetry/sdk/autoconfigure/LogRecordExporterConfiguration.java @@ -17,6 +17,7 @@ import io.opentelemetry.exporter.otlp.logs.OtlpGrpcLogRecordExporterBuilder; import io.opentelemetry.sdk.autoconfigure.spi.ConfigProperties; import io.opentelemetry.sdk.autoconfigure.spi.ConfigurationException; +import io.opentelemetry.sdk.autoconfigure.spi.internal.DefaultConfigProperties; import io.opentelemetry.sdk.autoconfigure.spi.logs.ConfigurableLogRecordExporterProvider; import io.opentelemetry.sdk.logs.export.LogRecordExporter; import java.util.Collections; diff --git a/sdk-extensions/autoconfigure/src/main/java/io/opentelemetry/sdk/autoconfigure/MeterProviderConfiguration.java b/sdk-extensions/autoconfigure/src/main/java/io/opentelemetry/sdk/autoconfigure/MeterProviderConfiguration.java index 350b35ec881..40dd14c0a7c 100644 --- a/sdk-extensions/autoconfigure/src/main/java/io/opentelemetry/sdk/autoconfigure/MeterProviderConfiguration.java +++ b/sdk-extensions/autoconfigure/src/main/java/io/opentelemetry/sdk/autoconfigure/MeterProviderConfiguration.java @@ -7,6 +7,7 @@ import io.opentelemetry.sdk.autoconfigure.spi.ConfigProperties; import io.opentelemetry.sdk.autoconfigure.spi.ConfigurationException; +import io.opentelemetry.sdk.autoconfigure.spi.internal.DefaultConfigProperties; import io.opentelemetry.sdk.metrics.SdkMeterProviderBuilder; import io.opentelemetry.sdk.metrics.export.MetricExporter; import io.opentelemetry.sdk.metrics.export.MetricReader; diff --git a/sdk-extensions/autoconfigure/src/main/java/io/opentelemetry/sdk/autoconfigure/SpanExporterConfiguration.java b/sdk-extensions/autoconfigure/src/main/java/io/opentelemetry/sdk/autoconfigure/SpanExporterConfiguration.java index f9b5608826b..b7644f760aa 100644 --- a/sdk-extensions/autoconfigure/src/main/java/io/opentelemetry/sdk/autoconfigure/SpanExporterConfiguration.java +++ b/sdk-extensions/autoconfigure/src/main/java/io/opentelemetry/sdk/autoconfigure/SpanExporterConfiguration.java @@ -20,6 +20,7 @@ import io.opentelemetry.exporter.otlp.trace.OtlpGrpcSpanExporterBuilder; import io.opentelemetry.sdk.autoconfigure.spi.ConfigProperties; import io.opentelemetry.sdk.autoconfigure.spi.ConfigurationException; +import io.opentelemetry.sdk.autoconfigure.spi.internal.DefaultConfigProperties; import io.opentelemetry.sdk.autoconfigure.spi.traces.ConfigurableSpanExporterProvider; import io.opentelemetry.sdk.trace.export.SpanExporter; import java.time.Duration; diff --git a/sdk-extensions/autoconfigure/src/test/java/io/opentelemetry/sdk/autoconfigure/ConfigPropertiesTest.java b/sdk-extensions/autoconfigure/src/test/java/io/opentelemetry/sdk/autoconfigure/ConfigPropertiesTest.java index 1cf41bd0daf..d4ac3b59f9a 100644 --- a/sdk-extensions/autoconfigure/src/test/java/io/opentelemetry/sdk/autoconfigure/ConfigPropertiesTest.java +++ b/sdk-extensions/autoconfigure/src/test/java/io/opentelemetry/sdk/autoconfigure/ConfigPropertiesTest.java @@ -13,6 +13,7 @@ import io.opentelemetry.sdk.autoconfigure.spi.ConfigProperties; import io.opentelemetry.sdk.autoconfigure.spi.ConfigurationException; +import io.opentelemetry.sdk.autoconfigure.spi.internal.DefaultConfigProperties; import java.time.Duration; import java.util.Arrays; import java.util.Collections; @@ -236,7 +237,7 @@ void defaultMethodsDelegate() { expectedMap.put("bear", "growl"); Map map = makeTestProps(); - ConfigProperties properties = DefaultConfigProperties.get(map); + ConfigProperties properties = DefaultConfigProperties.create(map); assertThat(properties.getBoolean("test.boolean", false)).isTrue(); assertThat(properties.getString("test.string", "nah")).isEqualTo("str"); assertThat(properties.getDouble("test.double", 65.535)).isEqualTo(5.4); @@ -250,7 +251,7 @@ void defaultMethodsDelegate() { @Test void defaultMethodsFallBack() { - ConfigProperties properties = DefaultConfigProperties.get(emptyMap()); + ConfigProperties properties = DefaultConfigProperties.create(emptyMap()); assertThat(properties.getBoolean("foo", true)).isTrue(); assertThat(properties.getString("foo", "bar")).isEqualTo("bar"); assertThat(properties.getDouble("foo", 65.535)).isEqualTo(65.535); @@ -261,7 +262,7 @@ void defaultMethodsFallBack() { @Test void defaultCollectionTypes() { - ConfigProperties properties = DefaultConfigProperties.get(emptyMap()); + ConfigProperties properties = DefaultConfigProperties.create(emptyMap()); assertThat(properties.getList("foo", Arrays.asList("1", "2", "3"))) .containsExactly("1", "2", "3"); assertThat(properties.getList("foo")).isEmpty(); diff --git a/sdk-extensions/autoconfigure/src/test/java/io/opentelemetry/sdk/autoconfigure/LogRecordExporterConfigurationTest.java b/sdk-extensions/autoconfigure/src/test/java/io/opentelemetry/sdk/autoconfigure/LogRecordExporterConfigurationTest.java index 29884cb5651..d5f7d1146fe 100644 --- a/sdk-extensions/autoconfigure/src/test/java/io/opentelemetry/sdk/autoconfigure/LogRecordExporterConfigurationTest.java +++ b/sdk-extensions/autoconfigure/src/test/java/io/opentelemetry/sdk/autoconfigure/LogRecordExporterConfigurationTest.java @@ -11,6 +11,7 @@ import io.opentelemetry.api.metrics.MeterProvider; import io.opentelemetry.sdk.autoconfigure.spi.ConfigProperties; import io.opentelemetry.sdk.autoconfigure.spi.ConfigurationException; +import io.opentelemetry.sdk.autoconfigure.spi.internal.DefaultConfigProperties; import org.junit.jupiter.api.Test; class LogRecordExporterConfigurationTest { diff --git a/sdk-extensions/autoconfigure/src/test/java/io/opentelemetry/sdk/autoconfigure/LoggerProviderConfigurationTest.java b/sdk-extensions/autoconfigure/src/test/java/io/opentelemetry/sdk/autoconfigure/LoggerProviderConfigurationTest.java index f70e382b73f..9c5ccb84afd 100644 --- a/sdk-extensions/autoconfigure/src/test/java/io/opentelemetry/sdk/autoconfigure/LoggerProviderConfigurationTest.java +++ b/sdk-extensions/autoconfigure/src/test/java/io/opentelemetry/sdk/autoconfigure/LoggerProviderConfigurationTest.java @@ -11,6 +11,7 @@ import com.google.common.collect.ImmutableMap; import io.opentelemetry.api.metrics.MeterProvider; import io.opentelemetry.sdk.autoconfigure.spi.ConfigProperties; +import io.opentelemetry.sdk.autoconfigure.spi.internal.DefaultConfigProperties; import io.opentelemetry.sdk.logs.LogLimits; import io.opentelemetry.sdk.logs.LogRecordProcessor; import io.opentelemetry.sdk.logs.SdkLoggerProvider; diff --git a/sdk-extensions/autoconfigure/src/test/java/io/opentelemetry/sdk/autoconfigure/NotOnClasspathTest.java b/sdk-extensions/autoconfigure/src/test/java/io/opentelemetry/sdk/autoconfigure/NotOnClasspathTest.java index 6ae928b6607..e82c58aeddd 100644 --- a/sdk-extensions/autoconfigure/src/test/java/io/opentelemetry/sdk/autoconfigure/NotOnClasspathTest.java +++ b/sdk-extensions/autoconfigure/src/test/java/io/opentelemetry/sdk/autoconfigure/NotOnClasspathTest.java @@ -11,6 +11,7 @@ import io.opentelemetry.api.metrics.MeterProvider; import io.opentelemetry.sdk.autoconfigure.spi.ConfigProperties; import io.opentelemetry.sdk.autoconfigure.spi.ConfigurationException; +import io.opentelemetry.sdk.autoconfigure.spi.internal.DefaultConfigProperties; import java.util.Collections; import org.junit.jupiter.api.Test; diff --git a/sdk-extensions/autoconfigure/src/test/java/io/opentelemetry/sdk/autoconfigure/PropagatorConfigurationTest.java b/sdk-extensions/autoconfigure/src/test/java/io/opentelemetry/sdk/autoconfigure/PropagatorConfigurationTest.java index 74aca205711..54cf999acba 100644 --- a/sdk-extensions/autoconfigure/src/test/java/io/opentelemetry/sdk/autoconfigure/PropagatorConfigurationTest.java +++ b/sdk-extensions/autoconfigure/src/test/java/io/opentelemetry/sdk/autoconfigure/PropagatorConfigurationTest.java @@ -8,6 +8,7 @@ import static org.assertj.core.api.Assertions.assertThat; import io.opentelemetry.context.propagation.ContextPropagators; +import io.opentelemetry.sdk.autoconfigure.spi.internal.DefaultConfigProperties; import java.util.Collections; import org.junit.jupiter.api.Test; diff --git a/sdk-extensions/autoconfigure/src/test/java/io/opentelemetry/sdk/autoconfigure/ResourceConfigurationFuzzTest.java b/sdk-extensions/autoconfigure/src/test/java/io/opentelemetry/sdk/autoconfigure/ResourceConfigurationFuzzTest.java index 3199f7320d7..e0152ea9b11 100644 --- a/sdk-extensions/autoconfigure/src/test/java/io/opentelemetry/sdk/autoconfigure/ResourceConfigurationFuzzTest.java +++ b/sdk-extensions/autoconfigure/src/test/java/io/opentelemetry/sdk/autoconfigure/ResourceConfigurationFuzzTest.java @@ -14,6 +14,7 @@ import edu.berkeley.cs.jqf.fuzz.random.NoGuidance; import io.opentelemetry.api.common.Attributes; import io.opentelemetry.api.internal.PercentEscaper; +import io.opentelemetry.sdk.autoconfigure.spi.internal.DefaultConfigProperties; import org.junit.jupiter.api.Test; import org.junit.runner.Result; import org.junit.runner.RunWith; diff --git a/sdk-extensions/autoconfigure/src/test/java/io/opentelemetry/sdk/autoconfigure/ResourceConfigurationTest.java b/sdk-extensions/autoconfigure/src/test/java/io/opentelemetry/sdk/autoconfigure/ResourceConfigurationTest.java index 7993074bca3..9c8e85ac432 100644 --- a/sdk-extensions/autoconfigure/src/test/java/io/opentelemetry/sdk/autoconfigure/ResourceConfigurationTest.java +++ b/sdk-extensions/autoconfigure/src/test/java/io/opentelemetry/sdk/autoconfigure/ResourceConfigurationTest.java @@ -14,6 +14,7 @@ import io.opentelemetry.api.common.AttributeKey; import io.opentelemetry.api.common.Attributes; import io.opentelemetry.sdk.autoconfigure.spi.ConfigProperties; +import io.opentelemetry.sdk.autoconfigure.spi.internal.DefaultConfigProperties; import io.opentelemetry.sdk.resources.Resource; import io.opentelemetry.semconv.resource.attributes.ResourceAttributes; import java.util.HashMap; @@ -34,7 +35,7 @@ void customConfigResource() { assertThat( ResourceConfiguration.configureResource( - DefaultConfigProperties.get(props), + DefaultConfigProperties.create(props), ResourceConfigurationTest.class.getClassLoader(), (r, c) -> r)) .isEqualTo( diff --git a/sdk-extensions/autoconfigure/src/test/java/io/opentelemetry/sdk/autoconfigure/SpiUtilTest.java b/sdk-extensions/autoconfigure/src/test/java/io/opentelemetry/sdk/autoconfigure/SpiUtilTest.java index ce842bd34d7..5733b41c6d0 100644 --- a/sdk-extensions/autoconfigure/src/test/java/io/opentelemetry/sdk/autoconfigure/SpiUtilTest.java +++ b/sdk-extensions/autoconfigure/src/test/java/io/opentelemetry/sdk/autoconfigure/SpiUtilTest.java @@ -16,6 +16,7 @@ import io.opentelemetry.sdk.autoconfigure.spi.ConfigProperties; import io.opentelemetry.sdk.autoconfigure.spi.ResourceProvider; +import io.opentelemetry.sdk.autoconfigure.spi.internal.DefaultConfigProperties; import java.util.Collections; import java.util.List; import org.junit.jupiter.api.Test; diff --git a/sdk-extensions/autoconfigure/src/test/java/io/opentelemetry/sdk/autoconfigure/TracerProviderConfigurationTest.java b/sdk-extensions/autoconfigure/src/test/java/io/opentelemetry/sdk/autoconfigure/TracerProviderConfigurationTest.java index 43f464f8a49..db56602d21c 100644 --- a/sdk-extensions/autoconfigure/src/test/java/io/opentelemetry/sdk/autoconfigure/TracerProviderConfigurationTest.java +++ b/sdk-extensions/autoconfigure/src/test/java/io/opentelemetry/sdk/autoconfigure/TracerProviderConfigurationTest.java @@ -14,6 +14,7 @@ import io.opentelemetry.api.metrics.MeterProvider; import io.opentelemetry.sdk.autoconfigure.spi.ConfigProperties; import io.opentelemetry.sdk.autoconfigure.spi.ConfigurationException; +import io.opentelemetry.sdk.autoconfigure.spi.internal.DefaultConfigProperties; import io.opentelemetry.sdk.common.CompletableResultCode; import io.opentelemetry.sdk.resources.Resource; import io.opentelemetry.sdk.trace.SdkTracerProvider; diff --git a/sdk-extensions/autoconfigure/src/testFullConfig/java/io/opentelemetry/sdk/autoconfigure/ConfigurableLogRecordExporterTest.java b/sdk-extensions/autoconfigure/src/testFullConfig/java/io/opentelemetry/sdk/autoconfigure/ConfigurableLogRecordExporterTest.java index 71e7c5df076..39a0f186126 100644 --- a/sdk-extensions/autoconfigure/src/testFullConfig/java/io/opentelemetry/sdk/autoconfigure/ConfigurableLogRecordExporterTest.java +++ b/sdk-extensions/autoconfigure/src/testFullConfig/java/io/opentelemetry/sdk/autoconfigure/ConfigurableLogRecordExporterTest.java @@ -12,6 +12,7 @@ import io.opentelemetry.api.metrics.MeterProvider; import io.opentelemetry.sdk.autoconfigure.spi.ConfigProperties; import io.opentelemetry.sdk.autoconfigure.spi.ConfigurationException; +import io.opentelemetry.sdk.autoconfigure.spi.internal.DefaultConfigProperties; import io.opentelemetry.sdk.logs.export.LogRecordExporter; import java.net.URL; import java.net.URLClassLoader; diff --git a/sdk-extensions/autoconfigure/src/testFullConfig/java/io/opentelemetry/sdk/autoconfigure/ConfigurableMetricExporterTest.java b/sdk-extensions/autoconfigure/src/testFullConfig/java/io/opentelemetry/sdk/autoconfigure/ConfigurableMetricExporterTest.java index f2b48063a0b..999c6ea27a1 100644 --- a/sdk-extensions/autoconfigure/src/testFullConfig/java/io/opentelemetry/sdk/autoconfigure/ConfigurableMetricExporterTest.java +++ b/sdk-extensions/autoconfigure/src/testFullConfig/java/io/opentelemetry/sdk/autoconfigure/ConfigurableMetricExporterTest.java @@ -13,6 +13,7 @@ import io.opentelemetry.exporter.prometheus.PrometheusHttpServer; import io.opentelemetry.sdk.autoconfigure.spi.ConfigProperties; import io.opentelemetry.sdk.autoconfigure.spi.ConfigurationException; +import io.opentelemetry.sdk.autoconfigure.spi.internal.DefaultConfigProperties; import io.opentelemetry.sdk.metrics.SdkMeterProvider; import io.opentelemetry.sdk.metrics.export.MetricExporter; import io.opentelemetry.sdk.metrics.export.PeriodicMetricReader; diff --git a/sdk-extensions/autoconfigure/src/testFullConfig/java/io/opentelemetry/sdk/autoconfigure/ConfigurableSamplerTest.java b/sdk-extensions/autoconfigure/src/testFullConfig/java/io/opentelemetry/sdk/autoconfigure/ConfigurableSamplerTest.java index c61f94f90b3..72caebd6734 100644 --- a/sdk-extensions/autoconfigure/src/testFullConfig/java/io/opentelemetry/sdk/autoconfigure/ConfigurableSamplerTest.java +++ b/sdk-extensions/autoconfigure/src/testFullConfig/java/io/opentelemetry/sdk/autoconfigure/ConfigurableSamplerTest.java @@ -11,6 +11,7 @@ import com.google.common.collect.ImmutableMap; import io.opentelemetry.sdk.autoconfigure.spi.ConfigProperties; import io.opentelemetry.sdk.autoconfigure.spi.ConfigurationException; +import io.opentelemetry.sdk.autoconfigure.spi.internal.DefaultConfigProperties; import io.opentelemetry.sdk.trace.samplers.Sampler; import java.net.URL; import java.net.URLClassLoader; 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 3f5e3d59279..f3b5fd0be8f 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 @@ -15,6 +15,7 @@ import io.opentelemetry.exporter.zipkin.ZipkinSpanExporter; import io.opentelemetry.sdk.autoconfigure.spi.ConfigProperties; import io.opentelemetry.sdk.autoconfigure.spi.ConfigurationException; +import io.opentelemetry.sdk.autoconfigure.spi.internal.DefaultConfigProperties; import io.opentelemetry.sdk.trace.export.BatchSpanProcessor; import io.opentelemetry.sdk.trace.export.SimpleSpanProcessor; import io.opentelemetry.sdk.trace.export.SpanExporter; diff --git a/sdk-extensions/autoconfigure/src/testFullConfig/java/io/opentelemetry/sdk/autoconfigure/LoggerProviderConfigurationTest.java b/sdk-extensions/autoconfigure/src/testFullConfig/java/io/opentelemetry/sdk/autoconfigure/LoggerProviderConfigurationTest.java index cb5a7254731..5fff386ee69 100644 --- a/sdk-extensions/autoconfigure/src/testFullConfig/java/io/opentelemetry/sdk/autoconfigure/LoggerProviderConfigurationTest.java +++ b/sdk-extensions/autoconfigure/src/testFullConfig/java/io/opentelemetry/sdk/autoconfigure/LoggerProviderConfigurationTest.java @@ -11,6 +11,7 @@ import io.opentelemetry.api.metrics.MeterProvider; import io.opentelemetry.exporter.logging.SystemOutLogRecordExporter; import io.opentelemetry.exporter.otlp.logs.OtlpGrpcLogRecordExporter; +import io.opentelemetry.sdk.autoconfigure.spi.internal.DefaultConfigProperties; import io.opentelemetry.sdk.logs.SdkLoggerProvider; import io.opentelemetry.sdk.logs.SdkLoggerProviderBuilder; import io.opentelemetry.sdk.logs.export.BatchLogRecordProcessor; diff --git a/sdk-extensions/autoconfigure/src/testFullConfig/java/io/opentelemetry/sdk/autoconfigure/MetricExporterConfigurationTest.java b/sdk-extensions/autoconfigure/src/testFullConfig/java/io/opentelemetry/sdk/autoconfigure/MetricExporterConfigurationTest.java index a0bdb80102a..6be98b6f069 100644 --- a/sdk-extensions/autoconfigure/src/testFullConfig/java/io/opentelemetry/sdk/autoconfigure/MetricExporterConfigurationTest.java +++ b/sdk-extensions/autoconfigure/src/testFullConfig/java/io/opentelemetry/sdk/autoconfigure/MetricExporterConfigurationTest.java @@ -9,6 +9,7 @@ import com.google.common.collect.ImmutableMap; import io.opentelemetry.sdk.autoconfigure.spi.ConfigurationException; +import io.opentelemetry.sdk.autoconfigure.spi.internal.DefaultConfigProperties; import org.junit.jupiter.api.Test; public class MetricExporterConfigurationTest { diff --git a/sdk-extensions/autoconfigure/src/testFullConfig/java/io/opentelemetry/sdk/autoconfigure/OtlpConfigUtilTest.java b/sdk-extensions/autoconfigure/src/testFullConfig/java/io/opentelemetry/sdk/autoconfigure/OtlpConfigUtilTest.java index 38572527034..de795f50e08 100644 --- a/sdk-extensions/autoconfigure/src/testFullConfig/java/io/opentelemetry/sdk/autoconfigure/OtlpConfigUtilTest.java +++ b/sdk-extensions/autoconfigure/src/testFullConfig/java/io/opentelemetry/sdk/autoconfigure/OtlpConfigUtilTest.java @@ -16,6 +16,7 @@ import com.google.common.collect.ImmutableMap; import io.opentelemetry.sdk.autoconfigure.spi.ConfigurationException; +import io.opentelemetry.sdk.autoconfigure.spi.internal.DefaultConfigProperties; import io.opentelemetry.sdk.metrics.InstrumentType; import io.opentelemetry.sdk.metrics.data.AggregationTemporality; import io.opentelemetry.sdk.metrics.export.AggregationTemporalitySelector; diff --git a/sdk-extensions/autoconfigure/src/testFullConfig/java/io/opentelemetry/sdk/autoconfigure/ResourceConfigurationTest.java b/sdk-extensions/autoconfigure/src/testFullConfig/java/io/opentelemetry/sdk/autoconfigure/ResourceConfigurationTest.java index ec5b149277c..8aa149e2856 100644 --- a/sdk-extensions/autoconfigure/src/testFullConfig/java/io/opentelemetry/sdk/autoconfigure/ResourceConfigurationTest.java +++ b/sdk-extensions/autoconfigure/src/testFullConfig/java/io/opentelemetry/sdk/autoconfigure/ResourceConfigurationTest.java @@ -9,6 +9,7 @@ import io.opentelemetry.api.common.AttributeKey; import io.opentelemetry.api.common.Attributes; +import io.opentelemetry.sdk.autoconfigure.spi.internal.DefaultConfigProperties; import java.net.URL; import java.net.URLClassLoader; import java.util.Collections; @@ -22,7 +23,7 @@ class ResourceConfigurationTest { void configureResource() { Attributes attributes = ResourceConfiguration.configureResource( - DefaultConfigProperties.get(Collections.emptyMap()), + DefaultConfigProperties.create(Collections.emptyMap()), ResourceConfigurationTest.class.getClassLoader(), (r, c) -> r) .getAttributes(); @@ -35,7 +36,7 @@ void configureResource() { void configureResource_EmptyClassLoader() { Attributes attributes = ResourceConfiguration.configureResource( - DefaultConfigProperties.get(Collections.emptyMap()), + DefaultConfigProperties.create(Collections.emptyMap()), new URLClassLoader(new URL[0], null), (r, c) -> r) .getAttributes(); @@ -52,7 +53,7 @@ void configureResource_OnlyEnabled() { "io.opentelemetry.sdk.autoconfigure.TestAnimalResourceProvider"); Attributes attributes = ResourceConfiguration.configureResource( - DefaultConfigProperties.get(customConfigs), + DefaultConfigProperties.create(customConfigs), ResourceConfigurationTest.class.getClassLoader(), (r, c) -> r) .getAttributes(); @@ -72,7 +73,7 @@ void configureResource_EnabledAndDisabled() { "io.opentelemetry.sdk.extension.resources.TestColorResourceProvider"); Attributes attributes = ResourceConfiguration.configureResource( - DefaultConfigProperties.get(customConfigs), + DefaultConfigProperties.create(customConfigs), ResourceConfigurationTest.class.getClassLoader(), (r, c) -> r) .getAttributes(); @@ -89,7 +90,7 @@ void configureResource_OnlyDisabled() { "io.opentelemetry.sdk.autoconfigure.TestColorResourceProvider"); Attributes attributes = ResourceConfiguration.configureResource( - DefaultConfigProperties.get(customConfigs), + DefaultConfigProperties.create(customConfigs), ResourceConfigurationTest.class.getClassLoader(), (r, c) -> r) .getAttributes(); diff --git a/sdk-extensions/autoconfigure/src/testFullConfig/java/io/opentelemetry/sdk/autoconfigure/SpanExporterConfigurationTest.java b/sdk-extensions/autoconfigure/src/testFullConfig/java/io/opentelemetry/sdk/autoconfigure/SpanExporterConfigurationTest.java index 5bc04ef890f..6fce08e43d0 100644 --- a/sdk-extensions/autoconfigure/src/testFullConfig/java/io/opentelemetry/sdk/autoconfigure/SpanExporterConfigurationTest.java +++ b/sdk-extensions/autoconfigure/src/testFullConfig/java/io/opentelemetry/sdk/autoconfigure/SpanExporterConfigurationTest.java @@ -14,6 +14,7 @@ import io.opentelemetry.exporter.otlp.trace.OtlpGrpcSpanExporter; import io.opentelemetry.sdk.autoconfigure.spi.ConfigProperties; import io.opentelemetry.sdk.autoconfigure.spi.ConfigurationException; +import io.opentelemetry.sdk.autoconfigure.spi.internal.DefaultConfigProperties; import io.opentelemetry.sdk.trace.export.SpanExporter; import java.util.Collections; import org.junit.jupiter.api.Test; diff --git a/sdk-extensions/autoconfigure/src/testLoggingOtlp/java/io/opentelemetry/sdk/autoconfigure/LoggingOtlpTest.java b/sdk-extensions/autoconfigure/src/testLoggingOtlp/java/io/opentelemetry/sdk/autoconfigure/LoggingOtlpTest.java index aba93ae800e..50974adb338 100644 --- a/sdk-extensions/autoconfigure/src/testLoggingOtlp/java/io/opentelemetry/sdk/autoconfigure/LoggingOtlpTest.java +++ b/sdk-extensions/autoconfigure/src/testLoggingOtlp/java/io/opentelemetry/sdk/autoconfigure/LoggingOtlpTest.java @@ -14,6 +14,7 @@ import io.opentelemetry.exporter.logging.otlp.OtlpJsonLoggingMetricExporter; import io.opentelemetry.exporter.logging.otlp.OtlpJsonLoggingSpanExporter; import io.opentelemetry.sdk.OpenTelemetrySdk; +import io.opentelemetry.sdk.autoconfigure.spi.internal.DefaultConfigProperties; import java.util.concurrent.TimeUnit; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.RegisterExtension; diff --git a/sdk-extensions/autoconfigure/src/testOtlp/java/io/opentelemetry/sdk/autoconfigure/OtlpGrpcConfigTest.java b/sdk-extensions/autoconfigure/src/testOtlp/java/io/opentelemetry/sdk/autoconfigure/OtlpGrpcConfigTest.java index cdc1e922d57..b5bbd792612 100644 --- a/sdk-extensions/autoconfigure/src/testOtlp/java/io/opentelemetry/sdk/autoconfigure/OtlpGrpcConfigTest.java +++ b/sdk-extensions/autoconfigure/src/testOtlp/java/io/opentelemetry/sdk/autoconfigure/OtlpGrpcConfigTest.java @@ -21,6 +21,7 @@ import io.opentelemetry.sdk.OpenTelemetrySdk; import io.opentelemetry.sdk.autoconfigure.spi.ConfigProperties; import io.opentelemetry.sdk.autoconfigure.spi.ConfigurationException; +import io.opentelemetry.sdk.autoconfigure.spi.internal.DefaultConfigProperties; import io.opentelemetry.sdk.logs.data.LogRecordData; import io.opentelemetry.sdk.logs.export.LogRecordExporter; import io.opentelemetry.sdk.metrics.InstrumentType; diff --git a/sdk-extensions/autoconfigure/src/testOtlp/java/io/opentelemetry/sdk/autoconfigure/OtlpGrpcRetryTest.java b/sdk-extensions/autoconfigure/src/testOtlp/java/io/opentelemetry/sdk/autoconfigure/OtlpGrpcRetryTest.java index d44c4c43ec4..731bf9a4a13 100644 --- a/sdk-extensions/autoconfigure/src/testOtlp/java/io/opentelemetry/sdk/autoconfigure/OtlpGrpcRetryTest.java +++ b/sdk-extensions/autoconfigure/src/testOtlp/java/io/opentelemetry/sdk/autoconfigure/OtlpGrpcRetryTest.java @@ -18,6 +18,7 @@ import io.opentelemetry.exporter.internal.retry.RetryPolicy; import io.opentelemetry.exporter.internal.retry.RetryUtil; import io.opentelemetry.internal.testing.slf4j.SuppressLogger; +import io.opentelemetry.sdk.autoconfigure.spi.internal.DefaultConfigProperties; import io.opentelemetry.sdk.common.CompletableResultCode; import io.opentelemetry.sdk.logs.data.LogRecordData; import io.opentelemetry.sdk.logs.export.LogRecordExporter; diff --git a/sdk-extensions/autoconfigure/src/testOtlp/java/io/opentelemetry/sdk/autoconfigure/OtlpHttpConfigTest.java b/sdk-extensions/autoconfigure/src/testOtlp/java/io/opentelemetry/sdk/autoconfigure/OtlpHttpConfigTest.java index e98f34ac945..f9f3bf66d4b 100644 --- a/sdk-extensions/autoconfigure/src/testOtlp/java/io/opentelemetry/sdk/autoconfigure/OtlpHttpConfigTest.java +++ b/sdk-extensions/autoconfigure/src/testOtlp/java/io/opentelemetry/sdk/autoconfigure/OtlpHttpConfigTest.java @@ -20,6 +20,7 @@ import io.opentelemetry.api.metrics.MeterProvider; import io.opentelemetry.sdk.autoconfigure.spi.ConfigProperties; import io.opentelemetry.sdk.autoconfigure.spi.ConfigurationException; +import io.opentelemetry.sdk.autoconfigure.spi.internal.DefaultConfigProperties; import io.opentelemetry.sdk.logs.export.LogRecordExporter; import io.opentelemetry.sdk.metrics.InstrumentType; import io.opentelemetry.sdk.metrics.data.AggregationTemporality; diff --git a/sdk-extensions/autoconfigure/src/testOtlp/java/io/opentelemetry/sdk/autoconfigure/OtlpHttpRetryTest.java b/sdk-extensions/autoconfigure/src/testOtlp/java/io/opentelemetry/sdk/autoconfigure/OtlpHttpRetryTest.java index 501824f1c91..08a23a07af1 100644 --- a/sdk-extensions/autoconfigure/src/testOtlp/java/io/opentelemetry/sdk/autoconfigure/OtlpHttpRetryTest.java +++ b/sdk-extensions/autoconfigure/src/testOtlp/java/io/opentelemetry/sdk/autoconfigure/OtlpHttpRetryTest.java @@ -19,6 +19,7 @@ import io.opentelemetry.exporter.internal.retry.RetryPolicy; import io.opentelemetry.exporter.internal.retry.RetryUtil; import io.opentelemetry.internal.testing.slf4j.SuppressLogger; +import io.opentelemetry.sdk.autoconfigure.spi.internal.DefaultConfigProperties; import io.opentelemetry.sdk.common.CompletableResultCode; import io.opentelemetry.sdk.logs.data.LogRecordData; import io.opentelemetry.sdk.logs.export.LogRecordExporter;