use of io.opencensus.common.Timestamp in project instrumentation-java by census-instrumentation.
the class StackdriverExportUtilsTest method convertTimestamp.
@Test
public void convertTimestamp() {
Timestamp censusTimestamp1 = Timestamp.create(100, 3000);
assertThat(StackdriverExportUtils.convertTimestamp(censusTimestamp1)).isEqualTo(com.google.protobuf.Timestamp.newBuilder().setSeconds(100).setNanos(3000).build());
// Stackdriver doesn't allow negative values, instead it will replace the negative values
// by returning a default instance.
Timestamp censusTimestamp2 = Timestamp.create(-100, 3000);
assertThat(StackdriverExportUtils.convertTimestamp(censusTimestamp2)).isEqualTo(com.google.protobuf.Timestamp.newBuilder().build());
}
use of io.opencensus.common.Timestamp in project instrumentation-java by census-instrumentation.
the class InstanaExporterHandler method convertToJson.
static String convertToJson(Collection<SpanData> spanDataList) {
StringBuilder sb = new StringBuilder();
sb.append('[');
for (final SpanData span : spanDataList) {
final SpanContext spanContext = span.getContext();
final SpanId parentSpanId = span.getParentSpanId();
final Timestamp startTimestamp = span.getStartTimestamp();
final Timestamp endTimestamp = span.getEndTimestamp();
final Status status = span.getStatus();
if (status == null || endTimestamp == null) {
continue;
}
if (sb.length() > 1) {
sb.append(',');
}
sb.append('{');
sb.append("\"spanId\":\"").append(encodeSpanId(spanContext.getSpanId())).append("\",");
sb.append("\"traceId\":\"").append(encodeTraceId(spanContext.getTraceId())).append("\",");
if (parentSpanId != null) {
sb.append("\"parentId\":\"").append(encodeSpanId(parentSpanId)).append("\",");
}
sb.append("\"timestamp\":").append(toMillis(startTimestamp)).append(',');
sb.append("\"duration\":").append(toMillis(startTimestamp, endTimestamp)).append(',');
sb.append("\"name\":\"").append(toSpanName(span)).append("\",");
sb.append("\"type\":\"").append(toSpanType(span)).append('"');
if (!status.isOk()) {
sb.append(",\"error\":").append("true");
}
Map<String, AttributeValue> attributeMap = span.getAttributes().getAttributeMap();
if (attributeMap.size() > 0) {
StringBuilder dataSb = new StringBuilder();
dataSb.append('{');
for (Entry<String, AttributeValue> entry : attributeMap.entrySet()) {
if (dataSb.length() > 1) {
dataSb.append(',');
}
dataSb.append("\"").append(entry.getKey()).append("\":\"").append(attributeValueToString(entry.getValue())).append("\"");
}
dataSb.append('}');
sb.append(",\"data\":").append(dataSb);
}
sb.append('}');
}
sb.append(']');
return sb.toString();
}
use of io.opencensus.common.Timestamp in project instrumentation-java by census-instrumentation.
the class OcAgentNodeUtils method getNodeInfo.
// Creates a Node with information from the OpenCensus library and environment variables.
static Node getNodeInfo(String serviceName) {
String jvmName = ManagementFactory.getRuntimeMXBean().getName();
Timestamp censusTimestamp = Timestamp.fromMillis(System.currentTimeMillis());
return Node.newBuilder().setIdentifier(getProcessIdentifier(jvmName, censusTimestamp)).setLibraryInfo(getLibraryInfo(OpenCensusLibraryInformation.VERSION)).setServiceInfo(getServiceInfo(serviceName)).build();
}
use of io.opencensus.common.Timestamp in project instrumentation-java by census-instrumentation.
the class ViewManagerImplTest method settingStateToDisabledWillClearStats.
@SuppressWarnings("deprecation")
private void settingStateToDisabledWillClearStats(View view) {
Timestamp timestamp1 = Timestamp.create(1, 0);
clock.setTime(timestamp1);
viewManager.registerView(view);
statsRecorder.newMeasureMap().put(MEASURE_DOUBLE, 1.1).record(tagger.emptyBuilder().put(KEY, VALUE).build());
StatsTestUtil.assertAggregationMapEquals(viewManager.getView(view.getName()).getAggregationMap(), ImmutableMap.of(Arrays.asList(VALUE), StatsTestUtil.createAggregationData(view.getAggregation(), view.getMeasure(), 1.1)), EPSILON);
Timestamp timestamp2 = Timestamp.create(2, 0);
clock.setTime(timestamp2);
// This will clear stats.
statsComponent.setState(StatsCollectionState.DISABLED);
assertThat(viewManager.getView(view.getName())).isEqualTo(createEmptyViewData(view));
Timestamp timestamp3 = Timestamp.create(3, 0);
clock.setTime(timestamp3);
statsComponent.setState(StatsCollectionState.ENABLED);
Timestamp timestamp4 = Timestamp.create(4, 0);
clock.setTime(timestamp4);
// This ViewData does not have any stats, but it should not be an empty ViewData, since it has
// non-zero TimeStamps.
ViewData viewData = viewManager.getView(view.getName());
assertThat(viewData.getAggregationMap()).isEmpty();
AggregationWindowData windowData = viewData.getWindowData();
if (windowData instanceof CumulativeData) {
assertThat(windowData).isEqualTo(CumulativeData.create(timestamp3, timestamp4));
} else {
assertThat(windowData).isEqualTo(IntervalData.create(timestamp4));
}
}
use of io.opencensus.common.Timestamp in project instrumentation-java by census-instrumentation.
the class IntervalBucketTest method preventCallingGetFractionOnFutureBuckets.
@Test
public void preventCallingGetFractionOnFutureBuckets() {
IntervalBucket bucket = new IntervalBucket(START, MINUTE, MEAN, MEASURE_DOUBLE);
Timestamp thirtySecondsBeforeStart = Timestamp.create(30, 0);
thrown.expect(IllegalArgumentException.class);
bucket.getFraction(thirtySecondsBeforeStart);
}
Aggregations