Skip to content

Commit

Permalink
feat: allow to inject message tracing context to any carrier
Browse files Browse the repository at this point in the history
  • Loading branch information
guillaumelamirand committed Nov 13, 2024
1 parent 4a04bad commit 4f11ce5
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 2 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@

<properties>
<gravitee-bom.version>8.1.16</gravitee-bom.version>
<gravitee-node.version>7.0.0-alpha.1</gravitee-node.version>
<gravitee-node.version>7.0.0-alpha.2</gravitee-node.version>
<gravitee-common.version>4.5.1</gravitee-common.version>
<gravitee-policy-api.version>1.11.0</gravitee-policy-api.version>
<gravitee-reporter-api.version>1.31.2</gravitee-reporter-api.version>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,10 @@
*/
package io.gravitee.gateway.reactive.api.tracing;

import io.gravitee.common.service.AbstractService;
import io.gravitee.node.api.opentelemetry.Span;
import io.opentelemetry.context.propagation.TextMapSetter;
import io.vertx.core.Context;
import java.util.function.BiConsumer;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;

Expand Down Expand Up @@ -67,4 +68,12 @@ public <R> void endWithResponseAndError(final Span span, final R response, final
public <R> void endWithResponseAndError(final Span span, final R response, final String message) {
delegate.endWithResponseAndError(vertxContext, span, response, message);
}

public <C> void injectSpanContext(final BiConsumer<String, String> textMapSetter) {
delegate.injectSpanContext(vertxContext, textMapSetter);
}

public <C> void injectSpanContext(final Span span, final BiConsumer<String, String> textMapSetter) {
delegate.injectSpanContext(vertxContext, span, textMapSetter);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,12 @@
import static io.gravitee.gateway.reactive.api.context.InternalContextAttributes.ATTR_INTERNAL_MESSAGE_RECORDABLE;
import static io.gravitee.gateway.reactive.api.context.InternalContextAttributes.ATTR_INTERNAL_TRACING_MESSAGE_SPAN;

import io.gravitee.gateway.reactive.api.context.base.BaseExecutionContext;
import io.gravitee.gateway.reactive.api.message.Message;
import io.gravitee.node.api.opentelemetry.Span;
import io.opentelemetry.context.propagation.TextMapSetter;
import java.util.Map;
import java.util.function.BiConsumer;

/**
* This interface defines a {@link Message} compatible with tracing
Expand Down Expand Up @@ -58,4 +61,19 @@ default boolean isTraceable() {
* @param value the value associated
*/
void addTracingAttribute(final String key, final String value);

/**
* Allow to inject message context into the given carrier
*
* @param executionContext the current execution context
* @param textMapSetter the map setter to use
*/
default void injectSpanContext(final BaseExecutionContext executionContext, final BiConsumer<String, String> textMapSetter) {
if (isTraceable()) {
Span messageSpan = internalAttribute(ATTR_INTERNAL_TRACING_MESSAGE_SPAN);
if (messageSpan != null) {
executionContext.getTracer().injectSpanContext(messageSpan, textMapSetter);
}
}
}
}

0 comments on commit 4f11ce5

Please sign in to comment.