You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by mg...@apache.org on 2023/07/11 12:21:06 UTC

[camel] branch tryingToFixLeak updated: Removes the scope wrapper workaround + allows multiple scope closing

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

mgrzejszczak pushed a commit to branch tryingToFixLeak
in repository https://gitbox.apache.org/repos/asf/camel.git


The following commit(s) were added to refs/heads/tryingToFixLeak by this push:
     new f8342f2f187 Removes the scope wrapper workaround + allows multiple scope closing
f8342f2f187 is described below

commit f8342f2f1878ce8a4da3ba3b9d60168e0af02638
Author: Marcin Grzejszczak <mg...@vmware.com>
AuthorDate: Tue Jul 11 14:20:55 2023 +0200

    Removes the scope wrapper workaround + allows multiple scope closing
---
 .../src/test/resources/log4j2.properties           |  2 +-
 .../src/test/resources/log4j2.properties           |  2 +-
 .../apache/camel/tracing/ActiveSpanManager.java    | 54 ++++------------------
 .../main/java/org/apache/camel/tracing/Tracer.java |  2 +-
 4 files changed, 12 insertions(+), 48 deletions(-)

diff --git a/components/camel-observation/src/test/resources/log4j2.properties b/components/camel-observation/src/test/resources/log4j2.properties
index af1e7f203ab..e8f85339941 100644
--- a/components/camel-observation/src/test/resources/log4j2.properties
+++ b/components/camel-observation/src/test/resources/log4j2.properties
@@ -26,6 +26,6 @@ appender.out.layout.pattern=%d [%-15.15t] %-5p %-30.30c{1} - %m%n
 logger.opentelemetry.name=org.apache.camel.observation
 logger.opentelemetry.level=INFO
 logger.tracing.name=org.apache.camel.tracing
-logger.tracing.level=TRACE
+logger.tracing.level=INFO
 rootLogger.level=INFO
 rootLogger.appenderRef.file.ref=file
diff --git a/components/camel-opentelemetry/src/test/resources/log4j2.properties b/components/camel-opentelemetry/src/test/resources/log4j2.properties
index 7db0d5df3cb..08423f8d76e 100644
--- a/components/camel-opentelemetry/src/test/resources/log4j2.properties
+++ b/components/camel-opentelemetry/src/test/resources/log4j2.properties
@@ -26,6 +26,6 @@ appender.out.layout.pattern=%d [%-15.15t] %-5p %-30.30c{1} - %m%n
 logger.opentelemetry.name=org.apache.camel.opentelemetry
 logger.opentelemetry.level=INFO
 logger.tracing.name=org.apache.camel.tracing
-logger.tracing.level=TRACE
+logger.tracing.level=INFO
 rootLogger.level=INFO
 rootLogger.appenderRef.file.ref=file
diff --git a/components/camel-tracing/src/main/java/org/apache/camel/tracing/ActiveSpanManager.java b/components/camel-tracing/src/main/java/org/apache/camel/tracing/ActiveSpanManager.java
index 392d9880f9c..c6f6b188cab 100644
--- a/components/camel-tracing/src/main/java/org/apache/camel/tracing/ActiveSpanManager.java
+++ b/components/camel-tracing/src/main/java/org/apache/camel/tracing/ActiveSpanManager.java
@@ -119,7 +119,10 @@ public final class ActiveSpanManager {
         public Holder(Holder parent, SpanAdapter span) {
             this.parent = parent;
             this.span = span;
-            this.scope = new ScopeWrapper(span.makeCurrent(), Thread.currentThread().getId());
+            this.scope = span.makeCurrent();
+            if (LOG.isTraceEnabled()) {
+                LOG.trace("Tracing: started scope={}", this.scope);
+            }
         }
 
         public Holder getParent() {
@@ -131,52 +134,13 @@ public final class ActiveSpanManager {
         }
 
         private void closeScope() {
-            if (scope != null) {
-                try {
-                    scope.close();
-                } catch (Exception e) {
-                    LOG.debug("Failed to close span scope", e);
-                }
-                this.scope = null;
-            }
-        }
-    }
-
-    /**
-     * Makes closing scopes idempotent and prevents restoring scope on the wrong thread: Should be removed if
-     * https://github.com/open-telemetry/opentelemetry-java/issues/5055 is fixed.
-     */
-    private static class ScopeWrapper implements AutoCloseable {
-        private final long startThreadId;
-        private final AutoCloseable inner;
-        private boolean closed;
-
-        private Throwable exceptionForStacktrace;
-
-        public ScopeWrapper(AutoCloseable inner, long startThreadId) {
-            this.startThreadId = startThreadId;
-            this.inner = inner;
-            if (LOG.isTraceEnabled()) {
-                LOG.trace("Created scope {}", inner);
-                this.exceptionForStacktrace = new RuntimeException("To see where this scope got created");
-            }
-        }
-
-        @Override
-        public void close() throws Exception {
-            if (!closed && Thread.currentThread().getId() == startThreadId) {
-                closed = true;
+            try {
                 if (LOG.isTraceEnabled()) {
-                    LOG.trace("Closing scope {}", inner);
-                }
-                inner.close();
-            } else {
-                LOG.debug("not closing scope, closed - {}, started on thread - '{}', current thread - '{}'",
-                        closed, startThreadId, Thread.currentThread().getId());
-                if (LOG.isTraceEnabled() && this.exceptionForStacktrace != null) {
-                    LOG.trace("Stacktrace of where we are", new RuntimeException());
-                    LOG.trace("Stacktrace of where the scope was created", this.exceptionForStacktrace);
+                    LOG.trace("Tracing: closing scope={}", this.scope);
                 }
+                scope.close();
+            } catch (Exception e) {
+                LOG.debug("Failed to close span scope", e);
             }
         }
     }
diff --git a/components/camel-tracing/src/main/java/org/apache/camel/tracing/Tracer.java b/components/camel-tracing/src/main/java/org/apache/camel/tracing/Tracer.java
index 7853762fec6..1b9c5297112 100644
--- a/components/camel-tracing/src/main/java/org/apache/camel/tracing/Tracer.java
+++ b/components/camel-tracing/src/main/java/org/apache/camel/tracing/Tracer.java
@@ -273,7 +273,7 @@ public abstract class Tracer extends ServiceSupport implements RoutePolicyFactor
                     SpanAdapter span = ActiveSpanManager.getSpan(ese.getExchange());
                     if (span != null) {
                         if (LOG.isTraceEnabled()) {
-                            LOG.trace("Tracing: start client span={}", span);
+                            LOG.trace("Tracing: stop client span={}", span);
                         }
                         sd.post(span, ese.getExchange(), ese.getEndpoint());
                         ActiveSpanManager.deactivate(ese.getExchange());