use of io.opencensus.tags.TagContext in project instrumentation-java by census-instrumentation.
the class RecordDifferentTagValuesBenchmark method record.
private static MeasureMap record(Data data, Measure.MeasureDouble measure, double value) {
MeasureMap map = data.recorder.newMeasureMap();
map.put(measure, value);
for (TagContext tags : data.contexts) {
map.record(tags);
}
return map;
}
use of io.opencensus.tags.TagContext in project instrumentation-java by census-instrumentation.
the class ContextUtilsTest method testGetCurrentTagContext_ContextSetToNull.
@Test
public void testGetCurrentTagContext_ContextSetToNull() {
Context orig = ContextUtils.withValue(Context.current(), null).attach();
try {
TagContext tags = ContextUtils.getValue(Context.current());
assertThat(tags).isNotNull();
assertThat(asList(tags)).isEmpty();
} finally {
Context.current().detach(orig);
}
}
use of io.opencensus.tags.TagContext in project instrumentation-java by census-instrumentation.
the class StatsRecorderImplTest method record_CurrentContextSet.
@Test
public void record_CurrentContextSet() {
View view = View.create(VIEW_NAME, "description", MEASURE_DOUBLE, Sum.create(), Arrays.asList(KEY), Cumulative.create());
viewManager.registerView(view);
TagContext tags = new SimpleTagContext(Tag.create(KEY, VALUE));
Context orig = ContextUtils.withValue(Context.current(), tags).attach();
try {
statsRecorder.newMeasureMap().put(MEASURE_DOUBLE, 1.0).record();
} finally {
Context.current().detach(orig);
}
ViewData viewData = viewManager.getView(VIEW_NAME);
// record() should have used the given TagContext.
assertThat(viewData.getAggregationMap().keySet()).containsExactly(Arrays.asList(VALUE));
}
use of io.opencensus.tags.TagContext in project instrumentation-java by census-instrumentation.
the class ViewManagerImplTest method getViewDoesNotClearStats.
@Test
public void getViewDoesNotClearStats() {
View view = createCumulativeView(VIEW_NAME, MEASURE_DOUBLE, DISTRIBUTION, Arrays.asList(KEY));
clock.setTime(Timestamp.create(10, 0));
viewManager.registerView(view);
TagContext tags = tagger.emptyBuilder().put(KEY, VALUE).build();
statsRecorder.newMeasureMap().put(MEASURE_DOUBLE, 0.1).record(tags);
clock.setTime(Timestamp.create(11, 0));
ViewData viewData1 = viewManager.getView(VIEW_NAME);
assertThat(viewData1.getWindowData()).isEqualTo(CumulativeData.create(Timestamp.create(10, 0), Timestamp.create(11, 0)));
StatsTestUtil.assertAggregationMapEquals(viewData1.getAggregationMap(), ImmutableMap.of(Arrays.asList(VALUE), StatsTestUtil.createAggregationData(DISTRIBUTION, MEASURE_DOUBLE, 0.1)), EPSILON);
statsRecorder.newMeasureMap().put(MEASURE_DOUBLE, 0.2).record(tags);
clock.setTime(Timestamp.create(12, 0));
ViewData viewData2 = viewManager.getView(VIEW_NAME);
// The second view should have the same start time as the first view, and it should include both
// recorded values:
assertThat(viewData2.getWindowData()).isEqualTo(CumulativeData.create(Timestamp.create(10, 0), Timestamp.create(12, 0)));
StatsTestUtil.assertAggregationMapEquals(viewData2.getAggregationMap(), ImmutableMap.of(Arrays.asList(VALUE), StatsTestUtil.createAggregationData(DISTRIBUTION, MEASURE_DOUBLE, 0.1, 0.2)), EPSILON);
}
use of io.opencensus.tags.TagContext in project instrumentation-java by census-instrumentation.
the class TagContextDeserializationTest method testDeserializeMultipleTags.
@Test
public void testDeserializeMultipleTags() throws TagContextDeserializationException {
ByteArrayDataOutput output = ByteStreams.newDataOutput();
output.write(BinarySerializationUtils.VERSION_ID);
encodeTagToOutput("Key1", "Value1", output);
encodeTagToOutput("Key2", "Value2", output);
TagContext expected = tagger.emptyBuilder().put(TagKey.create("Key1"), TagValue.create("Value1")).put(TagKey.create("Key2"), TagValue.create("Value2")).build();
assertThat(serializer.fromByteArray(output.toByteArray())).isEqualTo(expected);
}
Aggregations