Search in sources :

Example 16 with TraceParams

use of io.opencensus.trace.config.TraceParams in project instrumentation-java by census-instrumentation.

the class CensusSpringAspectTest method setup.

@Before
public void setup() {
    handler = new TestHandler();
    SpanExporter exporter = Tracing.getExportComponent().getSpanExporter();
    exporter.registerHandler("testing", handler);
    TraceParams params = Tracing.getTraceConfig().getActiveTraceParams().toBuilder().setSampler(Samplers.alwaysSample()).build();
    Tracing.getTraceConfig().updateActiveTraceParams(params);
}
Also used : SpanExporter(io.opencensus.trace.export.SpanExporter) TestHandler(io.opencensus.testing.export.TestHandler) TraceParams(io.opencensus.trace.config.TraceParams) Before(org.junit.Before)

Example 17 with TraceParams

use of io.opencensus.trace.config.TraceParams in project instrumentation-java by census-instrumentation.

the class RecordEventsSpanImplTest method droppingAnnotations.

@Test
public void droppingAnnotations() {
    final int maxNumberOfAnnotations = 8;
    TraceParams traceParams = TraceParams.DEFAULT.toBuilder().setMaxNumberOfAnnotations(maxNumberOfAnnotations).build();
    RecordEventsSpanImpl span = RecordEventsSpanImpl.startSpan(spanContext, SPAN_NAME, null, parentSpanId, false, traceParams, startEndHandler, timestampConverter, testClock);
    Annotation annotation = Annotation.fromDescription(ANNOTATION_DESCRIPTION);
    for (int i = 0; i < 2 * maxNumberOfAnnotations; i++) {
        span.addAnnotation(annotation);
        testClock.advanceTime(Duration.create(0, 100));
    }
    SpanData spanData = span.toSpanData();
    assertThat(spanData.getAnnotations().getDroppedEventsCount()).isEqualTo(maxNumberOfAnnotations);
    assertThat(spanData.getAnnotations().getEvents().size()).isEqualTo(maxNumberOfAnnotations);
    for (int i = 0; i < maxNumberOfAnnotations; i++) {
        assertThat(spanData.getAnnotations().getEvents().get(i).getTimestamp()).isEqualTo(timestamp.addNanos(100L * (maxNumberOfAnnotations + i)));
        assertThat(spanData.getAnnotations().getEvents().get(i).getEvent()).isEqualTo(annotation);
    }
    span.end();
    spanData = span.toSpanData();
    assertThat(spanData.getAnnotations().getDroppedEventsCount()).isEqualTo(maxNumberOfAnnotations);
    assertThat(spanData.getAnnotations().getEvents().size()).isEqualTo(maxNumberOfAnnotations);
    for (int i = 0; i < maxNumberOfAnnotations; i++) {
        assertThat(spanData.getAnnotations().getEvents().get(i).getTimestamp()).isEqualTo(timestamp.addNanos(100L * (maxNumberOfAnnotations + i)));
        assertThat(spanData.getAnnotations().getEvents().get(i).getEvent()).isEqualTo(annotation);
    }
}
Also used : SpanData(io.opencensus.trace.export.SpanData) TraceParams(io.opencensus.trace.config.TraceParams) Annotation(io.opencensus.trace.Annotation) 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