squakez commented on code in PR #22677:
URL: https://github.com/apache/camel/pull/22677#discussion_r3109275027
##########
components/camel-opentelemetry2/src/main/java/org/apache/camel/opentelemetry2/OpenTelemetrySpanAdapter.java:
##########
@@ -24,18 +24,41 @@
import io.opentelemetry.api.trace.Span;
import io.opentelemetry.api.trace.StatusCode;
import io.opentelemetry.context.Scope;
+import org.apache.camel.Exchange;
+import org.apache.camel.telemetry.SpanStorageManagerExchange;
import org.apache.camel.telemetry.TagConstants;
public class OpenTelemetrySpanAdapter implements
org.apache.camel.telemetry.Span {
private static final String DEFAULT_EVENT_NAME = "log";
static final String BAGGAGE_CAMEL_FLAG = "camelScope";
+ private static final SpanStorageManagerExchange SPAN_STORAGE = new
SpanStorageManagerExchange();
Review Comment:
This is an adapter, it has to know nothing about storage.
##########
components/camel-opentelemetry2/src/main/java/org/apache/camel/opentelemetry2/OpenTelemetrySpanAdapter.java:
##########
@@ -24,18 +24,41 @@
import io.opentelemetry.api.trace.Span;
import io.opentelemetry.api.trace.StatusCode;
import io.opentelemetry.context.Scope;
+import org.apache.camel.Exchange;
+import org.apache.camel.telemetry.SpanStorageManagerExchange;
import org.apache.camel.telemetry.TagConstants;
public class OpenTelemetrySpanAdapter implements
org.apache.camel.telemetry.Span {
private static final String DEFAULT_EVENT_NAME = "log";
static final String BAGGAGE_CAMEL_FLAG = "camelScope";
+ private static final SpanStorageManagerExchange SPAN_STORAGE = new
SpanStorageManagerExchange();
+
private final Span otelSpan;
- private final Baggage baggage;
+ private Baggage baggage;
private Scope scope;
private Scope baggageScope;
+ /**
+ * Retrieves the OpenTelemetry span associated with the given {@link
Exchange}.
+ *
+ * <p>
+ * This method returns the span only if the current span implementation is
backed by OpenTelemetry. If no span is
+ * present or a different tracing implementation is in use, {@code null}
is returned.
+ * </p>
+ *
+ * @param exchange the current Camel exchange
+ * @return the OpenTelemetry span adapter, or {@code null} if
unavailable
+ */
+ public static OpenTelemetrySpanAdapter fromExchange(Exchange exchange) {
Review Comment:
The adapter should know nothing about the exchange concept.
##########
components/camel-opentelemetry2/src/main/java/org/apache/camel/opentelemetry2/OpenTelemetrySpanAdapter.java:
##########
@@ -69,6 +92,26 @@ protected Baggage getBaggage() {
return this.baggage;
}
+ /**
+ * Adds a baggage entry that will be propagated to downstream spans and
services. If this span is currently active
+ * (made current), the baggage scope is refreshed so the new entry is
immediately visible in the current context.
+ */
+ public void setBaggageEntry(String key, String value) {
+ this.baggage = this.baggage.toBuilder().put(key, value).build();
+ // If baggage is currently scoped, refresh it so the new entry takes
effect
+ if (this.baggageScope != null) {
+ this.baggageScope.close();
+ this.baggageScope = this.baggage.makeCurrent();
Review Comment:
Potential leak. You close the previous scope, but you have no guaranty that
this one is going to be closed by anybody.
##########
components/camel-opentelemetry2/src/main/java/org/apache/camel/opentelemetry2/OpenTelemetrySpanAdapter.java:
##########
@@ -24,18 +24,41 @@
import io.opentelemetry.api.trace.Span;
import io.opentelemetry.api.trace.StatusCode;
import io.opentelemetry.context.Scope;
+import org.apache.camel.Exchange;
+import org.apache.camel.telemetry.SpanStorageManagerExchange;
import org.apache.camel.telemetry.TagConstants;
public class OpenTelemetrySpanAdapter implements
org.apache.camel.telemetry.Span {
private static final String DEFAULT_EVENT_NAME = "log";
static final String BAGGAGE_CAMEL_FLAG = "camelScope";
+ private static final SpanStorageManagerExchange SPAN_STORAGE = new
SpanStorageManagerExchange();
+
private final Span otelSpan;
- private final Baggage baggage;
+ private Baggage baggage;
Review Comment:
I think it makes sense to be final to avoid any kind of tampering.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]