use of io.opentelemetry.api.trace.SpanContext in project opentelemetry-java by open-telemetry.
the class B3PropagatorInjectorSingleHeader method inject.
@Override
public <C> void inject(Context context, @Nullable C carrier, TextMapSetter<C> setter) {
if (context == null) {
return;
}
if (setter == null) {
return;
}
SpanContext spanContext = Span.fromContext(context).getSpanContext();
if (!spanContext.isValid()) {
return;
}
char[] chars = TemporaryBuffers.chars(COMBINED_HEADER_SIZE);
String traceId = spanContext.getTraceId();
traceId.getChars(0, traceId.length(), chars, 0);
chars[SPAN_ID_OFFSET - 1] = B3Propagator.COMBINED_HEADER_DELIMITER_CHAR;
String spanId = spanContext.getSpanId();
spanId.getChars(0, SpanId.getLength(), chars, SPAN_ID_OFFSET);
chars[SAMPLED_FLAG_OFFSET - 1] = B3Propagator.COMBINED_HEADER_DELIMITER_CHAR;
if (Boolean.TRUE.equals(context.get(B3Propagator.DEBUG_CONTEXT_KEY))) {
chars[SAMPLED_FLAG_OFFSET] = B3Propagator.DEBUG_SAMPLED;
} else {
chars[SAMPLED_FLAG_OFFSET] = spanContext.isSampled() ? B3Propagator.IS_SAMPLED : B3Propagator.NOT_SAMPLED;
}
setter.set(carrier, COMBINED_HEADER, new String(chars, 0, COMBINED_HEADER_SIZE));
}
use of io.opentelemetry.api.trace.SpanContext in project opentelemetry-java by open-telemetry.
the class LogDataBuilderTest method canSetSpanContext.
@Test
void canSetSpanContext() {
LogDataBuilder builder = LogDataBuilder.create(resource, libraryInfo);
SpanContext spanContext = mock(SpanContext.class);
LogData result = builder.setSpanContext(spanContext).build();
assertSame(spanContext, result.getSpanContext());
}
use of io.opentelemetry.api.trace.SpanContext in project opentelemetry-java by open-telemetry.
the class LogMarshaler method create.
// name field to be removed
@SuppressWarnings("deprecation")
static LogMarshaler create(io.opentelemetry.sdk.logs.data.LogData logData) {
KeyValueMarshaler[] attributeMarshalers = KeyValueMarshaler.createRepeated(logData.getAttributes());
// For now, map all the bodies to String AnyValue.
StringAnyValueMarshaler anyValueMarshaler = new StringAnyValueMarshaler(MarshalerUtil.toBytes(logData.getBody().asString()));
SpanContext spanContext = logData.getSpanContext();
return new LogMarshaler(logData.getEpochNanos(), toProtoSeverityNumber(logData.getSeverity()), MarshalerUtil.toBytes(logData.getSeverityText()), MarshalerUtil.toBytes(logData.getName()), anyValueMarshaler, attributeMarshalers, // TODO (trask) implement droppedAttributesCount in LogRecord
0, spanContext.getTraceFlags(), spanContext.getTraceId().equals(INVALID_TRACE_ID) ? null : spanContext.getTraceId(), spanContext.getSpanId().equals(INVALID_SPAN_ID) ? null : spanContext.getSpanId());
}
use of io.opentelemetry.api.trace.SpanContext in project opentelemetry-java-instrumentation by open-telemetry.
the class CamelPropagationUtilTest method shouldNotFailExtractingNullAwsParentForSqsEndpoint.
@Test
public void shouldNotFailExtractingNullAwsParentForSqsEndpoint() {
// given
Endpoint endpoint = new SqsEndpoint("", new SqsComponent(), new SqsConfiguration());
Map<String, Object> exchangeHeaders = Collections.singletonMap("AWSTraceHeader", null);
// when
Context parent = CamelPropagationUtil.extractParent(exchangeHeaders, endpoint);
// then
Span parentSpan = Span.fromContext(parent);
SpanContext parentSpanContext = parentSpan.getSpanContext();
assertThat(parentSpanContext.isValid()).isEqualTo(false);
}
use of io.opentelemetry.api.trace.SpanContext in project opentelemetry-java-instrumentation by open-telemetry.
the class CamelPropagationUtilTest method shouldNotFailExtractingNullHttpParentForHttpEndpoint.
@Test
public void shouldNotFailExtractingNullHttpParentForHttpEndpoint() throws Exception {
// given
Endpoint endpoint = new HttpEndpoint("", new HttpComponent(), URI.create(""));
Map<String, Object> exchangeHeaders = Collections.singletonMap("uber-trace-id", null);
// when
Context parent = CamelPropagationUtil.extractParent(exchangeHeaders, endpoint);
// then
Span parentSpan = Span.fromContext(parent);
SpanContext parentSpanContext = parentSpan.getSpanContext();
assertThat(parentSpanContext.isValid()).isEqualTo(false);
}
Aggregations