use of brave.propagation.TraceContextOrSamplingFlags in project brave by openzipkin.
the class ITTracingFilter_Consumer method propagates_sampledFalse.
/**
* Unlike Brave 3, Brave 4 propagates trace ids even when unsampled
*/
@Test
public void propagates_sampledFalse() throws Exception {
setTracing(tracingBuilder(Sampler.NEVER_SAMPLE).build());
client.get().sayHello("jorge");
TraceContextOrSamplingFlags extracted = server.takeRequest();
assertThat(extracted.sampled()).isFalse();
// @After will check that nothing is reported
}
use of brave.propagation.TraceContextOrSamplingFlags in project brave by openzipkin.
the class ITTracingClientInterceptor method propagates_sampledFalse.
/**
* Unlike Brave 3, Brave 4 propagates trace ids even when unsampled
*/
@Test
public void propagates_sampledFalse() throws Exception {
tracing = GrpcTracing.create(tracingBuilder(Sampler.NEVER_SAMPLE).build());
closeClient(client);
client = newClient();
GreeterGrpc.newBlockingStub(client).sayHello(HELLO_REQUEST);
TraceContextOrSamplingFlags extracted = server.takeRequest();
assertThat(extracted.sampled()).isFalse();
// @After will check that nothing is reported
}
use of brave.propagation.TraceContextOrSamplingFlags in project brave by openzipkin.
the class KafkaTracing method nextSpan.
/**
* Use this to create a span for processing the given record. Note: the result has no name and is
* not started.
*
* <p>This creates a child from identifiers extracted from the record headers, or a new span if
* one couldn't be extracted.
*/
public Span nextSpan(ConsumerRecord<?, ?> record) {
TraceContextOrSamplingFlags extracted = extractAndClearHeaders(record);
Span result = tracing.tracer().nextSpan(extracted);
if (extracted.context() == null && !result.isNoop()) {
addTags(record, result);
}
return result;
}
use of brave.propagation.TraceContextOrSamplingFlags in project brave by openzipkin.
the class TracingConsumer method poll.
/**
* This
*/
@Override
public ConsumerRecords<K, V> poll(long timeout) {
ConsumerRecords<K, V> records = delegate.poll(timeout);
if (records.isEmpty() || tracing.isNoop())
return records;
Map<String, Span> consumerSpansForTopic = new LinkedHashMap<>();
for (TopicPartition partition : records.partitions()) {
String topic = partition.topic();
List<ConsumerRecord<K, V>> recordsInPartition = records.records(partition);
for (int i = 0, length = recordsInPartition.size(); i < length; i++) {
ConsumerRecord<K, V> record = recordsInPartition.get(i);
TraceContextOrSamplingFlags extracted = extractor.extract(record.headers());
// make or reuse a span for this topic
if (extracted.samplingFlags() != null && extracted.extra().isEmpty()) {
Span consumerSpanForTopic = consumerSpansForTopic.get(topic);
if (consumerSpanForTopic == null) {
consumerSpansForTopic.put(topic, consumerSpanForTopic = tracing.tracer().nextSpan(extracted).name("poll").kind(Span.Kind.CONSUMER).tag(KafkaTags.KAFKA_TOPIC_TAG, topic).start());
}
// no need to remove propagation headers as we failed to extract anything
injector.inject(consumerSpanForTopic.context(), record.headers());
} else {
// we extracted request-scoped data, so cannot share a consumer span.
Span span = tracing.tracer().nextSpan(extracted);
if (!span.isNoop()) {
span.name("poll").kind(Span.Kind.CONSUMER).tag(KafkaTags.KAFKA_TOPIC_TAG, topic);
if (remoteServiceName != null) {
span.remoteEndpoint(Endpoint.newBuilder().serviceName(remoteServiceName).build());
}
// span won't be shared by other records
span.start().finish();
}
// remove prior propagation headers from the record
tracing.propagation().keys().forEach(key -> record.headers().remove(key));
injector.inject(span.context(), record.headers());
}
}
}
consumerSpansForTopic.values().forEach(span -> {
if (remoteServiceName != null) {
span.remoteEndpoint(Endpoint.newBuilder().serviceName(remoteServiceName).build());
}
span.finish();
});
return records;
}
use of brave.propagation.TraceContextOrSamplingFlags in project brave by openzipkin.
the class TracerTest method nextSpan_extractedExtra_appendsToChildOfCurrent.
@Test
public void nextSpan_extractedExtra_appendsToChildOfCurrent() {
// current parent already has extra stuff
Span parent = tracer.toSpan(tracer.newTrace().context().toBuilder().extra(asList(1L)).build());
TraceContextOrSamplingFlags extracted = TraceContextOrSamplingFlags.create(SamplingFlags.EMPTY).toBuilder().addExtra(2L).build();
try (Tracer.SpanInScope ws = tracer.withSpanInScope(parent)) {
assertThat(tracer.nextSpan(extracted).context().extra()).containsExactly(1L, 2L);
}
}
Aggregations