@Override public void onCompleted() { Tracing.getTracer() .getCurrentSpan() .addAnnotation( "Firestore.Query: Completed", ImmutableMap.of( "numDocuments", AttributeValue.longAttributeValue(numDocuments))); documentObserver.onCompleted(readTime); } };
static ImmutableMap<String, AttributeValue> getExceptionAnnotations(RuntimeException e) { if (e instanceof SpannerException) { return ImmutableMap.of( "Status", AttributeValue.stringAttributeValue(((SpannerException) e).getErrorCode().toString())); } return ImmutableMap.of(); }
"Firestore.Query: Start", ImmutableMap.of( "transactional", AttributeValue.booleanAttributeValue(transactionId != null)));
private static ImmutableMap<String, AttributeValue> sampleAttributes() { return ImmutableMap.of( "BOOL", AttributeValue.booleanAttributeValue(false), "LONG", AttributeValue.longAttributeValue(Long.MAX_VALUE), "STRING", AttributeValue.stringAttributeValue( "Judge of a man by his questions rather than by his answers. -- Voltaire")); }
"Attempt started", ImmutableMap.of("attempt", AttributeValue.longAttributeValue(0))); "Connection selected", ImmutableMap.of("id", AttributeValue.longAttributeValue(1))); "Attempt failed, scheduling next attempt", ImmutableMap.of( "attempt", AttributeValue.longAttributeValue(0), "delay ms", AttributeValue.longAttributeValue(5), "status", AttributeValue.stringAttributeValue("DEADLINE_EXCEEDED"))); "Attempt started", ImmutableMap.of("attempt", AttributeValue.longAttributeValue(1))); "Connection selected", ImmutableMap.of("id", AttributeValue.longAttributeValue(2))); "Attempt succeeded", ImmutableMap.of("attempt", AttributeValue.longAttributeValue(1))); .putAttributes(ImmutableMap.of("attempt count", AttributeValue.longAttributeValue(2))); verify(span).end();
@Test public void attributeValue_ToString() { AttributeValue attribute = AttributeValue.stringAttributeValue("MyStringAttributeValue"); assertThat(attribute.toString()).contains("MyStringAttributeValue"); attribute = AttributeValue.booleanAttributeValue(true); assertThat(attribute.toString()).contains("true"); attribute = AttributeValue.longAttributeValue(123456L); assertThat(attribute.toString()).contains("123456"); attribute = AttributeValue.doubleAttributeValue(1.23456); assertThat(attribute.toString()).contains("1.23456"); } }
@Test public void longAttributeValue() { AttributeValue attribute = AttributeValue.longAttributeValue(123456L); attribute.match( new Function<String, Object>() { @Override @Nullable public Object apply(String stringValue) { fail("Expected a Long"); return null; } }, new Function<Boolean, Object>() { @Override @Nullable public Object apply(Boolean booleanValue) { fail("Expected a Long"); return null; } }, new Function<Long, Object>() { @Override @Nullable public Object apply(Long longValue) { assertThat(longValue).isEqualTo(123456L); return null; } }, Functions.throwIllegalArgumentException()); }
@Test public void stringAttributeValue() { AttributeValue attribute = AttributeValue.stringAttributeValue("MyStringAttributeValue"); attribute.match( new Function<String, Object>() { @Override @Nullable public Object apply(String stringValue) { assertThat(stringValue).isEqualTo("MyStringAttributeValue"); return null; } }, new Function<Boolean, Object>() { @Override @Nullable public Object apply(Boolean booleanValue) { fail("Expected a String"); return null; } }, new Function<Long, Object>() { @Override @Nullable public Object apply(Long longValue) { fail("Expected a String"); return null; } }, Functions.throwIllegalArgumentException()); }
@Before public void setUp() { attributesMap.put("MyAttributeKey1", AttributeValue.longAttributeValue(10)); attributesMap.put("MyAttributeKey2", AttributeValue.booleanAttributeValue(true)); attributes = Attributes.create(attributesMap, 1); annotationsList.add(SpanData.TimedEvent.create(eventTimestamp1, annotation)); annotationsList.add(SpanData.TimedEvent.create(eventTimestamp3, annotation)); annotations = TimedEvents.create(annotationsList, 2); networkEventsList.add(SpanData.TimedEvent.create(eventTimestamp1, recvNetworkEvent)); networkEventsList.add(SpanData.TimedEvent.create(eventTimestamp2, sentNetworkEvent)); networkEvents = TimedEvents.create(networkEventsList, 3); messageEventsList.add(SpanData.TimedEvent.create(eventTimestamp1, recvMessageEvent)); messageEventsList.add(SpanData.TimedEvent.create(eventTimestamp2, sentMessageEvent)); messageEvents = TimedEvents.create(messageEventsList, 3); linksList.add(Link.fromSpanContext(spanContext, Type.CHILD_LINKED_SPAN)); links = Links.create(linksList, 0); }
@javax.annotation.Nullable private static String attributeValueToString(AttributeValue attributeValue) { return attributeValue.match( returnToString, returnToString, returnToString, returnToString, Functions.</*@Nullable*/ String>returnNull()); }
@Test public void booleanAttributeValue() { AttributeValue attribute = AttributeValue.booleanAttributeValue(true); attribute.match( new Function<String, Object>() { @Override @Nullable public Object apply(String stringValue) { fail("Expected a Boolean"); return null; } }, new Function<Boolean, Object>() { @Override @Nullable public Object apply(Boolean booleanValue) { assertThat(booleanValue).isTrue(); return null; } }, new Function<Long, Object>() { @Override @Nullable public Object apply(Long longValue) { fail("Expected a Boolean"); return null; } }, Functions.throwIllegalArgumentException()); }
@Test public void doubleAttributeValue_DeprecatedMatchFunction() { AttributeValue attribute = AttributeValue.doubleAttributeValue(1.23456); attribute.match( new Function<String, Object>() { @Override
@Before public void setUp() { MockitoAnnotations.initMocks(this); attributes.put( "MyStringAttributeKey", AttributeValue.stringAttributeValue("MyStringAttributeValue")); attributes.put("MyLongAttributeKey", AttributeValue.longAttributeValue(123L)); attributes.put("MyBooleanAttributeKey", AttributeValue.booleanAttributeValue(false)); expectedAttributes.putAll(attributes); expectedAttributes.put( "MySingleStringAttributeKey", AttributeValue.stringAttributeValue("MySingleStringAttributeValue")); }
@Test public void testFailureExample() { tracer.attemptStarted(0); tracer.connectionSelected(1); ApiException error0 = new NotFoundException("not found", null, new FakeStatusCode(Code.NOT_FOUND), false); tracer.attemptPermanentFailure(error0); tracer.operationFailed(error0); verify(span) .addAnnotation( "Attempt started", ImmutableMap.of("attempt", AttributeValue.longAttributeValue(0))); verify(span) .addAnnotation( "Connection selected", ImmutableMap.of("id", AttributeValue.longAttributeValue(1))); verify(span) .addAnnotation( "Attempt failed, error not retryable", ImmutableMap.of( "attempt", AttributeValue.longAttributeValue(0), "status", AttributeValue.stringAttributeValue("NOT_FOUND"))); verify(span) .putAttributes(ImmutableMap.of("attempt count", AttributeValue.longAttributeValue(1))); verify(span) .end( EndSpanOptions.builder() .setStatus(Status.NOT_FOUND.withDescription("not found")) .build()); verifyNoMoreInteractions(span); }
@Test public void attributeValue_EqualsAndHashCode() { EqualsTester tester = new EqualsTester(); tester.addEqualityGroup( AttributeValue.stringAttributeValue("MyStringAttributeValue"), AttributeValue.stringAttributeValue("MyStringAttributeValue")); tester.addEqualityGroup(AttributeValue.stringAttributeValue("MyStringAttributeDiffValue")); tester.addEqualityGroup( AttributeValue.booleanAttributeValue(true), AttributeValue.booleanAttributeValue(true)); tester.addEqualityGroup(AttributeValue.booleanAttributeValue(false)); tester.addEqualityGroup( AttributeValue.longAttributeValue(123456L), AttributeValue.longAttributeValue(123456L)); tester.addEqualityGroup(AttributeValue.longAttributeValue(1234567L)); tester.addEqualityGroup( AttributeValue.doubleAttributeValue(1.23456), AttributeValue.doubleAttributeValue(1.23456)); tester.addEqualityGroup(AttributeValue.doubleAttributeValue(1.234567)); tester.testEquals(); }
@javax.annotation.Nullable private static AttributeValue toAttributeValueProto( io.opencensus.trace.AttributeValue attributeValue) { return attributeValue.match( stringAttributeValueFunction, booleanAttributeValueFunction, longAttributeValueFunction, doubleAttributeValueFunction, Functions.</*@Nullable*/ AttributeValue>returnNull()); }
@Test public void doubleAttributeValue() { AttributeValue attribute = AttributeValue.doubleAttributeValue(1.23456); attribute.match( new Function<String, Object>() { @Override
private void backoff(Context context, BackOff backoff) { long delay = txn.getRetryDelayInMillis(backoff); txn = session.newTransaction(); span.addAnnotation( "Backing off", ImmutableMap.of("Delay", AttributeValue.longAttributeValue(delay))); sleeper.backoffSleep(context, delay); } }
@Before public void setUp() { attributesMap.put("MyAttributeKey0", AttributeValue.stringAttributeValue("MyStringAttribute")); attributesMap.put("MyAttributeKey1", AttributeValue.longAttributeValue(10)); attributesMap.put("MyAttributeKey2", AttributeValue.booleanAttributeValue(true)); }
private Annotation sessionAnnotation(Session session) { AttributeValue sessionId = AttributeValue.stringAttributeValue(session.getName()); return Annotation.fromDescriptionAndAttributes( "Using Session", ImmutableMap.of("sessionId", sessionId)); }