use of org.exquery.xquery3.Annotation in project brave by openzipkin.
the class MutableSpanMapTest method reportOrphanedSpans_afterGC.
/**
* This is the key feature. Spans orphaned via GC are reported to zipkin on the next action.
*
* <p>This is a customized version of https://github.com/raphw/weak-lock-free/blob/master/src/test/java/com/blogspot/mydailyjava/weaklockfree/WeakConcurrentMapTest.java
*/
@Test
public void reportOrphanedSpans_afterGC() {
TraceContext context1 = context.toBuilder().spanId(1).build();
map.getOrCreate(context1);
TraceContext context2 = context.toBuilder().spanId(2).build();
map.getOrCreate(context2);
TraceContext context3 = context.toBuilder().spanId(3).build();
map.getOrCreate(context3);
TraceContext context4 = context.toBuilder().spanId(4).build();
map.getOrCreate(context4);
// By clearing strong references in this test, we are left with the weak ones in the map
context1 = context2 = null;
blockOnGC();
// After GC, we expect that the weak references of context1 and context2 to be cleared
assertThat(map.delegate.keySet()).extracting(o -> ((Reference) o).get()).containsExactlyInAnyOrder(null, null, context3, context4);
map.reportOrphanedSpans();
// After reporting, we expect no the weak references of null
assertThat(map.delegate.keySet()).extracting(o -> ((Reference) o).get()).containsExactlyInAnyOrder(context3, context4);
// We also expect the spans to have been reported
assertThat(spans).flatExtracting(Span::annotations).extracting(Annotation::value).containsExactly("brave.flush", "brave.flush");
}
use of org.exquery.xquery3.Annotation in project spring-cloud-gcp by spring-cloud.
the class LabelExtractor method extract.
/**
* Extracts the Stackdriver span labels that are equivalent to the Zipkin Span
* annotations.
*
* @param zipkinSpan The Zipkin Span
* @return A map of the Stackdriver span labels equivalent to the Zipkin annotations.
*/
public Map<String, String> extract(Span zipkinSpan) {
Map<String, String> result = new LinkedHashMap<>();
for (Map.Entry<String, String> tag : zipkinSpan.tags().entrySet()) {
result.put(label(tag.getKey()), tag.getValue());
}
// trace might not show the final destination.
if (zipkinSpan.localEndpoint() != null && zipkinSpan.kind() == Span.Kind.SERVER) {
if (zipkinSpan.localEndpoint().ipv4() != null) {
result.put(label("endpoint.ipv4"), zipkinSpan.localEndpoint().ipv4());
}
if (zipkinSpan.localEndpoint().ipv6() != null) {
result.put(label("endpoint.ipv6"), zipkinSpan.localEndpoint().ipv6());
}
}
for (Annotation annotation : zipkinSpan.annotations()) {
result.put(label(annotation.value()), formatTimestamp(annotation.timestamp()));
}
if (zipkinSpan.localEndpoint() != null && !zipkinSpan.localEndpoint().serviceName().isEmpty()) {
result.put("/component", zipkinSpan.localEndpoint().serviceName());
}
if (zipkinSpan.parentId() == null) {
String agentName = System.getProperty("stackdriver.trace.zipkin.agent", "spring-cloud-gcp-trace");
result.put("/agent", agentName);
}
return result;
}
use of org.exquery.xquery3.Annotation in project zipkin by openzipkin.
the class BulkIndexWriter method addSearchFields.
static void addSearchFields(Span span, JsonGenerator writer) throws IOException {
long timestampMillis = span.timestampAsLong() / 1000L;
if (timestampMillis != 0L)
writer.writeNumberField("timestamp_millis", timestampMillis);
if (!span.tags().isEmpty() || !span.annotations().isEmpty()) {
writer.writeArrayFieldStart("_q");
for (Annotation a : span.annotations()) {
if (a.value().length() > SHORT_STRING_LENGTH)
continue;
writer.writeString(a.value());
}
for (Map.Entry<String, String> tag : span.tags().entrySet()) {
int length = tag.getKey().length() + tag.getValue().length() + 1;
if (length > SHORT_STRING_LENGTH)
continue;
// search is possible by key alone
writer.writeString(tag.getKey());
writer.writeString(tag.getKey() + "=" + tag.getValue());
}
writer.writeEndArray();
}
}
use of org.exquery.xquery3.Annotation in project zipkin by openzipkin.
the class CassandraUtil method annotationQuery.
/**
* Returns a set of annotation getValues and tags joined on equals, delimited by ░
*
* <p>Values over {@link RecyclableBuffers#SHORT_STRING_LENGTH} are not considered. Zipkin's
* {@link QueryRequest#annotationQuery()} are equals match. Not all values are lookup values. For
* example, {@code sql.query} isn't something that is likely to be looked up by value and indexing
* that could add a potentially kilobyte partition key on {@link Schema#TABLE_SPAN}
*
* @see QueryRequest#annotationQuery()
*/
@Nullable
static String annotationQuery(Span span) {
if (span.annotations().isEmpty() && span.tags().isEmpty())
return null;
// as very unlikely to be in the query
char delimiter = '░';
StringBuilder result = new StringBuilder().append(delimiter);
for (Annotation a : span.annotations()) {
if (a.value().length() > SHORT_STRING_LENGTH)
continue;
result.append(a.value()).append(delimiter);
}
for (Map.Entry<String, String> tag : span.tags().entrySet()) {
if (tag.getValue().length() > SHORT_STRING_LENGTH)
continue;
// search is possible by key alone
result.append(tag.getKey()).append(delimiter);
result.append(tag.getKey()).append('=').append(tag.getValue()).append(delimiter);
}
return result.length() == 1 ? null : result.toString();
}
use of org.exquery.xquery3.Annotation in project zipkin by openzipkin.
the class V2SpanWriter method sizeInBytes.
@Override
public int sizeInBytes(Span value) {
// {"traceId":""
int sizeInBytes = 13;
sizeInBytes += value.traceId().length();
if (value.parentId() != null) {
// ,"parentId":"0123456789abcdef"
sizeInBytes += 30;
}
// ,"id":"0123456789abcdef"
sizeInBytes += 24;
if (value.kind() != null) {
// ,"kind":""
sizeInBytes += 10;
sizeInBytes += value.kind().name().length();
}
if (value.name() != null) {
// ,"name":""
sizeInBytes += 10;
sizeInBytes += jsonEscapedSizeInBytes(value.name());
}
if (value.timestampAsLong() != 0L) {
// ,"timestamp":
sizeInBytes += 13;
sizeInBytes += asciiSizeInBytes(value.timestampAsLong());
}
if (value.durationAsLong() != 0L) {
// ,"duration":
sizeInBytes += 12;
sizeInBytes += asciiSizeInBytes(value.durationAsLong());
}
if (value.localEndpoint() != null) {
// ,"localEndpoint":
sizeInBytes += 17;
sizeInBytes += endpointSizeInBytes(value.localEndpoint(), false);
}
if (value.remoteEndpoint() != null) {
// ,"remoteEndpoint":
sizeInBytes += 18;
sizeInBytes += endpointSizeInBytes(value.remoteEndpoint(), false);
}
if (!value.annotations().isEmpty()) {
// ,"annotations":[]
sizeInBytes += 17;
int length = value.annotations().size();
// comma to join elements
if (length > 1)
sizeInBytes += length - 1;
for (int i = 0; i < length; i++) {
Annotation a = value.annotations().get(i);
sizeInBytes += annotationSizeInBytes(a.timestamp(), a.value(), 0);
}
}
if (!value.tags().isEmpty()) {
// ,"tags":{}
sizeInBytes += 10;
int tagCount = value.tags().size();
// comma to join elements
if (tagCount > 1)
sizeInBytes += tagCount - 1;
for (Map.Entry<String, String> entry : value.tags().entrySet()) {
// "":""
sizeInBytes += 5;
sizeInBytes += jsonEscapedSizeInBytes(entry.getKey());
sizeInBytes += jsonEscapedSizeInBytes(entry.getValue());
}
}
if (Boolean.TRUE.equals(value.debug())) {
// ,"debug":true
sizeInBytes += 13;
}
if (Boolean.TRUE.equals(value.shared())) {
// ,"shared":true
sizeInBytes += 14;
}
// }
return ++sizeInBytes;
}
Aggregations