You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by da...@apache.org on 2024/01/24 10:28:13 UTC

(camel) branch main updated: CAMEL-20350: camel-observation - Fix Micrometer should use real null for null values. (#12891)

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 39f0a3488c9 CAMEL-20350: camel-observation - Fix Micrometer should use real null for null values. (#12891)
39f0a3488c9 is described below

commit 39f0a3488c974b33a4ccdb9586b14a2a5f2c47f5
Author: Claus Ibsen <cl...@gmail.com>
AuthorDate: Wed Jan 24 11:28:06 2024 +0100

    CAMEL-20350: camel-observation - Fix Micrometer should use real null for null values. (#12891)
---
 .../camel/observation/MicrometerObservationTracer.java   | 16 ++++++++++++----
 1 file changed, 12 insertions(+), 4 deletions(-)

diff --git a/components/camel-observation/src/main/java/org/apache/camel/observation/MicrometerObservationTracer.java b/components/camel-observation/src/main/java/org/apache/camel/observation/MicrometerObservationTracer.java
index 74f90818965..a11a84f7a1f 100644
--- a/components/camel-observation/src/main/java/org/apache/camel/observation/MicrometerObservationTracer.java
+++ b/components/camel-observation/src/main/java/org/apache/camel/observation/MicrometerObservationTracer.java
@@ -72,14 +72,20 @@ public class MicrometerObservationTracer extends org.apache.camel.tracing.Tracer
                 throw new UnsupportedOperationException("You can't extract when sending a message");
             case SPAN_KIND_SERVER:
                 RequestReplyReceiverContext<Object, Message> replyReceiverContext
-                        = new RequestReplyReceiverContext<>((carrier, key) -> String.valueOf(adapter.get(key)));
+                        = new RequestReplyReceiverContext<>((carrier, key) -> {
+                            Object val = adapter.get(key);
+                            return val != null ? val.toString() : null;
+                        });
                 replyReceiverContext.setResponse(exchange.getMessage());
                 replyReceiverContext.setCarrier(exchange.getIn());
                 return replyReceiverContext;
             case CONSUMER:
             case SPAN_KIND_CLIENT:
                 ReceiverContext<Message> receiverContext
-                        = new ReceiverContext<>((carrier, key) -> String.valueOf(adapter.get(key)));
+                        = new ReceiverContext<>((carrier, key) -> {
+                            Object val = adapter.get(key);
+                            return val != null ? val.toString() : null;
+                        });
                 receiverContext.setCarrier(exchange.getIn());
                 return receiverContext;
             default:
@@ -144,8 +150,10 @@ public class MicrometerObservationTracer extends org.apache.camel.tracing.Tracer
                 // Because Camel allows to close scopes multiple times
                 TracingObservationHandler.TracingContext tracingContext
                         = parentObservation.getContextView().get(TracingObservationHandler.TracingContext.class);
-                Span parentSpan = tracingContext.getSpan();
-                scope = tracer.withSpan(parentSpan);
+                if (tracingContext != null) {
+                    Span parentSpan = tracingContext.getSpan();
+                    scope = tracer.withSpan(parentSpan);
+                }
             }
             if (parentObservation != null) {
                 observation.parentObservation(parentObservation);