use of io.opencensus.tags.TagContextBuilder in project instrumentation-java by census-instrumentation.
the class TagMapImplTest method put_nullKey.
@Test
public void put_nullKey() {
TagContext tags = new TagMapImpl(ImmutableMap.of(K1, VM1));
TagContextBuilder builder = tagger.toBuilder(tags);
thrown.expect(NullPointerException.class);
thrown.expectMessage("key");
builder.put(null, V2);
}
use of io.opencensus.tags.TagContextBuilder in project instrumentation-java by census-instrumentation.
the class TagMapImplTest method remove_nullKey.
@Test
public void remove_nullKey() {
TagContext tags = new TagMapImpl(ImmutableMap.of(K1, VM1));
TagContextBuilder builder = tagger.toBuilder(tags);
thrown.expect(NullPointerException.class);
thrown.expectMessage("key");
builder.remove(null);
}
use of io.opencensus.tags.TagContextBuilder in project instrumentation-java by census-instrumentation.
the class TaggerImplTest method currentBuilder_RemoveDuplicateTags.
@Test
public void currentBuilder_RemoveDuplicateTags() {
Tag tag1 = Tag.create(K1, V1);
Tag tag2 = Tag.create(K1, V2);
TagContext tagContextWithDuplicateTags = new SimpleTagContext(tag1, tag2);
TagContextBuilder result = getResultOfCurrentBuilder(tagContextWithDuplicateTags);
assertThat(tagContextToList(result.build())).containsExactly(tag2);
}
use of io.opencensus.tags.TagContextBuilder in project instrumentation-java by census-instrumentation.
the class QuickStart method main.
/**
* Main launcher for the QuickStart example.
*/
public static void main(String[] args) throws InterruptedException {
TagContextBuilder tagContextBuilder = tagger.currentBuilder().put(FRONTEND_KEY, TagValue.create("mobile-ios9.3.5"));
SpanBuilder spanBuilder = tracer.spanBuilder("my.org/ProcessVideo").setRecordEvents(true).setSampler(Samplers.alwaysSample());
viewManager.registerView(VIDEO_SIZE_VIEW);
LoggingTraceExporter.register();
// Record the processed video size.
try (Scope scopedTags = tagContextBuilder.buildScoped();
Scope scopedSpan = spanBuilder.startScopedSpan()) {
tracer.getCurrentSpan().addAnnotation("Start processing video.");
// Sleep for [0,10] milliseconds to fake work.
Thread.sleep(new Random().nextInt(10) + 1);
statsRecorder.newMeasureMap().put(VIDEO_SIZE, 25 * MiB).record();
tracer.getCurrentSpan().addAnnotation("Finished processing video.");
} catch (Exception e) {
tracer.getCurrentSpan().addAnnotation("Exception thrown when processing video.");
tracer.getCurrentSpan().setStatus(Status.UNKNOWN);
logger.severe(e.getMessage());
}
logger.info("Wait longer than the reporting duration...");
// Wait for a duration longer than reporting duration (5s) to ensure spans are exported.
// TODO(songya): remove the gap once we add a shutdown hook for exporting unflushed spans.
Thread.sleep(5100);
ViewData viewData = viewManager.getView(VIDEO_SIZE_VIEW_NAME);
logger.info(String.format("Recorded stats for %s:\n %s", VIDEO_SIZE_VIEW_NAME.asString(), viewData));
}
use of io.opencensus.tags.TagContextBuilder in project instrumentation-java by census-instrumentation.
the class TagContextSerializationTest method testSerializeTooLargeTagContext.
@Test
public void testSerializeTooLargeTagContext() throws TagContextSerializationException {
TagContextBuilder builder = tagger.emptyBuilder();
for (int i = 0; i < BinarySerializationUtils.TAGCONTEXT_SERIALIZED_SIZE_LIMIT / 8 - 1; i++) {
// Each tag will be with format {key : "0123", value : "0123"}, so the length of it is 8.
String str;
if (i < 10) {
str = "000" + i;
} else if (i < 100) {
str = "00" + i;
} else if (i < 1000) {
str = "0" + i;
} else {
str = String.valueOf(i);
}
builder.put(TagKey.create(str), TagValue.create(str));
}
// The last tag will be of size 9, so the total size of the TagContext (8193) will be one byte
// more than limit.
builder.put(TagKey.create("last"), TagValue.create("last1"));
TagContext tagContext = builder.build();
thrown.expect(TagContextSerializationException.class);
thrown.expectMessage("Size of TagContext exceeds the maximum serialized size ");
serializer.toByteArray(tagContext);
}
Aggregations