Search in sources :

Example 6 with TagContext

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);
}
Also used : TagContext(io.opencensus.tags.TagContext)

Example 7 with TagContext

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);
}
Also used : TagContext(io.opencensus.tags.TagContext)

Example 8 with TagContext

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);
}
Also used : TagContext(io.opencensus.tags.TagContext)

Example 9 with TagContext

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()));
}
Also used : Scope(io.opencensus.common.Scope) TagContext(io.opencensus.tags.TagContext)

Example 10 with TagContext

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);
}
Also used : SimpleTagContext(io.opencensus.implcore.stats.StatsTestUtil.SimpleTagContext) TagContext(io.opencensus.tags.TagContext) SimpleTagContext(io.opencensus.implcore.stats.StatsTestUtil.SimpleTagContext)

Aggregations

TagContext (io.opencensus.tags.TagContext)76 Test (org.junit.Test)56 Tag (io.opencensus.tags.Tag)10 TagContextBuilder (io.opencensus.tags.TagContextBuilder)9 ByteArrayDataOutput (com.google.common.io.ByteArrayDataOutput)7 Context (io.grpc.Context)6 Scope (io.opencensus.common.Scope)5 StatsTestUtil.createEmptyViewData (io.opencensus.implcore.stats.StatsTestUtil.createEmptyViewData)5 View (io.opencensus.stats.View)5 ViewData (io.opencensus.stats.ViewData)5 Metadata (io.grpc.Metadata)3 StatsTestUtils (io.grpc.internal.testing.StatsTestUtils)3 MeasureMap (io.opencensus.stats.MeasureMap)3 TagValue (io.opencensus.tags.TagValue)3 SpanContext (io.opencensus.trace.SpanContext)3 HashMap (java.util.HashMap)3 ServerStreamTracer (io.grpc.ServerStreamTracer)2 CallAttemptsTracerFactory (io.grpc.census.CensusTracingModule.CallAttemptsTracerFactory)2 HttpRequestContext (io.opencensus.contrib.http.HttpRequestContext)2 SimpleTagContext (io.opencensus.implcore.stats.StatsTestUtil.SimpleTagContext)2