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

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


The following commit(s) were added to refs/heads/main by this push:
     new 6476a71ede1 Add `ExchangePropertyKey` for active tracing span property 
(#15241)
6476a71ede1 is described below

commit 6476a71ede16274a4c43796fa4a6a25f3c481d08
Author: Adriano Machado <[email protected]>
AuthorDate: Wed Aug 21 10:27:11 2024 -0400

    Add `ExchangePropertyKey` for active tracing span property (#15241)
    
    * Add `ExchangePropertyKey` for active tracing span property
    
    * Adding missing file from previous commit
---
 .../apache/camel/tracing/ActiveSpanManager.java    | 14 ++++++-------
 .../org/apache/camel/ExchangeConstantProvider.java |  3 ++-
 .../src/main/java/org/apache/camel/Exchange.java   | 23 +++++++++++-----------
 .../java/org/apache/camel/ExchangePropertyKey.java |  1 +
 .../apache/camel/saga/InMemorySagaCoordinator.java |  7 +++----
 5 files changed, 25 insertions(+), 23 deletions(-)

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 5ce1ebf72ab..92dc551619f 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
@@ -17,6 +17,7 @@
 package org.apache.camel.tracing;
 
 import org.apache.camel.Exchange;
+import org.apache.camel.ExchangePropertyKey;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 import org.slf4j.MDC;
@@ -28,7 +29,6 @@ public final class ActiveSpanManager {
 
     public static final String MDC_TRACE_ID = "trace_id";
     public static final String MDC_SPAN_ID = "span_id";
-    private static final String ACTIVE_SPAN_PROPERTY = 
"OpenTracing.activeSpan";
     private static final Logger LOG = 
LoggerFactory.getLogger(ActiveSpanManager.class);
 
     private ActiveSpanManager() {
@@ -41,7 +41,7 @@ public final class ActiveSpanManager {
      * @return          The current active span, or null if none exists
      */
     public static SpanAdapter getSpan(Exchange exchange) {
-        Holder holder = exchange.getProperty(ACTIVE_SPAN_PROPERTY, 
Holder.class);
+        Holder holder = exchange.getProperty(ExchangePropertyKey.ACTIVE_SPAN, 
Holder.class);
         if (holder != null) {
             return holder.getSpan();
         }
@@ -56,8 +56,8 @@ public final class ActiveSpanManager {
      * @param span     The span
      */
     public static void activate(Exchange exchange, SpanAdapter span) {
-        exchange.setProperty(ACTIVE_SPAN_PROPERTY,
-                new Holder(exchange.getProperty(ACTIVE_SPAN_PROPERTY, 
Holder.class), span));
+        exchange.setProperty(ExchangePropertyKey.ACTIVE_SPAN,
+                new 
Holder(exchange.getProperty(ExchangePropertyKey.ACTIVE_SPAN, Holder.class), 
span));
         if (Boolean.TRUE.equals(exchange.getContext().isUseMDCLogging())) {
             MDC.put(MDC_TRACE_ID, span.traceId());
             MDC.put(MDC_SPAN_ID, span.spanId());
@@ -72,10 +72,10 @@ public final class ActiveSpanManager {
      * @param exchange The exchange
      */
     public static void deactivate(Exchange exchange) {
-        Holder holder = exchange.getProperty(ACTIVE_SPAN_PROPERTY, 
Holder.class);
+        Holder holder = exchange.getProperty(ExchangePropertyKey.ACTIVE_SPAN, 
Holder.class);
         if (holder != null) {
             Holder parent = holder.getParent();
-            exchange.setProperty(ACTIVE_SPAN_PROPERTY, parent);
+            exchange.setProperty(ExchangePropertyKey.ACTIVE_SPAN, parent);
 
             holder.closeScope();
             if (Boolean.TRUE.equals(exchange.getContext().isUseMDCLogging())) {
@@ -99,7 +99,7 @@ public final class ActiveSpanManager {
      * @param exchange The exchange
      */
     public static void endScope(Exchange exchange) {
-        Holder holder = exchange.getProperty(ACTIVE_SPAN_PROPERTY, 
Holder.class);
+        Holder holder = exchange.getProperty(ExchangePropertyKey.ACTIVE_SPAN, 
Holder.class);
         if (holder != null && !holder.isClosed()) {
             holder.closeScope();
         }
diff --git 
a/core/camel-api/src/generated/java/org/apache/camel/ExchangeConstantProvider.java
 
b/core/camel-api/src/generated/java/org/apache/camel/ExchangeConstantProvider.java
index 1887de93403..87d878c6a2c 100644
--- 
a/core/camel-api/src/generated/java/org/apache/camel/ExchangeConstantProvider.java
+++ 
b/core/camel-api/src/generated/java/org/apache/camel/ExchangeConstantProvider.java
@@ -13,8 +13,9 @@ public class ExchangeConstantProvider {
 
     private static final Map<String, String> MAP;
     static {
-        Map<String, String> map = new HashMap<>(156);
+        Map<String, String> map = new HashMap<>(157);
         map.put("ACCEPT_CONTENT_TYPE", "CamelAcceptContentType");
+        map.put("ACTIVE_SPAN", "OpenTracing.activeSpan");
         map.put("AGGREGATED_COLLECTION_GUARD", 
"CamelAggregatedCollectionGuard");
         map.put("AGGREGATED_COMPLETED_BY", "CamelAggregatedCompletedBy");
         map.put("AGGREGATED_CORRELATION_KEY", "CamelAggregatedCorrelationKey");
diff --git a/core/camel-api/src/main/java/org/apache/camel/Exchange.java 
b/core/camel-api/src/main/java/org/apache/camel/Exchange.java
index 41cd9b83b82..250cfaa8348 100644
--- a/core/camel-api/src/main/java/org/apache/camel/Exchange.java
+++ b/core/camel-api/src/main/java/org/apache/camel/Exchange.java
@@ -30,15 +30,15 @@ import org.apache.camel.spi.annotations.ConstantProvider;
  * During processing down the {@link Processor} chain, the {@link Exchange} 
provides access to the current (not the
  * original) request and response {@link Message} messages. The {@link 
Exchange} also holds meta-data during its entire
  * lifetime stored as properties accessible using the various {@link 
#getProperty(String)} methods. The
- * {@link #setProperty(String, Object)} is used to store a property. For 
example you can use this to store security, SLA
- * related data or any other information deemed useful throughout processing. 
If an {@link Exchange} failed during
+ * {@link #setProperty(String, Object)} is used to store a property. For 
example, you can use this to store security,
+ * SLA related data or any other information deemed useful throughout 
processing. If an {@link Exchange} failed during
  * routing the {@link Exception} that caused the failure is stored and 
accessible via the {@link #getException()}
  * method.
  * <p/>
  * An Exchange is created when a {@link Consumer} receives a request. A new 
{@link Message} is created, the request is
  * set as the body of the {@link Message} and depending on the {@link 
Consumer} other {@link Endpoint} and protocol
  * related information is added as headers on the {@link Message}. Then an 
Exchange is created and the newly created
- * {@link Message} is set as the in on the Exchange. Therefore an Exchange 
starts its life in a {@link Consumer}. The
+ * {@link Message} is set as the in on the Exchange. Therefore, an Exchange 
starts its life in a {@link Consumer}. The
  * Exchange is then sent down the {@link Route} for processing along a {@link 
Processor} chain. The {@link Processor} as
  * the name suggests is what processes the {@link Message} in the Exchange and 
Camel, in addition to providing
  * out-of-the-box a large number of useful processors, it also allows you to 
create your own. The rule Camel uses is to
@@ -57,7 +57,7 @@ import org.apache.camel.spi.annotations.ConstantProvider;
  * you could also instantiate your specialized {@link Message} and set it on 
the exchange using the
  * {@link #setOut(org.apache.camel.Message)} method. Please note that a {@link 
Message} contains not only the body but
  * also headers and attachments. If you are creating a new {@link Message} the 
headers and attachments of the in
- * {@link Message} are not automatically copied to the out by Camel and you'll 
have to set the headers and attachments
+ * {@link Message} are not automatically copied to the out by Camel, and 
you'll have to set the headers and attachments
  * you need yourself. If your {@link Processor} is not producing a different 
{@link Message} but only needs to slightly
  * modify the in, you can simply update the in {@link Message} returned by 
{@link #getIn()}.
  * <p/>
@@ -67,6 +67,7 @@ import org.apache.camel.spi.annotations.ConstantProvider;
 @ConstantProvider("org.apache.camel.ExchangeConstantProvider")
 public interface Exchange extends VariableAware {
 
+    String ACTIVE_SPAN = "OpenTracing.activeSpan";
     String AUTHENTICATION = "CamelAuthentication";
     String AUTHENTICATION_FAILURE_POLICY_ID = 
"CamelAuthenticationFailurePolicyId";
     @Deprecated(since = "2.20.0")
@@ -102,7 +103,7 @@ public interface Exchange extends VariableAware {
     String BATCH_COMPLETE = "CamelBatchComplete";
     String BEAN_METHOD_NAME = "CamelBeanMethodName";
     String BINDING = "CamelBinding";
-    // do not prefix with Camel and use lower-case starting letter as its a 
shared key
+    // do not prefix with Camel and use a lower-case starting letter as it's a 
shared key
     // used across other Apache products such as AMQ, SMX etc.
     String BREADCRUMB_ID = "breadcrumbId";
 
@@ -473,7 +474,7 @@ public interface Exchange extends VariableAware {
     /**
      * Returns whether any properties have been set
      *
-     * @return <tt>true</tt> if any properties has been set
+     * @return <tt>true</tt> if any property has been set
      */
     boolean hasProperties();
 
@@ -500,7 +501,7 @@ public interface Exchange extends VariableAware {
     /**
      * Returns a variable by name and specifying the type required
      *
-     * @param  name         the variable name. Can be prefixed with 
repo-id:name to lookup the variable from a specific
+     * @param  name         the variable name. Can be prefixed with 
repo-id:name to look up the variable from a specific
      *                      repository. If no repo-id is provided, then 
variables will be from the current exchange.
      * @param  defaultValue the default value to return if variable was absent
      * @param  type         the type of the variable
@@ -595,9 +596,9 @@ public interface Exchange extends VariableAware {
      * headers etc. is kept and propagated when routing continues. Bottom line 
end users should rarely use this method.
      * <p/>
      * <br/>
-     * If you want to test whether an OUT message have been set or not, use 
the {@link #hasOut()} method.
+     * If you want to test whether an OUT message has been set or not, use the 
{@link #hasOut()} method.
      * <p/>
-     * See also the class java doc for this {@link Exchange} for more details 
and this
+     * See also the class Javadoc for this {@link Exchange} for more details 
and this
      * <a 
href="http://camel.apache.org/using-getin-or-getout-methods-on-exchange.html";>FAQ
 entry</a>.
      *
      * @return     the response
@@ -615,9 +616,9 @@ public interface Exchange extends VariableAware {
      * headers etc. is kept and propagated when routing continues. Bottom line 
end users should rarely use this method.
      * <p/>
      * <br/>
-     * If you want to test whether an OUT message have been set or not, use 
the {@link #hasOut()} method.
+     * If you want to test whether an OUT message has been set or not, use the 
{@link #hasOut()} method.
      * <p/>
-     * See also the class java doc for this {@link Exchange} for more details 
and this
+     * See also the class Javadoc for this {@link Exchange} for more details 
and this
      * <a 
href="http://camel.apache.org/using-getin-or-getout-methods-on-exchange.html";>FAQ
 entry</a>.
      *
      * @param      type the given type
diff --git 
a/core/camel-api/src/main/java/org/apache/camel/ExchangePropertyKey.java 
b/core/camel-api/src/main/java/org/apache/camel/ExchangePropertyKey.java
index a22ec549074..da612e93348 100644
--- a/core/camel-api/src/main/java/org/apache/camel/ExchangePropertyKey.java
+++ b/core/camel-api/src/main/java/org/apache/camel/ExchangePropertyKey.java
@@ -23,6 +23,7 @@ import org.apache.camel.spi.CircuitBreakerConstants;
  */
 public enum ExchangePropertyKey {
 
+    ACTIVE_SPAN(Exchange.ACTIVE_SPAN),
     AGGREGATED_COMPLETED_BY(Exchange.AGGREGATED_COMPLETED_BY),
     AGGREGATED_CORRELATION_KEY(Exchange.AGGREGATED_CORRELATION_KEY),
     AGGREGATED_SIZE(Exchange.AGGREGATED_SIZE),
diff --git 
a/core/camel-support/src/main/java/org/apache/camel/saga/InMemorySagaCoordinator.java
 
b/core/camel-support/src/main/java/org/apache/camel/saga/InMemorySagaCoordinator.java
index dbb1c9c5323..0b91c6a52ea 100644
--- 
a/core/camel-support/src/main/java/org/apache/camel/saga/InMemorySagaCoordinator.java
+++ 
b/core/camel-support/src/main/java/org/apache/camel/saga/InMemorySagaCoordinator.java
@@ -32,6 +32,7 @@ import java.util.function.Function;
 import org.apache.camel.CamelContext;
 import org.apache.camel.Endpoint;
 import org.apache.camel.Exchange;
+import org.apache.camel.ExchangePropertyKey;
 import org.apache.camel.Expression;
 import org.apache.camel.RuntimeCamelException;
 import org.apache.camel.util.ObjectHelper;
@@ -43,8 +44,6 @@ import org.slf4j.LoggerFactory;
  */
 public class InMemorySagaCoordinator implements CamelSagaCoordinator {
 
-    private static final String ACTIVE_SPAN_PROPERTY = 
"OpenTracing.activeSpan";
-
     private enum Status {
         RUNNING,
         COMPENSATING,
@@ -234,9 +233,9 @@ public class InMemorySagaCoordinator implements 
CamelSagaCoordinator {
         answer.getMessage().setHeader(Exchange.SAGA_LONG_RUNNING_ACTION, 
getId());
 
         // preserve span from parent, so we can link this new exchange to the 
parent span for distributed tracing
-        Object span = parent != null ? 
parent.getProperty(ACTIVE_SPAN_PROPERTY) : null;
+        Object span = parent != null ? 
parent.getProperty(ExchangePropertyKey.ACTIVE_SPAN) : null;
         if (span != null) {
-            answer.setProperty(ACTIVE_SPAN_PROPERTY, span);
+            answer.setProperty(ExchangePropertyKey.ACTIVE_SPAN, span);
         }
 
         Map<String, Object> values = optionValues.get(step);

Reply via email to