Search in sources :

Example 1 with SpanProcessor

use of io.opentelemetry.sdk.trace.SpanProcessor in project opentelemetry-java by open-telemetry.

the class SimpleSpanProcessorTest method onEndSync_OnlySampled_SampledSpan.

@Test
void onEndSync_OnlySampled_SampledSpan() {
    when(readableSpan.getSpanContext()).thenReturn(SAMPLED_SPAN_CONTEXT);
    when(readableSpan.toSpanData()).thenReturn(TestUtils.makeBasicSpan()).thenThrow(new RuntimeException());
    SpanProcessor simpleSpanProcessor = SimpleSpanProcessor.create(spanExporter);
    simpleSpanProcessor.onEnd(readableSpan);
    verify(spanExporter).export(Collections.singletonList(TestUtils.makeBasicSpan()));
}
Also used : SpanProcessor(io.opentelemetry.sdk.trace.SpanProcessor) Test(org.junit.jupiter.api.Test)

Example 2 with SpanProcessor

use of io.opentelemetry.sdk.trace.SpanProcessor in project opentelemetry-java by open-telemetry.

the class TracerProviderConfiguration method configureSpanProcessors.

static List<SpanProcessor> configureSpanProcessors(ConfigProperties config, Map<String, SpanExporter> exportersByName, MeterProvider meterProvider) {
    Map<String, SpanExporter> exportersByNameCopy = new HashMap<>(exportersByName);
    List<SpanProcessor> spanProcessors = new ArrayList<>();
    SpanExporter exporter = exportersByNameCopy.remove("logging");
    if (exporter != null) {
        spanProcessors.add(SimpleSpanProcessor.create(exporter));
    }
    if (!exportersByNameCopy.isEmpty()) {
        SpanExporter compositeSpanExporter = SpanExporter.composite(exportersByNameCopy.values());
        spanProcessors.add(configureBatchSpanProcessor(config, compositeSpanExporter, meterProvider));
    }
    return spanProcessors;
}
Also used : BatchSpanProcessor(io.opentelemetry.sdk.trace.export.BatchSpanProcessor) SimpleSpanProcessor(io.opentelemetry.sdk.trace.export.SimpleSpanProcessor) SpanProcessor(io.opentelemetry.sdk.trace.SpanProcessor) SpanExporter(io.opentelemetry.sdk.trace.export.SpanExporter) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList)

Example 3 with SpanProcessor

use of io.opentelemetry.sdk.trace.SpanProcessor in project opentelemetry-java by open-telemetry.

the class SimpleSpanProcessorTest method onEndSync_OnlySampled_NotSampledSpan.

@Test
void onEndSync_OnlySampled_NotSampledSpan() {
    when(readableSpan.getSpanContext()).thenReturn(NOT_SAMPLED_SPAN_CONTEXT);
    when(readableSpan.toSpanData()).thenReturn(TestUtils.makeBasicSpan()).thenThrow(new RuntimeException());
    SpanProcessor simpleSpanProcessor = SimpleSpanProcessor.create(spanExporter);
    simpleSpanProcessor.onEnd(readableSpan);
    verifyNoInteractions(spanExporter);
}
Also used : SpanProcessor(io.opentelemetry.sdk.trace.SpanProcessor) Test(org.junit.jupiter.api.Test)

Example 4 with SpanProcessor

use of io.opentelemetry.sdk.trace.SpanProcessor in project honeycomb-opentelemetry-java by honeycombio.

the class OpenTelemetryConfigurationTest method testConfiguration_tracerSettings.

@Test
@SuppressWarnings("unchecked")
public void testConfiguration_tracerSettings() {
    Sampler sampler = new DeterministicTraceSampler(5);
    OpenTelemetry openTelemetry = OpenTelemetryConfiguration.builder().setSampler(sampler).setApiKey("foobar").setDataset("dataset").addResourceAttribute("str", "str").addResourceAttribute("bool", true).addResourceAttribute("int", 123).addResourceAttribute("str-array", "str1", "str2", "str3").build();
    TracerProvider provider = openTelemetry.getTracerProvider();
    try {
        Method m = provider.getClass().getDeclaredMethod("unobfuscate");
        m.setAccessible(true);
        SdkTracerProvider sdkProvider = (SdkTracerProvider) m.invoke(provider, (Object[]) null);
        // verify sampler
        Sampler s = sdkProvider.getSampler();
        Assertions.assertEquals(sampler, s);
        Field providerField = pluckField(sdkProvider.getClass(), "sharedState");
        Object sharedState = providerField.get(sdkProvider);
        Field resourceField = pluckField(sharedState.getClass(), "resource");
        Resource r = (Resource) resourceField.get(sharedState);
        Attributes attrs = r.getAttributes();
        // verify resource attributes
        Assertions.assertEquals(DistroMetadata.VERSION_VALUE, attrs.get(AttributeKey.stringKey(DistroMetadata.VERSION_FIELD)));
        Assertions.assertEquals(DistroMetadata.RUNTIME_VERSION_VALUE, attrs.get(AttributeKey.stringKey(DistroMetadata.RUNTIME_VERSION_FIELD)));
        Assertions.assertEquals("str", attrs.get(AttributeKey.stringKey("str")));
        Assertions.assertEquals(true, attrs.get(AttributeKey.booleanKey("bool")));
        Assertions.assertEquals(123, attrs.get(AttributeKey.longKey("int")));
        Assertions.assertEquals(Arrays.asList("str1", "str2", "str3"), attrs.get(AttributeKey.stringArrayKey("str-array")));
        Field procesorField = pluckField(sharedState.getClass(), "activeSpanProcessor");
        Object sp = procesorField.get(sharedState);
        Field allSpanProcessors = pluckField(sp.getClass(), "spanProcessorsAll");
        List<SpanProcessor> processors = (List<SpanProcessor>) allSpanProcessors.get(sp);
        // verify configured span processors
        Assertions.assertInstanceOf(BaggageSpanProcessor.class, processors.get(0));
        Assertions.assertInstanceOf(BatchSpanProcessor.class, processors.get(1));
    } catch (Exception e) {
        Assertions.fail(e);
    }
}
Also used : Resource(io.opentelemetry.sdk.resources.Resource) Attributes(io.opentelemetry.api.common.Attributes) OpenTelemetry(io.opentelemetry.api.OpenTelemetry) GlobalOpenTelemetry(io.opentelemetry.api.GlobalOpenTelemetry) Method(java.lang.reflect.Method) SdkTracerProvider(io.opentelemetry.sdk.trace.SdkTracerProvider) SdkTracerProvider(io.opentelemetry.sdk.trace.SdkTracerProvider) TracerProvider(io.opentelemetry.api.trace.TracerProvider) Field(java.lang.reflect.Field) BatchSpanProcessor(io.opentelemetry.sdk.trace.export.BatchSpanProcessor) BaggageSpanProcessor(io.honeycomb.opentelemetry.sdk.trace.spanprocessors.BaggageSpanProcessor) SpanProcessor(io.opentelemetry.sdk.trace.SpanProcessor) Sampler(io.opentelemetry.sdk.trace.samplers.Sampler) DeterministicTraceSampler(io.honeycomb.opentelemetry.sdk.trace.samplers.DeterministicTraceSampler) List(java.util.List) DeterministicTraceSampler(io.honeycomb.opentelemetry.sdk.trace.samplers.DeterministicTraceSampler) Test(org.junit.jupiter.api.Test)

Example 5 with SpanProcessor

use of io.opentelemetry.sdk.trace.SpanProcessor in project incubator-eventmesh by apache.

the class ZipkinTraceService method init.

@Override
public void init() {
    // zipkin's config
    eventMeshZipkinIP = ZipkinConfiguration.getEventMeshZipkinIP();
    eventMeshZipkinPort = ZipkinConfiguration.getEventMeshZipkinPort();
    // exporter's config
    eventMeshTraceExportInterval = ExporterConfiguration.getEventMeshTraceExportInterval();
    eventMeshTraceExportTimeout = ExporterConfiguration.getEventMeshTraceExportTimeout();
    eventMeshTraceMaxExportSize = ExporterConfiguration.getEventMeshTraceMaxExportSize();
    eventMeshTraceMaxQueueSize = ExporterConfiguration.getEventMeshTraceMaxQueueSize();
    String httpUrl = String.format("http://%s:%s", eventMeshZipkinIP, eventMeshZipkinPort);
    ZipkinSpanExporter zipkinExporter = ZipkinSpanExporter.builder().setEndpoint(httpUrl + ENDPOINT_V2_SPANS).build();
    SpanProcessor spanProcessor = BatchSpanProcessor.builder(zipkinExporter).setScheduleDelay(eventMeshTraceExportInterval, TimeUnit.SECONDS).setExporterTimeout(eventMeshTraceExportTimeout, TimeUnit.SECONDS).setMaxExportBatchSize(eventMeshTraceMaxExportSize).setMaxQueueSize(eventMeshTraceMaxQueueSize).build();
    // set the trace service's name
    Resource serviceNameResource = Resource.create(Attributes.of(stringKey("service.name"), serviceName));
    sdkTracerProvider = SdkTracerProvider.builder().addSpanProcessor(spanProcessor).setResource(Resource.getDefault().merge(serviceNameResource)).build();
    openTelemetry = OpenTelemetrySdk.builder().setPropagators(ContextPropagators.create(W3CTraceContextPropagator.getInstance())).setTracerProvider(sdkTracerProvider).build();
    Runtime.getRuntime().addShutdownHook(new Thread(sdkTracerProvider::close));
}
Also used : BatchSpanProcessor(io.opentelemetry.sdk.trace.export.BatchSpanProcessor) SpanProcessor(io.opentelemetry.sdk.trace.SpanProcessor) Resource(io.opentelemetry.sdk.resources.Resource) ZipkinSpanExporter(io.opentelemetry.exporter.zipkin.ZipkinSpanExporter)

Aggregations

SpanProcessor (io.opentelemetry.sdk.trace.SpanProcessor)5 BatchSpanProcessor (io.opentelemetry.sdk.trace.export.BatchSpanProcessor)3 Test (org.junit.jupiter.api.Test)3 Resource (io.opentelemetry.sdk.resources.Resource)2 DeterministicTraceSampler (io.honeycomb.opentelemetry.sdk.trace.samplers.DeterministicTraceSampler)1 BaggageSpanProcessor (io.honeycomb.opentelemetry.sdk.trace.spanprocessors.BaggageSpanProcessor)1 GlobalOpenTelemetry (io.opentelemetry.api.GlobalOpenTelemetry)1 OpenTelemetry (io.opentelemetry.api.OpenTelemetry)1 Attributes (io.opentelemetry.api.common.Attributes)1 TracerProvider (io.opentelemetry.api.trace.TracerProvider)1 ZipkinSpanExporter (io.opentelemetry.exporter.zipkin.ZipkinSpanExporter)1 SdkTracerProvider (io.opentelemetry.sdk.trace.SdkTracerProvider)1 SimpleSpanProcessor (io.opentelemetry.sdk.trace.export.SimpleSpanProcessor)1 SpanExporter (io.opentelemetry.sdk.trace.export.SpanExporter)1 Sampler (io.opentelemetry.sdk.trace.samplers.Sampler)1 Field (java.lang.reflect.Field)1 Method (java.lang.reflect.Method)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 List (java.util.List)1