This is an automated email from the ASF dual-hosted git repository.

rzo1 pushed a commit to branch TOMEE-4343
in repository https://gitbox.apache.org/repos/asf/tomee.git


The following commit(s) were added to refs/heads/TOMEE-4343 by this push:
     new bbb4d6f0b9 TOMEE-4343 - WIP: OpenTelemetry 1.0
bbb4d6f0b9 is described below

commit bbb4d6f0b97c089b40edddacc0b75ee9797d4b3f
Author: Richard Zowalla <[email protected]>
AuthorDate: Fri May 31 11:15:13 2024 +0200

    TOMEE-4343 - WIP: OpenTelemetry 1.0
---
 boms/tomee-microprofile/pom.xml                    |  11 ++
 boms/tomee-plume/pom.xml                           |  11 ++
 boms/tomee-plus/pom.xml                            |  11 ++
 tomee/tomee-microprofile/mp-common/pom.xml         |  16 ++
 .../microprofile/TomEEMicroProfileListener.java    |   1 -
 .../opentelemetry/MPOpenTelemetryCDIExtension.java | 164 +++++++++++++++++++++
 .../opentelemetry/WithSpanInterceptorProducer.java |  19 +++
 .../META-INF/openwebbeans/openwebbeans.properties  |  20 +++
 .../jakarta.enterprise.inject.spi.Extension        |   2 +-
 9 files changed, 253 insertions(+), 2 deletions(-)

diff --git a/boms/tomee-microprofile/pom.xml b/boms/tomee-microprofile/pom.xml
index 10e0ff2c9c..b0781cd51f 100644
--- a/boms/tomee-microprofile/pom.xml
+++ b/boms/tomee-microprofile/pom.xml
@@ -639,6 +639,17 @@
         </exclusion>
       </exclusions>
     </dependency>
+    <dependency>
+      <groupId>io.smallrye.opentelemetry</groupId>
+      <artifactId>smallrye-opentelemetry-config</artifactId>
+      <version>2.6.0</version>
+      <exclusions>
+        <exclusion>
+          <artifactId>*</artifactId>
+          <groupId>*</groupId>
+        </exclusion>
+      </exclusions>
+    </dependency>
     <dependency>
       <groupId>io.smallrye.opentelemetry</groupId>
       <artifactId>smallrye-opentelemetry-rest</artifactId>
diff --git a/boms/tomee-plume/pom.xml b/boms/tomee-plume/pom.xml
index 87c58c84bf..92eda34a2a 100644
--- a/boms/tomee-plume/pom.xml
+++ b/boms/tomee-plume/pom.xml
@@ -639,6 +639,17 @@
         </exclusion>
       </exclusions>
     </dependency>
+    <dependency>
+      <groupId>io.smallrye.opentelemetry</groupId>
+      <artifactId>smallrye-opentelemetry-config</artifactId>
+      <version>2.6.0</version>
+      <exclusions>
+        <exclusion>
+          <artifactId>*</artifactId>
+          <groupId>*</groupId>
+        </exclusion>
+      </exclusions>
+    </dependency>
     <dependency>
       <groupId>io.smallrye.opentelemetry</groupId>
       <artifactId>smallrye-opentelemetry-rest</artifactId>
diff --git a/boms/tomee-plus/pom.xml b/boms/tomee-plus/pom.xml
index e4a20da98e..a436441627 100644
--- a/boms/tomee-plus/pom.xml
+++ b/boms/tomee-plus/pom.xml
@@ -639,6 +639,17 @@
         </exclusion>
       </exclusions>
     </dependency>
+    <dependency>
+      <groupId>io.smallrye.opentelemetry</groupId>
+      <artifactId>smallrye-opentelemetry-config</artifactId>
+      <version>2.6.0</version>
+      <exclusions>
+        <exclusion>
+          <artifactId>*</artifactId>
+          <groupId>*</groupId>
+        </exclusion>
+      </exclusions>
+    </dependency>
     <dependency>
       <groupId>io.smallrye.opentelemetry</groupId>
       <artifactId>smallrye-opentelemetry-rest</artifactId>
diff --git a/tomee/tomee-microprofile/mp-common/pom.xml 
b/tomee/tomee-microprofile/mp-common/pom.xml
index 21f05dae32..ea06788b11 100644
--- a/tomee/tomee-microprofile/mp-common/pom.xml
+++ b/tomee/tomee-microprofile/mp-common/pom.xml
@@ -327,6 +327,22 @@
       </exclusions>
     </dependency>
 
+    <dependency>
+      <groupId>io.smallrye.opentelemetry</groupId>
+      <artifactId>smallrye-opentelemetry-config</artifactId>
+      <version>${version.microprofile.impl.opentelemetry}</version>
+      <exclusions>
+        <exclusion>
+          <groupId>jakarta.enterprise</groupId>
+          <artifactId>jakarta.enterprise.cdi-api</artifactId>
+        </exclusion>
+        <exclusion>
+          <groupId>jakarta.ws.rs</groupId>
+          <artifactId>jakarta.ws.rs-api</artifactId>
+        </exclusion>
+      </exclusions>
+    </dependency>
+
     <!-- Jackson and snakeyaml required by OpenAPI Impl -->
     <dependency>
       <groupId>com.fasterxml.jackson.dataformat</groupId>
diff --git 
a/tomee/tomee-microprofile/mp-common/src/main/java/org/apache/tomee/microprofile/TomEEMicroProfileListener.java
 
b/tomee/tomee-microprofile/mp-common/src/main/java/org/apache/tomee/microprofile/TomEEMicroProfileListener.java
index 1e685c5ab1..9f7f3b04b5 100644
--- 
a/tomee/tomee-microprofile/mp-common/src/main/java/org/apache/tomee/microprofile/TomEEMicroProfileListener.java
+++ 
b/tomee/tomee-microprofile/mp-common/src/main/java/org/apache/tomee/microprofile/TomEEMicroProfileListener.java
@@ -64,7 +64,6 @@ public class TomEEMicroProfileListener {
         "io.smallrye.opentracing.SmallRyeTracingDynamicFeature",
         "io.smallrye.opentracing.contrib.interceptor.OpenTracingInterceptor",
         "io.smallrye.faulttolerance.FaultToleranceExtension",
-        "io.smallrye.opentelemetry.implementation.cdi.OpenTelemetryExtension",
         };
 
     public void enhanceScannableUrls(@Observes final EnhanceScannableUrlsEvent 
enhanceScannableUrlsEvent) {
diff --git 
a/tomee/tomee-microprofile/mp-common/src/main/java/org/apache/tomee/microprofile/opentelemetry/MPOpenTelemetryCDIExtension.java
 
b/tomee/tomee-microprofile/mp-common/src/main/java/org/apache/tomee/microprofile/opentelemetry/MPOpenTelemetryCDIExtension.java
new file mode 100644
index 0000000000..522561bb1e
--- /dev/null
+++ 
b/tomee/tomee-microprofile/mp-common/src/main/java/org/apache/tomee/microprofile/opentelemetry/MPOpenTelemetryCDIExtension.java
@@ -0,0 +1,164 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.tomee.microprofile.opentelemetry;
+
+import java.lang.annotation.Annotation;
+import java.lang.reflect.Method;
+import java.lang.reflect.Type;
+import java.util.Collections;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Set;
+
+import io.opentelemetry.instrumentation.annotations.WithSpan;
+import io.smallrye.opentelemetry.implementation.cdi.OpenTelemetryProducer;
+import 
io.smallrye.opentelemetry.implementation.config.OpenTelemetryConfigProducer;
+import jakarta.enterprise.event.Observes;
+import jakarta.enterprise.inject.spi.AnnotatedConstructor;
+import jakarta.enterprise.inject.spi.AnnotatedField;
+import jakarta.enterprise.inject.spi.AnnotatedMethod;
+import jakarta.enterprise.inject.spi.AnnotatedParameter;
+import jakarta.enterprise.inject.spi.AnnotatedType;
+import jakarta.enterprise.inject.spi.BeanManager;
+import jakarta.enterprise.inject.spi.BeforeBeanDiscovery;
+import jakarta.enterprise.inject.spi.Extension;
+import jakarta.enterprise.util.Nonbinding;
+
+public class MPOpenTelemetryCDIExtension implements Extension {
+
+    public void beforeBeanDiscovery(@Observes BeforeBeanDiscovery 
beforeBeanDiscovery, BeanManager beanManager) {
+        beforeBeanDiscovery.addInterceptorBinding(
+            new 
MPOpenTelemetryCDIExtension.WithSpanAnnotatedType(beanManager.createAnnotatedType(WithSpan.class)));
+
+        
beforeBeanDiscovery.addAnnotatedType(beanManager.createAnnotatedType(OpenTelemetryProducer.class),
 "OpenTelemetryProducer");
+        
beforeBeanDiscovery.addAnnotatedType(beanManager.createAnnotatedType(WithSpanInterceptorProducer.class),
 "WithSpanInterceptorProducer");
+        
beforeBeanDiscovery.addAnnotatedType(beanManager.createAnnotatedType(OpenTelemetryConfigProducer.class),
 "OpenTelemetryConfigProducer");
+
+    }
+
+    // To add Nonbinding to @WithSpan members
+    @SuppressWarnings("unchecked")
+    static class WithSpanAnnotatedType implements AnnotatedType<WithSpan> {
+        private final AnnotatedType<WithSpan> delegate;
+        private final Set<AnnotatedMethod<? super WithSpan>> methods;
+
+        WithSpanAnnotatedType(final AnnotatedType<WithSpan> delegate) {
+            this.delegate = delegate;
+            this.methods = new HashSet<>();
+
+            for (AnnotatedMethod<? super WithSpan> method : 
delegate.getMethods()) {
+                methods.add(new AnnotatedMethod<WithSpan>() {
+                    private final AnnotatedMethod<WithSpan> delegate = 
(AnnotatedMethod<WithSpan>) method;
+                    private final Set<Annotation> annotations = 
Collections.singleton(Nonbinding.Literal.INSTANCE);
+
+                    @Override
+                    public Method getJavaMember() {
+                        return delegate.getJavaMember();
+                    }
+
+                    @Override
+                    public List<AnnotatedParameter<WithSpan>> getParameters() {
+                        return delegate.getParameters();
+                    }
+
+                    @Override
+                    public boolean isStatic() {
+                        return delegate.isStatic();
+                    }
+
+                    @Override
+                    public AnnotatedType<WithSpan> getDeclaringType() {
+                        return delegate.getDeclaringType();
+                    }
+
+                    @Override
+                    public Type getBaseType() {
+                        return delegate.getBaseType();
+                    }
+
+                    @Override
+                    public Set<Type> getTypeClosure() {
+                        return delegate.getTypeClosure();
+                    }
+
+                    @Override
+                    public <T extends Annotation> T getAnnotation(final 
Class<T> annotationType) {
+                        if (annotationType.equals(Nonbinding.class)) {
+                            return (T) annotations.iterator().next();
+                        }
+                        return null;
+                    }
+
+                    @Override
+                    public Set<Annotation> getAnnotations() {
+                        return annotations;
+                    }
+
+                    @Override
+                    public boolean isAnnotationPresent(final Class<? extends 
Annotation> annotationType) {
+                        return annotationType.equals(Nonbinding.class);
+                    }
+                });
+            }
+        }
+
+        @Override
+        public Class<WithSpan> getJavaClass() {
+            return delegate.getJavaClass();
+        }
+
+        @Override
+        public Set<AnnotatedConstructor<WithSpan>> getConstructors() {
+            return delegate.getConstructors();
+        }
+
+        @Override
+        public Set<AnnotatedMethod<? super WithSpan>> getMethods() {
+            return this.methods;
+        }
+
+        @Override
+        public Set<AnnotatedField<? super WithSpan>> getFields() {
+            return delegate.getFields();
+        }
+
+        @Override
+        public Type getBaseType() {
+            return delegate.getBaseType();
+        }
+
+        @Override
+        public Set<Type> getTypeClosure() {
+            return delegate.getTypeClosure();
+        }
+
+        @Override
+        public <T extends Annotation> T getAnnotation(final Class<T> 
annotationType) {
+            return delegate.getAnnotation(annotationType);
+        }
+
+        @Override
+        public Set<Annotation> getAnnotations() {
+            return delegate.getAnnotations();
+        }
+
+        @Override
+        public boolean isAnnotationPresent(final Class<? extends Annotation> 
annotationType) {
+            return delegate.isAnnotationPresent(annotationType);
+        }
+    }
+}
\ No newline at end of file
diff --git 
a/tomee/tomee-microprofile/mp-common/src/main/java/org/apache/tomee/microprofile/opentelemetry/WithSpanInterceptorProducer.java
 
b/tomee/tomee-microprofile/mp-common/src/main/java/org/apache/tomee/microprofile/opentelemetry/WithSpanInterceptorProducer.java
new file mode 100644
index 0000000000..13fdc95dd0
--- /dev/null
+++ 
b/tomee/tomee-microprofile/mp-common/src/main/java/org/apache/tomee/microprofile/opentelemetry/WithSpanInterceptorProducer.java
@@ -0,0 +1,19 @@
+package org.apache.tomee.microprofile.opentelemetry;
+
+import io.smallrye.opentelemetry.implementation.cdi.WithSpanInterceptorBean;
+import jakarta.enterprise.context.ApplicationScoped;
+import jakarta.enterprise.inject.Produces;
+import jakarta.enterprise.inject.spi.BeanManager;
+import jakarta.inject.Inject;
+
+@ApplicationScoped
+public class WithSpanInterceptorProducer {
+
+    @Inject
+    private BeanManager beanManager;
+
+    @Produces
+    public WithSpanInterceptorBean createWithSpanInterceptorBean() {
+        return new WithSpanInterceptorBean(beanManager); //This is a hack as 
the actual interceptor bean from Smallrye has no default constructor breaking 
OWB.
+    }
+}
\ No newline at end of file
diff --git 
a/tomee/tomee-microprofile/mp-common/src/main/resources/META-INF/openwebbeans/openwebbeans.properties
 
b/tomee/tomee-microprofile/mp-common/src/main/resources/META-INF/openwebbeans/openwebbeans.properties
new file mode 100644
index 0000000000..c8770a9761
--- /dev/null
+++ 
b/tomee/tomee-microprofile/mp-common/src/main/resources/META-INF/openwebbeans/openwebbeans.properties
@@ -0,0 +1,20 @@
+#
+# Licensed to the Apache Software Foundation (ASF) under one or more
+# contributor license agreements.  See the NOTICE file distributed with
+# this work for additional information regarding copyright ownership.
+# The ASF licenses this file to You under the Apache License, Version 2.0
+# (the "License"); you may not use this file except in compliance with
+# the License.  You may obtain a copy of the License at
+#
+#     http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+configuration.ordinal=75
+
+# exclude this extension from being loaded as we need to workaround a smallrye 
bean with no default constructor
+org.apache.webbeans.ignoredExtensions=io.smallrye.opentelemetry.implementation.cdi.OpenTelemetryExtension
diff --git 
a/tomee/tomee-microprofile/mp-common/src/main/resources/META-INF/services/jakarta.enterprise.inject.spi.Extension
 
b/tomee/tomee-microprofile/mp-common/src/main/resources/META-INF/services/jakarta.enterprise.inject.spi.Extension
index f8e0f665f8..ff200bd024 100644
--- 
a/tomee/tomee-microprofile/mp-common/src/main/resources/META-INF/services/jakarta.enterprise.inject.spi.Extension
+++ 
b/tomee/tomee-microprofile/mp-common/src/main/resources/META-INF/services/jakarta.enterprise.inject.spi.Extension
@@ -1,5 +1,5 @@
 org.apache.tomee.microprofile.health.MPHealthCDIExtension
-org.apache.tomee.microprofile.metrics.MPMetricsCDIExtension
+org.apache.tomee.microprofile.opentelemetry.MPOpenTelemetryCDIExtension
 org.apache.tomee.microprofile.opentracing.MPOpenTracingCDIExtension
 org.apache.tomee.microprofile.faulttolerance.MPFaultToleranceCDIExtension
 

Reply via email to