private static String renderAnnotation(Annotation annotation) { StringBuilder stringBuilder = new StringBuilder(); stringBuilder.append(annotation.getDescription()); if (!annotation.getAttributes().isEmpty()) { stringBuilder.append(" "); stringBuilder.append(renderAttributes(annotation.getAttributes())); } return stringBuilder.toString(); }
@Test public void fromDescriptionAndAttributes_EmptyAttributes() { Annotation annotation = Annotation.fromDescriptionAndAttributes( "MyAnnotationText", Collections.<String, AttributeValue>emptyMap()); assertThat(annotation.getDescription()).isEqualTo("MyAnnotationText"); assertThat(annotation.getAttributes().size()).isEqualTo(0); }
@Test public void fromDescription() { Annotation annotation = Annotation.fromDescription("MyAnnotationText"); assertThat(annotation.getDescription()).isEqualTo("MyAnnotationText"); assertThat(annotation.getAttributes().size()).isEqualTo(0); }
@Test public void fromDescriptionAndAttributes() { Map<String, AttributeValue> attributes = new HashMap<String, AttributeValue>(); attributes.put( "MyStringAttributeKey", AttributeValue.stringAttributeValue("MyStringAttributeValue")); Annotation annotation = Annotation.fromDescriptionAndAttributes("MyAnnotationText", attributes); assertThat(annotation.getDescription()).isEqualTo("MyAnnotationText"); assertThat(annotation.getAttributes()).isEqualTo(attributes); }
@Test public void sqlExecute() throws Exception { // When String sql = "select 1"; Sample sample = (Sample) context.getBean("sample"); sample.execute(sql); // Then List<SpanData> data = handler.waitForExport(1); assertThat(data).isNotNull(); assertThat(data.size()).isEqualTo(1); assertThat(data.get(0).getName()).isEqualTo("execute-4705ea0d"); // sql-{hash of sql statement} List<SpanData.TimedEvent<Annotation>> events = data.get(0).getAnnotations().getEvents(); assertThat(events.size()).isEqualTo(1); assertThat(events.get(0).getEvent().getDescription()).isEqualTo(sql); }
@Test public void sqlQuery() throws Exception { // When String sql = "select 2"; Sample sample = (Sample) context.getBean("sample"); sample.executeQuery(sql); // Then List<SpanData> data = handler.waitForExport(1); assertThat(data).isNotNull(); assertThat(data.size()).isEqualTo(1); assertThat(data.get(0).getName()).isEqualTo("executeQuery-4705ea0e"); SpanData.TimedEvents<Annotation> annotations = data.get(0).getAnnotations(); List<SpanData.TimedEvent<Annotation>> events = annotations.getEvents(); assertThat(events.size()).isEqualTo(1); assertThat(events.get(0).getEvent().getDescription()).isEqualTo(sql); }
@Test public void sqlUpdate() throws Exception { // When String sql = "update content set value = 1"; Sample sample = (Sample) context.getBean("sample"); sample.executeUpdate(sql); // Then List<SpanData> data = handler.waitForExport(1); assertThat(data).isNotNull(); assertThat(data.size()).isEqualTo(1); assertThat(data.get(0).getName()).isEqualTo("executeUpdate-acaeb423"); List<SpanData.TimedEvent<Annotation>> events = data.get(0).getAnnotations().getEvents(); assertThat(events.size()).isEqualTo(1); assertThat(events.get(0).getEvent().getDescription()).isEqualTo(sql); } }
@Test public void handlesException() { // When Sample sample = (Sample) context.getBean("sample"); try { sample.boom(); } catch (Exception ignored) { // ok } // Then List<SpanData> spanList = handler.waitForExport(1); assertThat(spanList).isNotNull(); assertThat(spanList.size()).isEqualTo(1); SpanData spanData = spanList.get(0); assertThat(spanData.getName()).isEqualTo("boom"); assertThat(spanData.getStatus()).isEqualTo(Status.UNKNOWN); SpanData.TimedEvents<Annotation> annotations = spanData.getAnnotations(); assertThat(annotations).isNotNull(); List<SpanData.TimedEvent<Annotation>> events = annotations.getEvents(); assertThat(events.size()).isEqualTo(1); assertThat(events.get(0).getEvent().getDescription()).isEqualTo("error"); }
attributesToTags( event.getEvent().getAttributes(), descriptionToTag(event.getEvent().getDescription()))));
private static TimeEvent toTimeAnnotationProto(TimedEvent<Annotation> timedEvent) { TimeEvent.Builder timeEventBuilder = TimeEvent.newBuilder().setTime(toTimestampProto(timedEvent.getTimestamp())); Annotation annotation = timedEvent.getEvent(); timeEventBuilder.setAnnotation( TimeEvent.Annotation.newBuilder() .setDescription(toTruncatableStringProto(annotation.getDescription())) .setAttributes(toAttributesBuilderProto(annotation.getAttributes(), 0)) .build()); return timeEventBuilder.build(); }
private static TimeEvent toTimeAnnotationProto(TimedEvent<Annotation> timedEvent) { TimeEvent.Builder timeEventBuilder = TimeEvent.newBuilder().setTime(toTimestampProto(timedEvent.getTimestamp())); Annotation annotation = timedEvent.getEvent(); timeEventBuilder.setAnnotation( TimeEvent.Annotation.newBuilder() .setDescription(toTruncatableStringProto(annotation.getDescription())) .setAttributes(toAttributesBuilderProto(annotation.getAttributes(), 0)) .build()); return timeEventBuilder.build(); }
private static TimeEvent toTimeAnnotationProto(TimedEvent<Annotation> timedEvent) { TimeEvent.Builder timeEventBuilder = TimeEvent.newBuilder().setTime(toTimestampProto(timedEvent.getTimestamp())); Annotation annotation = timedEvent.getEvent(); timeEventBuilder.setAnnotation( TimeEvent.Annotation.newBuilder() .setDescription(toTruncatableStringProto(annotation.getDescription())) .setAttributes(toAttributesBuilderProto(annotation.getAttributes(), 0)) .build()); return timeEventBuilder.build(); }
toEpochMicros(annotation.getTimestamp()), annotation.getEvent().getDescription());