io.opentelemetry.javaagent.instrumentation.apachecamel.CamelPropagationUtil Maven / Gradle / Ivy
The newest version!
/*
* Copyright The OpenTelemetry Authors
* SPDX-License-Identifier: Apache-2.0
*/
package io.opentelemetry.javaagent.instrumentation.apachecamel;
import io.opentelemetry.api.GlobalOpenTelemetry;
import io.opentelemetry.context.Context;
import io.opentelemetry.context.propagation.TextMapGetter;
import io.opentelemetry.context.propagation.TextMapSetter;
import io.opentelemetry.contrib.awsxray.propagator.AwsXrayPropagator;
import java.util.Collections;
import java.util.Map;
import org.apache.camel.Endpoint;
final class CamelPropagationUtil {
private CamelPropagationUtil() {}
static Context extractParent(Map exchangeHeaders, Endpoint endpoint) {
return (isAwsPropagated(endpoint)
? extractAwsPropagationParent(exchangeHeaders)
: extractHttpPropagationParent(exchangeHeaders));
}
private static boolean isAwsPropagated(Endpoint endpoint) {
return endpoint.getClass().getName().endsWith("SqsEndpoint");
}
private static Context extractAwsPropagationParent(Map exchangeHeaders) {
return AwsXrayPropagator.getInstance()
.extract(
Context.current(),
Collections.singletonMap("X-Amzn-Trace-Id", exchangeHeaders.get("AWSTraceHeader")),
MapGetter.INSTANCE);
}
private static Context extractHttpPropagationParent(Map exchangeHeaders) {
return GlobalOpenTelemetry.getPropagators()
.getTextMapPropagator()
.extract(Context.current(), exchangeHeaders, MapGetter.INSTANCE);
}
static void injectParent(Context context, Map exchangeHeaders) {
GlobalOpenTelemetry.getPropagators()
.getTextMapPropagator()
.inject(context, exchangeHeaders, MapSetter.INSTANCE);
}
private enum MapGetter implements TextMapGetter