Search in sources :

Example 1 with TraceParams

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());
}
Also used : TraceConfig(io.opencensus.trace.config.TraceConfig) TraceParams(io.opencensus.trace.config.TraceParams)

Example 2 with TraceParams

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);
    }
}
Also used : SpanData(io.opencensus.trace.export.SpanData) TraceParams(io.opencensus.trace.config.TraceParams) Link(io.opencensus.trace.Link) Test(org.junit.Test)

Example 3 with TraceParams

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));
    }
}
Also used : AttributeValue(io.opencensus.trace.AttributeValue) SpanData(io.opencensus.trace.export.SpanData) HashMap(java.util.HashMap) TraceParams(io.opencensus.trace.config.TraceParams) Test(org.junit.Test)

Example 4 with TraceParams

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));
    }
}
Also used : AttributeValue(io.opencensus.trace.AttributeValue) SpanData(io.opencensus.trace.export.SpanData) HashMap(java.util.HashMap) TraceParams(io.opencensus.trace.config.TraceParams) Test(org.junit.Test)

Example 5 with TraceParams

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);
    }
}
Also used : SpanData(io.opencensus.trace.export.SpanData) NetworkEvent(io.opencensus.trace.NetworkEvent) TraceParams(io.opencensus.trace.config.TraceParams) Test(org.junit.Test)

Aggregations

TraceParams (io.opencensus.trace.config.TraceParams)17 Test (org.junit.Test)9 SpanData (io.opencensus.trace.export.SpanData)5 TestHandler (io.opencensus.testing.export.TestHandler)3 TraceConfig (io.opencensus.trace.config.TraceConfig)3 SpanExporter (io.opencensus.trace.export.SpanExporter)3 Before (org.junit.Before)3 TraceConfig (io.opencensus.proto.trace.v1.TraceConfig)2 AttributeValue (io.opencensus.trace.AttributeValue)2 Span (io.opencensus.trace.Span)2 HashMap (java.util.HashMap)2 ByteString (com.google.protobuf.ByteString)1 Scope (io.opencensus.common.Scope)1 TimestampConverter (io.opencensus.implcore.internal.TimestampConverter)1 Node (io.opencensus.proto.agent.common.v1.Node)1 CurrentLibraryConfig (io.opencensus.proto.agent.trace.v1.CurrentLibraryConfig)1 ExportTraceServiceRequest (io.opencensus.proto.agent.trace.v1.ExportTraceServiceRequest)1 TraceServiceStub (io.opencensus.proto.agent.trace.v1.TraceServiceGrpc.TraceServiceStub)1 UpdatedLibraryConfig (io.opencensus.proto.agent.trace.v1.UpdatedLibraryConfig)1 ConstantSampler (io.opencensus.proto.trace.v1.ConstantSampler)1