From f76d812036f1e2ce3ca12d0bb5465e09bfa28212 Mon Sep 17 00:00:00 2001 From: brunobat Date: Fri, 22 Mar 2024 17:11:21 +0000 Subject: [PATCH] Revert EndUserSpanProcessor integration --- docs/src/main/asciidoc/opentelemetry.adoc | 4 - .../exporter/otlp/OtlpExporterProcessor.java | 13 --- .../build/EndUserSpanProcessorConfig.java | 24 ------ .../config/build/TracesBuildConfig.java | 5 -- .../exporter/otlp/EndUserSpanProcessor.java | 54 ------------ .../it/opentelemetry/AbstractEndUserTest.java | 83 ------------------- .../it/opentelemetry/EndUserDisabledTest.java | 23 ----- .../it/opentelemetry/EndUserEnabledTest.java | 26 ------ .../it/opentelemetry/util/EndUserProfile.java | 15 ---- .../opentelemetry/util/EndUserResource.java | 17 ---- 10 files changed, 264 deletions(-) delete mode 100644 extensions/opentelemetry/runtime/src/main/java/io/quarkus/opentelemetry/runtime/config/build/EndUserSpanProcessorConfig.java delete mode 100644 extensions/opentelemetry/runtime/src/main/java/io/quarkus/opentelemetry/runtime/exporter/otlp/EndUserSpanProcessor.java delete mode 100644 integration-tests/opentelemetry/src/test/java/io/quarkus/it/opentelemetry/AbstractEndUserTest.java delete mode 100644 integration-tests/opentelemetry/src/test/java/io/quarkus/it/opentelemetry/EndUserDisabledTest.java delete mode 100644 integration-tests/opentelemetry/src/test/java/io/quarkus/it/opentelemetry/EndUserEnabledTest.java delete mode 100644 integration-tests/opentelemetry/src/test/java/io/quarkus/it/opentelemetry/util/EndUserProfile.java delete mode 100644 integration-tests/opentelemetry/src/test/java/io/quarkus/it/opentelemetry/util/EndUserResource.java diff --git a/docs/src/main/asciidoc/opentelemetry.adoc b/docs/src/main/asciidoc/opentelemetry.adoc index 2a621b0c5c14f..9e565536d89f8 100644 --- a/docs/src/main/asciidoc/opentelemetry.adoc +++ b/docs/src/main/asciidoc/opentelemetry.adoc @@ -382,10 +382,6 @@ public class CustomConfiguration { } ---- -==== User data - -By setting `quarkus.otel.traces.eusp.enabled=true` you can add information about the user related to each span. The user's ID and roles will be added to the span attributes, if available. - [[sampler]] === Sampler A https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/trace/sdk.md#sampling[sampler] decides whether a trace should be discarded or forwarded, effectively managing noise and reducing overhead by limiting the number of collected traces sent to the collector. diff --git a/extensions/opentelemetry/deployment/src/main/java/io/quarkus/opentelemetry/deployment/exporter/otlp/OtlpExporterProcessor.java b/extensions/opentelemetry/deployment/src/main/java/io/quarkus/opentelemetry/deployment/exporter/otlp/OtlpExporterProcessor.java index 8d2d594d3ca44..40f6af76b8930 100644 --- a/extensions/opentelemetry/deployment/src/main/java/io/quarkus/opentelemetry/deployment/exporter/otlp/OtlpExporterProcessor.java +++ b/extensions/opentelemetry/deployment/src/main/java/io/quarkus/opentelemetry/deployment/exporter/otlp/OtlpExporterProcessor.java @@ -15,7 +15,6 @@ import io.opentelemetry.sdk.trace.SpanProcessor; import io.opentelemetry.sdk.trace.export.SpanExporter; -import io.quarkus.arc.deployment.AdditionalBeanBuildItem; import io.quarkus.arc.deployment.SyntheticBeanBuildItem; import io.quarkus.deployment.annotations.BuildProducer; import io.quarkus.deployment.annotations.BuildStep; @@ -26,7 +25,6 @@ import io.quarkus.opentelemetry.runtime.config.build.exporter.OtlpExporterBuildConfig; import io.quarkus.opentelemetry.runtime.config.runtime.OTelRuntimeConfig; import io.quarkus.opentelemetry.runtime.config.runtime.exporter.OtlpExporterRuntimeConfig; -import io.quarkus.opentelemetry.runtime.exporter.otlp.EndUserSpanProcessor; import io.quarkus.opentelemetry.runtime.exporter.otlp.LateBoundBatchSpanProcessor; import io.quarkus.opentelemetry.runtime.exporter.otlp.OTelExporterRecorder; import io.quarkus.runtime.TlsConfig; @@ -47,17 +45,6 @@ public boolean getAsBoolean() { } } - @BuildStep - void createEndUserSpanProcessor( - BuildProducer buildProducer, - OTelBuildConfig otelBuildConfig) { - if (otelBuildConfig.traces().eusp().enabled().orElse(Boolean.FALSE)) { - buildProducer.produce( - AdditionalBeanBuildItem.unremovableOf( - EndUserSpanProcessor.class)); - } - } - @SuppressWarnings("deprecation") @BuildStep @Record(ExecutionTime.RUNTIME_INIT) diff --git a/extensions/opentelemetry/runtime/src/main/java/io/quarkus/opentelemetry/runtime/config/build/EndUserSpanProcessorConfig.java b/extensions/opentelemetry/runtime/src/main/java/io/quarkus/opentelemetry/runtime/config/build/EndUserSpanProcessorConfig.java deleted file mode 100644 index 2e261c0d3e89b..0000000000000 --- a/extensions/opentelemetry/runtime/src/main/java/io/quarkus/opentelemetry/runtime/config/build/EndUserSpanProcessorConfig.java +++ /dev/null @@ -1,24 +0,0 @@ -package io.quarkus.opentelemetry.runtime.config.build; - -import java.util.Optional; - -import io.quarkus.runtime.annotations.ConfigGroup; -import io.smallrye.config.WithDefault; - -/** - * Tracing build time configuration - */ -@ConfigGroup -public interface EndUserSpanProcessorConfig { - - /** - * Enable the {@link io.quarkus.opentelemetry.runtime.exporter.otlp.EndUserSpanProcessor}. - *

- * The {@link io.quarkus.opentelemetry.runtime.exporter.otlp.EndUserSpanProcessor} adds - * the {@link io.opentelemetry.semconv.SemanticAttributes.ENDUSER_ID} - * and {@link io.opentelemetry.semconv.SemanticAttributes.ENDUSER_ROLE} to the Span. - */ - @WithDefault("false") - Optional enabled(); - -} diff --git a/extensions/opentelemetry/runtime/src/main/java/io/quarkus/opentelemetry/runtime/config/build/TracesBuildConfig.java b/extensions/opentelemetry/runtime/src/main/java/io/quarkus/opentelemetry/runtime/config/build/TracesBuildConfig.java index 2bbe78e10fbf1..1c53611a14f1a 100644 --- a/extensions/opentelemetry/runtime/src/main/java/io/quarkus/opentelemetry/runtime/config/build/TracesBuildConfig.java +++ b/extensions/opentelemetry/runtime/src/main/java/io/quarkus/opentelemetry/runtime/config/build/TracesBuildConfig.java @@ -51,9 +51,4 @@ public interface TracesBuildConfig { */ @WithDefault(SamplerType.Constants.PARENT_BASED_ALWAYS_ON) String sampler(); - - /** - * EndUser SpanProcessor configurations. - */ - EndUserSpanProcessorConfig eusp(); } diff --git a/extensions/opentelemetry/runtime/src/main/java/io/quarkus/opentelemetry/runtime/exporter/otlp/EndUserSpanProcessor.java b/extensions/opentelemetry/runtime/src/main/java/io/quarkus/opentelemetry/runtime/exporter/otlp/EndUserSpanProcessor.java deleted file mode 100644 index a17cff566afd3..0000000000000 --- a/extensions/opentelemetry/runtime/src/main/java/io/quarkus/opentelemetry/runtime/exporter/otlp/EndUserSpanProcessor.java +++ /dev/null @@ -1,54 +0,0 @@ -package io.quarkus.opentelemetry.runtime.exporter.otlp; - -import jakarta.enterprise.context.ApplicationScoped; -import jakarta.enterprise.context.control.ActivateRequestContext; -import jakarta.inject.Inject; - -import org.eclipse.microprofile.context.ManagedExecutor; - -import io.opentelemetry.api.common.Attributes; -import io.opentelemetry.context.Context; -import io.opentelemetry.sdk.trace.ReadWriteSpan; -import io.opentelemetry.sdk.trace.ReadableSpan; -import io.opentelemetry.sdk.trace.SpanProcessor; -import io.opentelemetry.semconv.SemanticAttributes; -import io.quarkus.security.identity.SecurityIdentity; - -@ApplicationScoped -public class EndUserSpanProcessor implements SpanProcessor { - - @Inject - protected SecurityIdentity securityIdentity; - - @Inject - protected ManagedExecutor managedExecutor; - - @Override - @ActivateRequestContext - public void onStart(Context parentContext, ReadWriteSpan span) { - managedExecutor.execute( - () -> span.setAllAttributes( - securityIdentity.isAnonymous() - ? Attributes.empty() - : Attributes.of( - SemanticAttributes.ENDUSER_ID, - securityIdentity.getPrincipal().getName(), - SemanticAttributes.ENDUSER_ROLE, - securityIdentity.getRoles().toString()))); - } - - @Override - public boolean isStartRequired() { - return Boolean.TRUE; - } - - @Override - public void onEnd(ReadableSpan span) { - } - - @Override - public boolean isEndRequired() { - return Boolean.FALSE; - } - -} diff --git a/integration-tests/opentelemetry/src/test/java/io/quarkus/it/opentelemetry/AbstractEndUserTest.java b/integration-tests/opentelemetry/src/test/java/io/quarkus/it/opentelemetry/AbstractEndUserTest.java deleted file mode 100644 index 410188105c27d..0000000000000 --- a/integration-tests/opentelemetry/src/test/java/io/quarkus/it/opentelemetry/AbstractEndUserTest.java +++ /dev/null @@ -1,83 +0,0 @@ -package io.quarkus.it.opentelemetry; - -import static io.restassured.RestAssured.given; -import static java.util.concurrent.TimeUnit.SECONDS; -import static org.awaitility.Awaitility.await; -import static org.junit.jupiter.api.Assertions.assertTrue; - -import java.util.List; -import java.util.Optional; -import java.util.concurrent.TimeUnit; -import java.util.function.Predicate; -import java.util.stream.Collectors; - -import jakarta.enterprise.inject.Instance; -import jakarta.inject.Inject; - -import org.junit.jupiter.api.AfterEach; -import org.junit.jupiter.api.BeforeEach; -import org.junit.jupiter.api.Test; - -import io.opentelemetry.api.common.Attributes; -import io.opentelemetry.sdk.testing.exporter.InMemorySpanExporter; -import io.opentelemetry.sdk.trace.data.SpanData; -import io.quarkus.it.opentelemetry.util.EndUserResource; -import io.quarkus.opentelemetry.runtime.exporter.otlp.EndUserSpanProcessor; -import io.quarkus.test.common.http.TestHTTPEndpoint; -import io.quarkus.test.security.TestSecurity; - -@TestHTTPEndpoint(EndUserResource.class) -@TestSecurity(user = "testUser", roles = { "admin", "user" }) -public abstract class AbstractEndUserTest { - - @Inject - InMemorySpanExporter inMemorySpanExporter; - - @Inject - Instance endUserSpanProcessor; - - protected final Predicate> injectionPredicate; - - public AbstractEndUserTest(Predicate> predicate) { - this.injectionPredicate = predicate; - } - - @BeforeEach - @AfterEach - protected void reset() { - await().atMost(5, TimeUnit.SECONDS).until(() -> { - // make sure spans from previous tests are not included - List finishedSpanItems = inMemorySpanExporter.getFinishedSpanItems(); - if (finishedSpanItems.size() > 0) { - inMemorySpanExporter.reset(); - } - return finishedSpanItems.size() == 0; - }); - } - - protected List getSpansName(final String spanName) { - return inMemorySpanExporter.getFinishedSpanItems().stream() - .filter(span -> spanName.equals(span.getName())) - .collect(Collectors.toList()); - } - - protected abstract void evaluateAttributes(Attributes attributes); - - @Test - protected void baseTest() { - assertTrue(this.injectionPredicate.test(endUserSpanProcessor)); - - given() - .when().get() - .then() - .statusCode(200); - - final String spanName = "GET /otel/enduser"; - await().atMost(5, SECONDS).until(() -> getSpansName(spanName).size() > 0); - Optional spanData = getSpansName(spanName).stream().findFirst(); - - assertTrue(spanData.isPresent(), "Span not found for " + spanName); - evaluateAttributes(spanData.get().getAttributes()); - } - -} diff --git a/integration-tests/opentelemetry/src/test/java/io/quarkus/it/opentelemetry/EndUserDisabledTest.java b/integration-tests/opentelemetry/src/test/java/io/quarkus/it/opentelemetry/EndUserDisabledTest.java deleted file mode 100644 index 8fee9dcd3a0ba..0000000000000 --- a/integration-tests/opentelemetry/src/test/java/io/quarkus/it/opentelemetry/EndUserDisabledTest.java +++ /dev/null @@ -1,23 +0,0 @@ -package io.quarkus.it.opentelemetry; - -import static org.junit.jupiter.api.Assertions.assertNull; - -import jakarta.enterprise.inject.Instance; - -import io.opentelemetry.api.common.Attributes; -import io.opentelemetry.semconv.SemanticAttributes; -import io.quarkus.test.junit.QuarkusTest; - -@QuarkusTest -public class EndUserDisabledTest extends AbstractEndUserTest { - - public EndUserDisabledTest() { - super(Instance::isUnsatisfied); - } - - @Override - protected void evaluateAttributes(Attributes attributes) { - assertNull(attributes.get(SemanticAttributes.ENDUSER_ID)); - assertNull(attributes.get(SemanticAttributes.ENDUSER_ROLE)); - } -} diff --git a/integration-tests/opentelemetry/src/test/java/io/quarkus/it/opentelemetry/EndUserEnabledTest.java b/integration-tests/opentelemetry/src/test/java/io/quarkus/it/opentelemetry/EndUserEnabledTest.java deleted file mode 100644 index 30f3bd7d1877e..0000000000000 --- a/integration-tests/opentelemetry/src/test/java/io/quarkus/it/opentelemetry/EndUserEnabledTest.java +++ /dev/null @@ -1,26 +0,0 @@ -package io.quarkus.it.opentelemetry; - -import static org.junit.jupiter.api.Assertions.assertEquals; - -import jakarta.enterprise.inject.Instance; - -import io.opentelemetry.api.common.Attributes; -import io.opentelemetry.semconv.SemanticAttributes; -import io.quarkus.it.opentelemetry.util.EndUserProfile; -import io.quarkus.test.junit.QuarkusTest; -import io.quarkus.test.junit.TestProfile; - -@QuarkusTest -@TestProfile(EndUserProfile.class) -public class EndUserEnabledTest extends AbstractEndUserTest { - - public EndUserEnabledTest() { - super(Instance::isResolvable); - } - - @Override - protected void evaluateAttributes(Attributes attributes) { - assertEquals("testUser", attributes.get(SemanticAttributes.ENDUSER_ID), attributes.toString()); - assertEquals("[admin, user]", attributes.get(SemanticAttributes.ENDUSER_ROLE), attributes.toString()); - } -} diff --git a/integration-tests/opentelemetry/src/test/java/io/quarkus/it/opentelemetry/util/EndUserProfile.java b/integration-tests/opentelemetry/src/test/java/io/quarkus/it/opentelemetry/util/EndUserProfile.java deleted file mode 100644 index f0962667964b3..0000000000000 --- a/integration-tests/opentelemetry/src/test/java/io/quarkus/it/opentelemetry/util/EndUserProfile.java +++ /dev/null @@ -1,15 +0,0 @@ -package io.quarkus.it.opentelemetry.util; - -import java.util.Map; - -import io.quarkus.test.junit.QuarkusTestProfile; - -public class EndUserProfile implements QuarkusTestProfile { - - @Override - public Map getConfigOverrides() { - return Map.of( - "quarkus.otel.traces.eusp.enabled", "true"); - } - -} diff --git a/integration-tests/opentelemetry/src/test/java/io/quarkus/it/opentelemetry/util/EndUserResource.java b/integration-tests/opentelemetry/src/test/java/io/quarkus/it/opentelemetry/util/EndUserResource.java deleted file mode 100644 index 490012212d6d9..0000000000000 --- a/integration-tests/opentelemetry/src/test/java/io/quarkus/it/opentelemetry/util/EndUserResource.java +++ /dev/null @@ -1,17 +0,0 @@ -package io.quarkus.it.opentelemetry.util; - -import jakarta.enterprise.context.RequestScoped; -import jakarta.ws.rs.GET; -import jakarta.ws.rs.Path; -import jakarta.ws.rs.core.Response; - -@Path("/otel/enduser") -@RequestScoped -public class EndUserResource { - - @GET - public Response dummy() { - return Response.ok().build(); - } - -}