private Annotation sessionAnnotation(Session session) { AttributeValue sessionId = AttributeValue.stringAttributeValue(session.getName()); return Annotation.fromDescriptionAndAttributes( "Using Session", ImmutableMap.of("sessionId", sessionId)); }
private Annotation sessionAnnotation(Session session) { AttributeValue sessionId = AttributeValue.stringAttributeValue(session.getName()); return Annotation.fromDescriptionAndAttributes( "Using Session", ImmutableMap.of("sessionId", sessionId)); }
@Override public void addAnnotation(String description, Map<String, AttributeValue> attributes) { Preconditions.checkNotNull(description, "description"); Preconditions.checkNotNull(attributes, "attribute"); synchronized (this) { if (hasBeenEnded) { logger.log(Level.FINE, "Calling addAnnotation() on an ended Span."); return; } getInitializedAnnotations() .addEvent( new EventWithNanoTime<Annotation>( clock.nowNanos(), Annotation.fromDescriptionAndAttributes(description, attributes))); } }
@Override public void addAnnotation(String description, Map<String, AttributeValue> attributes) { Preconditions.checkNotNull(description, "description"); Preconditions.checkNotNull(attributes, "attribute"); synchronized (this) { if (hasBeenEnded) { logger.log(Level.FINE, "Calling addAnnotation() on an ended Span."); return; } getInitializedAnnotations() .addEvent( new EventWithNanoTime<Annotation>( clock.nowNanos(), Annotation.fromDescriptionAndAttributes(description, attributes))); } }
@Test(expected = NullPointerException.class) public void fromDescriptionAndAttributes_NullDescription() { Annotation.fromDescriptionAndAttributes(null, Collections.<String, AttributeValue>emptyMap()); }
@Test(expected = NullPointerException.class) public void fromDescriptionAndAttributes_NullAttributes() { Annotation.fromDescriptionAndAttributes("", null); }
@Test public void annotation_ToString() { Annotation annotation = Annotation.fromDescription("MyAnnotationText"); assertThat(annotation.toString()).contains("MyAnnotationText"); Map<String, AttributeValue> attributes = new HashMap<String, AttributeValue>(); attributes.put( "MyStringAttributeKey", AttributeValue.stringAttributeValue("MyStringAttributeValue")); annotation = Annotation.fromDescriptionAndAttributes("MyAnnotationText2", attributes); assertThat(annotation.toString()).contains("MyAnnotationText2"); assertThat(annotation.toString()).contains(attributes.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 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 annotation_EqualsAndHashCode() { EqualsTester tester = new EqualsTester(); Map<String, AttributeValue> attributes = new HashMap<String, AttributeValue>(); attributes.put( "MyStringAttributeKey", AttributeValue.stringAttributeValue("MyStringAttributeValue")); tester .addEqualityGroup( Annotation.fromDescription("MyAnnotationText"), Annotation.fromDescriptionAndAttributes( "MyAnnotationText", Collections.<String, AttributeValue>emptyMap())) .addEqualityGroup( Annotation.fromDescriptionAndAttributes("MyAnnotationText", attributes), Annotation.fromDescriptionAndAttributes("MyAnnotationText", attributes)) .addEqualityGroup(Annotation.fromDescription("MyAnnotationText2")); tester.testEquals(); }
private static SpanData.TimedEvent<Annotation> sampleAnnotation() { return SpanData.TimedEvent.create( Timestamp.create(1519629872L, 987654321), Annotation.fromDescriptionAndAttributes( "annotation #1", ImmutableMap.of( "bool", AttributeValue.booleanAttributeValue(true), "long", AttributeValue.longAttributeValue(1337L), "string", AttributeValue.stringAttributeValue( "Kind words do not cost much. Yet they accomplish much. -- Pascal")))); }
/** * Calls {@link BigtableAsyncRpc#newCall(CallOptions)} and * {@link BigtableAsyncRpc#start(Object, io.grpc.ClientCall.Listener, Metadata, ClientCall)} } * with this as the listener so that retries happen correctly. */ protected void run() { try (Scope scope = TRACER.withSpan(operationSpan)) { rpcTimerContext = rpc.getRpcMetrics().timeRpc(); operationSpan.addAnnotation(Annotation.fromDescriptionAndAttributes("rpcStart", ImmutableMap.of("attempt", AttributeValue.longAttributeValue(failedCount)))); Metadata metadata = new Metadata(); metadata.merge(originalMetadata); callWrapper.setCallAndStart(rpc, getRpcCallOptions(), getRetryRequest(), this, metadata); } catch (Exception e) { setException(e); } }
.isEqualTo(timestamp.addNanos(200)); assertThat(spanData.getAnnotations().getEvents().get(1).getEvent()) .isEqualTo(Annotation.fromDescriptionAndAttributes(ANNOTATION_DESCRIPTION, attributes)); assertThat(spanData.getNetworkEvents().getDroppedEventsCount()).isEqualTo(0); assertThat(spanData.getNetworkEvents().getEvents().size()).isEqualTo(1);
.isEqualTo(timestamp.addNanos(200)); assertThat(spanData.getAnnotations().getEvents().get(1).getEvent()) .isEqualTo(Annotation.fromDescriptionAndAttributes(ANNOTATION_DESCRIPTION, attributes)); assertThat(spanData.getNetworkEvents().getDroppedEventsCount()).isEqualTo(0); assertThat(spanData.getNetworkEvents().getEvents().size()).isEqualTo(1);