use of io.opencensus.tags.TagContext in project instrumentation-java by census-instrumentation.
the class OcAgentExportersQuickStart method recordTaggedStat.
private static void recordTaggedStat(TagKey key, String value, MeasureLong ml, long n) {
TagContext context = tagger.emptyBuilder().put(key, TagValue.create(value)).build();
statsRecorder.newMeasureMap().put(ml, n).record(context);
}
use of io.opencensus.tags.TagContext in project instrumentation-java by census-instrumentation.
the class OcAgentExportersQuickStart method recordTaggedStat.
private static void recordTaggedStat(TagKey key, String value, MeasureDouble md, double d) {
TagContext context = tagger.emptyBuilder().put(key, TagValue.create(value)).build();
statsRecorder.newMeasureMap().put(md, d).record(context);
}
use of io.opencensus.tags.TagContext in project instrumentation-java by census-instrumentation.
the class OcAgentExportersQuickStart method recordStat.
private static void recordStat(MeasureLong ml, Long n) {
TagContext empty = tagger.emptyBuilder().build();
statsRecorder.newMeasureMap().put(ml, n).record(empty);
}
use of io.opencensus.tags.TagContext in project instrumentation-java by census-instrumentation.
the class TagContextExample method main.
/**
* Main method.
*
* @param args the main arguments.
*/
public static void main(String[] args) {
System.out.println("Hello Stats World");
System.out.println("Default Tags: " + tagger.empty());
System.out.println("Current Tags: " + tagger.getCurrentTagContext());
TagContext tags1 = tagger.emptyBuilder().put(K1, V1).put(K2, V2).build();
try (Scope scopedTagCtx1 = tagger.withTagContext(tags1)) {
System.out.println(" Current Tags: " + tagger.getCurrentTagContext());
System.out.println(" Current == Default + tags1: " + tagger.getCurrentTagContext().equals(tags1));
TagContext tags2 = tagger.toBuilder(tags1).put(K3, V3).put(K4, V4).build();
try (Scope scopedTagCtx2 = tagger.withTagContext(tags2)) {
System.out.println(" Current Tags: " + tagger.getCurrentTagContext());
System.out.println(" Current == Default + tags1 + tags2: " + tagger.getCurrentTagContext().equals(tags2));
statsRecorder.newMeasureMap().put(M1, 0.2).put(M2, 0.4).record();
}
}
System.out.println("Current == Default: " + tagger.getCurrentTagContext().equals(tagger.empty()));
}
use of io.opencensus.tags.TagContext in project instrumentation-java by census-instrumentation.
the class StatsRecorderImplTest method recordWithAttachments.
private void recordWithAttachments() {
TagContext context = new SimpleTagContext(Tag.create(KEY, VALUE));
// The test Distribution has bucket boundaries [-10.0, 0.0, 10.0].
// 1st second.
testClock.advanceTime(ONE_SECOND);
// -1.0 is in the 2nd bucket [-10.0, 0.0).
statsRecorder.newMeasureMap().put(MEASURE_DOUBLE, -1.0).putAttachment("k1", ATTACHMENT_VALUE_1).record(context);
// 2nd second.
testClock.advanceTime(ONE_SECOND);
// 1.0 is in the 3rd bucket [0.0, 10.0).
statsRecorder.newMeasureMap().put(MEASURE_DOUBLE, 1.0).putAttachment("k2", ATTACHMENT_VALUE_2).record(context);
// 3rd second.
testClock.advanceTime(ONE_SECOND);
// 12.0 is in the 4th bucket [10.0, +Inf).
statsRecorder.newMeasureMap().put(MEASURE_DOUBLE, 12.0).putAttachment("k1", ATTACHMENT_VALUE_3).record(context);
// 4th second.
testClock.advanceTime(ONE_SECOND);
// -20.0 is in the 1st bucket [-Inf, -10.0).
statsRecorder.newMeasureMap().put(MEASURE_DOUBLE, -20.0).putAttachment("k3", ATTACHMENT_VALUE_1).record(context);
// 5th second.
testClock.advanceTime(ONE_SECOND);
// -5.0 is in the 2nd bucket [-10.0, 0), should overwrite the previous exemplar -1.0.
statsRecorder.newMeasureMap().put(MEASURE_DOUBLE, -5.0).putAttachment("k3", ATTACHMENT_VALUE_3).record(context);
// 6th second.
testClock.advanceTime(ONE_SECOND);
// -3.0 is in the 2nd bucket [-10.0, 0), but this value doesn't come with attachments, so it
// shouldn't overwrite the previous exemplar (-5.0).
statsRecorder.newMeasureMap().put(MEASURE_DOUBLE, -3.0).record(context);
}
Aggregations