use of io.opencensus.trace.config.TraceParams in project instrumentation-java by census-instrumentation.
the class OcAgentExportersQuickStart method configureAlwaysSample.
private static void configureAlwaysSample() {
TraceConfig traceConfig = Tracing.getTraceConfig();
TraceParams activeTraceParams = traceConfig.getActiveTraceParams();
traceConfig.updateActiveTraceParams(activeTraceParams.toBuilder().setSampler(Samplers.alwaysSample()).build());
}
use of io.opencensus.trace.config.TraceParams in project instrumentation-java by census-instrumentation.
the class RecordEventsSpanImplTest method droppingLinks.
@Test
public void droppingLinks() {
final int maxNumberOfLinks = 8;
TraceParams traceParams = TraceParams.DEFAULT.toBuilder().setMaxNumberOfLinks(maxNumberOfLinks).build();
RecordEventsSpanImpl span = RecordEventsSpanImpl.startSpan(spanContext, SPAN_NAME, null, parentSpanId, false, traceParams, startEndHandler, timestampConverter, testClock);
Link link = Link.fromSpanContext(spanContext, Link.Type.CHILD_LINKED_SPAN);
for (int i = 0; i < 2 * maxNumberOfLinks; i++) {
span.addLink(link);
}
SpanData spanData = span.toSpanData();
assertThat(spanData.getLinks().getDroppedLinksCount()).isEqualTo(maxNumberOfLinks);
assertThat(spanData.getLinks().getLinks().size()).isEqualTo(maxNumberOfLinks);
for (int i = 0; i < maxNumberOfLinks; i++) {
assertThat(spanData.getLinks().getLinks().get(i)).isEqualTo(link);
}
span.end();
spanData = span.toSpanData();
assertThat(spanData.getLinks().getDroppedLinksCount()).isEqualTo(maxNumberOfLinks);
assertThat(spanData.getLinks().getLinks().size()).isEqualTo(maxNumberOfLinks);
for (int i = 0; i < maxNumberOfLinks; i++) {
assertThat(spanData.getLinks().getLinks().get(i)).isEqualTo(link);
}
}
use of io.opencensus.trace.config.TraceParams in project instrumentation-java by census-instrumentation.
the class RecordEventsSpanImplTest method droppingAndAddingAttributes.
@Test
public void droppingAndAddingAttributes() {
final int maxNumberOfAttributes = 8;
TraceParams traceParams = TraceParams.DEFAULT.toBuilder().setMaxNumberOfAttributes(maxNumberOfAttributes).build();
RecordEventsSpanImpl span = RecordEventsSpanImpl.startSpan(spanContext, SPAN_NAME, null, parentSpanId, false, traceParams, startEndHandler, timestampConverter, testClock);
for (int i = 0; i < 2 * maxNumberOfAttributes; i++) {
Map<String, AttributeValue> attributes = new HashMap<String, AttributeValue>();
attributes.put("MyStringAttributeKey" + i, AttributeValue.longAttributeValue(i));
span.putAttributes(attributes);
}
SpanData spanData = span.toSpanData();
assertThat(spanData.getAttributes().getDroppedAttributesCount()).isEqualTo(maxNumberOfAttributes);
assertThat(spanData.getAttributes().getAttributeMap().size()).isEqualTo(maxNumberOfAttributes);
for (int i = 0; i < maxNumberOfAttributes; i++) {
assertThat(spanData.getAttributes().getAttributeMap().get("MyStringAttributeKey" + (i + maxNumberOfAttributes))).isEqualTo(AttributeValue.longAttributeValue(i + maxNumberOfAttributes));
}
for (int i = 0; i < maxNumberOfAttributes / 2; i++) {
Map<String, AttributeValue> attributes = new HashMap<String, AttributeValue>();
attributes.put("MyStringAttributeKey" + i, AttributeValue.longAttributeValue(i));
span.putAttributes(attributes);
}
spanData = span.toSpanData();
assertThat(spanData.getAttributes().getDroppedAttributesCount()).isEqualTo(maxNumberOfAttributes * 3 / 2);
assertThat(spanData.getAttributes().getAttributeMap().size()).isEqualTo(maxNumberOfAttributes);
// Test that we still have in the attributes map the latest maxNumberOfAttributes / 2 entries.
for (int i = 0; i < maxNumberOfAttributes / 2; i++) {
assertThat(spanData.getAttributes().getAttributeMap().get("MyStringAttributeKey" + (i + maxNumberOfAttributes * 3 / 2))).isEqualTo(AttributeValue.longAttributeValue(i + maxNumberOfAttributes * 3 / 2));
}
// Test that we have the newest re-added initial entries.
for (int i = 0; i < maxNumberOfAttributes / 2; i++) {
assertThat(spanData.getAttributes().getAttributeMap().get("MyStringAttributeKey" + i)).isEqualTo(AttributeValue.longAttributeValue(i));
}
}
use of io.opencensus.trace.config.TraceParams in project instrumentation-java by census-instrumentation.
the class RecordEventsSpanImplTest method droppingAttributes.
@Test
public void droppingAttributes() {
final int maxNumberOfAttributes = 8;
TraceParams traceParams = TraceParams.DEFAULT.toBuilder().setMaxNumberOfAttributes(maxNumberOfAttributes).build();
RecordEventsSpanImpl span = RecordEventsSpanImpl.startSpan(spanContext, SPAN_NAME, null, parentSpanId, false, traceParams, startEndHandler, timestampConverter, testClock);
for (int i = 0; i < 2 * maxNumberOfAttributes; i++) {
Map<String, AttributeValue> attributes = new HashMap<String, AttributeValue>();
attributes.put("MyStringAttributeKey" + i, AttributeValue.longAttributeValue(i));
span.putAttributes(attributes);
}
SpanData spanData = span.toSpanData();
assertThat(spanData.getAttributes().getDroppedAttributesCount()).isEqualTo(maxNumberOfAttributes);
assertThat(spanData.getAttributes().getAttributeMap().size()).isEqualTo(maxNumberOfAttributes);
for (int i = 0; i < maxNumberOfAttributes; i++) {
assertThat(spanData.getAttributes().getAttributeMap().get("MyStringAttributeKey" + (i + maxNumberOfAttributes))).isEqualTo(AttributeValue.longAttributeValue(i + maxNumberOfAttributes));
}
span.end();
spanData = span.toSpanData();
assertThat(spanData.getAttributes().getDroppedAttributesCount()).isEqualTo(maxNumberOfAttributes);
assertThat(spanData.getAttributes().getAttributeMap().size()).isEqualTo(maxNumberOfAttributes);
for (int i = 0; i < maxNumberOfAttributes; i++) {
assertThat(spanData.getAttributes().getAttributeMap().get("MyStringAttributeKey" + (i + maxNumberOfAttributes))).isEqualTo(AttributeValue.longAttributeValue(i + maxNumberOfAttributes));
}
}
use of io.opencensus.trace.config.TraceParams in project instrumentation-java by census-instrumentation.
the class RecordEventsSpanImplTest method droppingNetworkEvents.
@Test
public void droppingNetworkEvents() {
final int maxNumberOfNetworkEvents = 8;
TraceParams traceParams = TraceParams.DEFAULT.toBuilder().setMaxNumberOfNetworkEvents(maxNumberOfNetworkEvents).build();
RecordEventsSpanImpl span = RecordEventsSpanImpl.startSpan(spanContext, SPAN_NAME, null, parentSpanId, false, traceParams, startEndHandler, timestampConverter, testClock);
NetworkEvent networkEvent = NetworkEvent.builder(NetworkEvent.Type.RECV, 1).setUncompressedMessageSize(3).build();
for (int i = 0; i < 2 * maxNumberOfNetworkEvents; i++) {
span.addNetworkEvent(networkEvent);
testClock.advanceTime(Duration.create(0, 100));
}
SpanData spanData = span.toSpanData();
assertThat(spanData.getNetworkEvents().getDroppedEventsCount()).isEqualTo(maxNumberOfNetworkEvents);
assertThat(spanData.getNetworkEvents().getEvents().size()).isEqualTo(maxNumberOfNetworkEvents);
for (int i = 0; i < maxNumberOfNetworkEvents; i++) {
assertThat(spanData.getNetworkEvents().getEvents().get(i).getTimestamp()).isEqualTo(timestamp.addNanos(100L * (maxNumberOfNetworkEvents + i)));
assertThat(spanData.getNetworkEvents().getEvents().get(i).getEvent()).isEqualTo(networkEvent);
}
span.end();
spanData = span.toSpanData();
assertThat(spanData.getNetworkEvents().getDroppedEventsCount()).isEqualTo(maxNumberOfNetworkEvents);
assertThat(spanData.getNetworkEvents().getEvents().size()).isEqualTo(maxNumberOfNetworkEvents);
for (int i = 0; i < maxNumberOfNetworkEvents; i++) {
assertThat(spanData.getNetworkEvents().getEvents().get(i).getTimestamp()).isEqualTo(timestamp.addNanos(100L * (maxNumberOfNetworkEvents + i)));
assertThat(spanData.getNetworkEvents().getEvents().get(i).getEvent()).isEqualTo(networkEvent);
}
}
Aggregations