CassandraUtil { static Set<String> annotationKeys(Span span) { Set<String> annotationKeys = new LinkedHashSet<>(); String localServiceName = span.localServiceName(); if (localServiceName == null) return annotationKeys; for (Annotation a : span.annotations()) { if (a.value().length() > SHORT_STRING_LENGTH) continue; if (CORE_ANNOTATIONS.contains(a.value())) continue; annotationKeys.add(localServiceName + ":" + a.value()); } for (Map.Entry<String, String> e : span.tags().entrySet()) { if (e.getValue().length() > SHORT_STRING_LENGTH) continue; annotationKeys.add(localServiceName + ":" + e.getKey()); annotationKeys.add(localServiceName + ":" + e.getKey() + ":" + e.getValue()); } return annotationKeys; }    }
@Test public void annotationKeys_serviceNameRequired() { request = request.toBuilder().parseAnnotationQuery("error").build(); assertThatThrownBy(() -> CassandraUtil.annotationKeys(request)) .isInstanceOf(IllegalArgumentException.class); }
@Test public void annotationKeys() { assertThat( CassandraUtil.annotationKeys( request .toBuilder() .serviceName("service") .parseAnnotationQuery("error and http.method=GET") .build())) .containsExactly("service:error", "service:http.method:GET"); }
@Test public void annotationKeys_dedupes() { assertThat( CassandraUtil.annotationKeys( request .toBuilder() .serviceName("service") .parseAnnotationQuery("error and error") .build())) .containsExactly("service:error"); }
@Test public void annotationKeys_skipsCoreAndAddressAnnotations() { Span span = CLIENT_SPAN.toBuilder() .addAnnotation(CLIENT_SPAN.timestampAsLong(), "cs").build(); assertThat(CassandraUtil.annotationKeys(span)) .containsExactly( "frontend:foo", "frontend:clnt/finagle.version", "frontend:clnt/finagle.version:6.45.0", "frontend:http.path", "frontend:http.path:/api"); }
@Test public void annotationKeys_skipsTagsLongerThan256chars() { String arn = "arn:aws:acm:us-east-1:123456789012:certificate/12345678-1234-1234-1234-123456789012"; String url = "http: Span span = Span.newBuilder() .traceId("1") .id("1") .localEndpoint(FRONTEND) .putTag("aws.arn", arn) .putTag("http.url", url) .build(); assertThat(CassandraUtil.annotationKeys(span)) .containsOnly("frontend:aws.arn", "frontend:aws.arn:" + arn); }
@Test public void annotationKeys_emptyRequest() { assertThat(CassandraUtil.annotationKeys(request)).isEmpty(); }