use of io.opentracing.noop.NoopSpanContext in project hono by eclipse.
the class TracingHelper method injectSpanContext.
/**
* Injects a {@code SpanContext} as key-value pairs into a given operation.
* <p>
* This provides a generic way to serialize a span context in any kind of textual data.
* See {@link #extractSpanContext(Tracer, Supplier)} for the corresponding method to deserialize the
* context from that data.
*
* @param tracer The Tracer to use for injecting the context.
* @param spanContext The context to inject or {@code null} if no context is available.
* @param keyValueConsumer The operation that will receive the key-value pairs representing the context.
* @throws NullPointerException if tracer or keyValueConsumer is {@code null}.
*/
public static void injectSpanContext(final Tracer tracer, final SpanContext spanContext, final BiConsumer<String, String> keyValueConsumer) {
Objects.requireNonNull(tracer);
Objects.requireNonNull(keyValueConsumer);
if (spanContext != null && !(spanContext instanceof NoopSpanContext)) {
tracer.inject(spanContext, Format.Builtin.TEXT_MAP, new TextMap() {
@Override
public Iterator<Map.Entry<String, String>> iterator() {
throw new UnsupportedOperationException();
}
@Override
public void put(final String key, final String value) {
keyValueConsumer.accept(key, value);
}
});
}
}
use of io.opentracing.noop.NoopSpanContext in project hono by eclipse.
the class TracingHelper method injectSpanContext.
/**
* Injects a {@code SpanContext} into a JSON object.
* <p>
* The span context will be injected into a new JSON object under key <em>span-context</em>.
*
* @param tracer The Tracer to use for injecting the context.
* @param spanContext The context to inject or {@code null} if no context is available.
* @param jsonObject The JSON object to inject the context into.
* @throws NullPointerException if tracer or jsonObject is {@code null}.
*/
public static void injectSpanContext(final Tracer tracer, final SpanContext spanContext, final JsonObject jsonObject) {
Objects.requireNonNull(tracer);
Objects.requireNonNull(jsonObject);
if (spanContext != null && !(spanContext instanceof NoopSpanContext)) {
final JsonObject spanContextJson = new JsonObject();
jsonObject.put(JSON_KEY_SPAN_CONTEXT, spanContextJson);
tracer.inject(spanContext, Format.Builtin.TEXT_MAP, new JsonObjectInjectAdapter(spanContextJson));
}
}
use of io.opentracing.noop.NoopSpanContext in project hono by eclipse.
the class TracingHelper method injectSpanContext.
/**
* Injects a {@code SpanContext} into the headers of vert.x {@code DeliveryOptions}.
*
* @param tracer The Tracer to use for injecting the context.
* @param spanContext The context to inject or {@code null} if no context is available.
* @param deliveryOptions The delivery options to inject the context into.
* @throws NullPointerException if tracer or deliveryOptions is {@code null}.
*/
public static void injectSpanContext(final Tracer tracer, final SpanContext spanContext, final DeliveryOptions deliveryOptions) {
Objects.requireNonNull(tracer);
Objects.requireNonNull(deliveryOptions);
if (spanContext != null && !(spanContext instanceof NoopSpanContext)) {
final MultiMap headers = Optional.of(deliveryOptions).map(options -> options.getHeaders()).orElseGet(() -> {
final MultiMap newHeaders = MultiMap.caseInsensitiveMultiMap();
deliveryOptions.setHeaders(newHeaders);
return newHeaders;
});
tracer.inject(spanContext, Format.Builtin.TEXT_MAP, new MultiMapInjectAdapter(headers));
}
}
Aggregations