static ImmutableMap<String, AttributeValue> getExceptionAnnotations(RuntimeException e) { if (e instanceof SpannerException) { return ImmutableMap.of( "Status", AttributeValue.stringAttributeValue(((SpannerException) e).getErrorCode().toString())); } return ImmutableMap.of(); }
private Annotation sessionAnnotation(Session session) { AttributeValue sessionId = AttributeValue.stringAttributeValue(session.getName()); return Annotation.fromDescriptionAndAttributes( "Using Session", ImmutableMap.of("sessionId", sessionId)); }
static Map<String, AttributeValue> getTransactionAnnotations(Transaction t) { return ImmutableMap.of( "Id", AttributeValue.stringAttributeValue(t.getId().toStringUtf8()), "Timestamp", AttributeValue.stringAttributeValue(Timestamp.fromProto(t.getReadTimestamp()).toString())); }
static ImmutableMap<String, AttributeValue> getExceptionAnnotations(SpannerException e) { return ImmutableMap.of( "Status", AttributeValue.stringAttributeValue(e.getErrorCode().toString())); }
void ensureTxn() { if (transactionId == null) { span.addAnnotation("Creating Transaction"); try { transactionId = session.beginTransaction(); span.addAnnotation( "Transaction Creation Done", ImmutableMap.of( "Id", AttributeValue.stringAttributeValue(transactionId.toStringUtf8()))); txnLogger.log( Level.FINER, "Started transaction {0}", txnLogger.isLoggable(Level.FINER) ? transactionId.asReadOnlyByteBuffer() : null); } catch (SpannerException e) { span.addAnnotation("Transaction Creation Failed", TraceUtil.getExceptionAnnotations(e)); throw e; } } else { span.addAnnotation( "Transaction Initialized", ImmutableMap.of( "Id", AttributeValue.stringAttributeValue(transactionId.toStringUtf8()))); txnLogger.log( Level.FINER, "Using prepared transaction {0}", txnLogger.isLoggable(Level.FINER) ? transactionId.asReadOnlyByteBuffer() : null); } }
ImmutableMap.of( "ResumeToken", AttributeValue.stringAttributeValue( resumeToken == null ? "null" : resumeToken.toStringUtf8()))); try (Scope s = tracer.withSpan(span)) {
private static void putAttributeIfNotEmptyOrNull(Span span, String key, @Nullable String value) { if (value != null && !value.isEmpty()) { span.putAttribute(key, AttributeValue.stringAttributeValue(value)); } }
private static void putAttributeIfNotEmptyOrNull(Span span, String key, @Nullable String value) { if (value != null && !value.isEmpty()) { span.putAttribute(key, AttributeValue.stringAttributeValue(value)); } }
static ImmutableMap<String, AttributeValue> getExceptionAnnotations(RuntimeException e) { if (e instanceof SpannerException) { return ImmutableMap.of( "Status", AttributeValue.stringAttributeValue(((SpannerException) e).getErrorCode().toString())); } return ImmutableMap.of(); }
static Map<String, AttributeValue> getTransactionAnnotations(Transaction t) { return ImmutableMap.of( "Id", AttributeValue.stringAttributeValue(t.getId().toStringUtf8()), "Timestamp", AttributeValue.stringAttributeValue(Timestamp.fromProto(t.getReadTimestamp()).toString())); }
private Annotation sessionAnnotation(Session session) { AttributeValue sessionId = AttributeValue.stringAttributeValue(session.getName()); return Annotation.fromDescriptionAndAttributes( "Using Session", ImmutableMap.of("sessionId", sessionId)); }
private void populateError(Map<String, AttributeValue> attributes, Throwable error) { if (error == null) { attributes.put("status", null); return; } Status status = convertErrorToStatus(error); attributes.put( "status", AttributeValue.stringAttributeValue(status.getCanonicalCode().toString())); }
private void populateError(Map<String, AttributeValue> attributes, Throwable error) { if (error == null) { attributes.put("status", null); return; } Status status = convertErrorToStatus(error); attributes.put( "status", AttributeValue.stringAttributeValue(status.getCanonicalCode().toString())); }
@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")); }
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")); }
@Before public void setUp() { attributesMap.put("MyAttributeKey0", AttributeValue.stringAttributeValue("MyStringAttribute")); attributesMap.put("MyAttributeKey1", AttributeValue.longAttributeValue(10)); attributesMap.put("MyAttributeKey2", AttributeValue.booleanAttributeValue(true)); }
@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 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 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); }
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")))); }