use of io.opentelemetry.api.trace.SpanContext in project opentelemetry-java-instrumentation by open-telemetry.
the class CamelPropagationUtilTest method shouldExtractAwsParentForSqsEndpoint.
@Test
public void shouldExtractAwsParentForSqsEndpoint() {
// given
Endpoint endpoint = new SqsEndpoint("", new SqsComponent(), new SqsConfiguration());
Map<String, Object> exchangeHeaders = Collections.singletonMap("AWSTraceHeader", "Root=1-5759e988-bd862e3fe1be46a994272793;Parent=53995c3f42cd8ad8;Sampled=1\n");
// when
Context parent = CamelPropagationUtil.extractParent(exchangeHeaders, endpoint);
// then
Span parentSpan = Span.fromContext(parent);
SpanContext parentSpanContext = parentSpan.getSpanContext();
assertThat(parentSpanContext.getTraceId()).isEqualTo("5759e988bd862e3fe1be46a994272793");
assertThat(parentSpanContext.getSpanId()).isEqualTo("53995c3f42cd8ad8");
}
use of io.opentelemetry.api.trace.SpanContext in project opentelemetry-java-instrumentation by open-telemetry.
the class OpenTelemetryContextDataProvider method supplyContextData.
/**
* Returns context from the current span when available.
*
* @return A map containing string versions of the traceId, spanId, and traceFlags, which can then
* be accessed from layout components
*/
@Override
public Map<String, String> supplyContextData() {
Span currentSpan = Span.current();
if (!currentSpan.getSpanContext().isValid()) {
return Collections.emptyMap();
}
Map<String, String> contextData = new HashMap<>();
SpanContext spanContext = currentSpan.getSpanContext();
contextData.put(TRACE_ID, spanContext.getTraceId());
contextData.put(SPAN_ID, spanContext.getSpanId());
contextData.put(TRACE_FLAGS, spanContext.getTraceFlags().asHex());
return contextData;
}
use of io.opentelemetry.api.trace.SpanContext in project opentelemetry-java-instrumentation by open-telemetry.
the class OpenTelemetryAppender method wrapEvent.
public static ILoggingEvent wrapEvent(ILoggingEvent event) {
Span currentSpan = Span.current();
if (!currentSpan.getSpanContext().isValid()) {
return event;
}
Map<String, String> eventContext = event.getMDCPropertyMap();
if (eventContext != null && eventContext.containsKey(TRACE_ID)) {
// Assume already instrumented event if traceId is present.
return event;
}
Map<String, String> contextData = new HashMap<>();
SpanContext spanContext = currentSpan.getSpanContext();
contextData.put(TRACE_ID, spanContext.getTraceId());
contextData.put(SPAN_ID, spanContext.getSpanId());
contextData.put(TRACE_FLAGS, spanContext.getTraceFlags().asHex());
if (eventContext == null) {
eventContext = contextData;
} else {
eventContext = new UnionMap<>(eventContext, contextData);
}
return new LoggingEventWrapper(event, eventContext);
}
use of io.opentelemetry.api.trace.SpanContext in project opentelemetry-java-instrumentation by open-telemetry.
the class SpanDecoratingContextDataInjector method injectContextData.
@Override
public StringMap injectContextData(List<Property> list, StringMap stringMap) {
StringMap contextData = delegate.injectContextData(list, stringMap);
if (contextData.containsKey(TRACE_ID)) {
// Assume already instrumented event if traceId is present.
return contextData;
}
SpanContext currentContext = Java8BytecodeBridge.currentSpan().getSpanContext();
if (!currentContext.isValid()) {
return contextData;
}
StringMap newContextData = new SortedArrayStringMap(contextData);
newContextData.putValue(TRACE_ID, currentContext.getTraceId());
newContextData.putValue(SPAN_ID, currentContext.getSpanId());
newContextData.putValue(TRACE_FLAGS, currentContext.getTraceFlags().asHex());
return newContextData;
}
use of io.opentelemetry.api.trace.SpanContext in project opentelemetry-java-instrumentation by open-telemetry.
the class ParentContextExtractor method isValidAndSampled.
private static boolean isValidAndSampled(Context context) {
if (context == null) {
return false;
}
Span parentSpan = Span.fromContext(context);
SpanContext parentSpanContext = parentSpan.getSpanContext();
return (parentSpanContext.isValid() && parentSpanContext.isSampled());
}
Aggregations