Search in sources :

Example 6 with SpanExporter

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

the class OtlpExporterIntegrationTest method testOtlpHttpTraceExport.

@ParameterizedTest
@ValueSource(strings = { "gzip", "none" })
void testOtlpHttpTraceExport(String compression) {
    SpanExporter otlpGrpcTraceExporter = OtlpHttpSpanExporter.builder().setEndpoint("http://" + collector.getHost() + ":" + collector.getMappedPort(COLLECTOR_OTLP_HTTP_PORT) + "/v1/traces").setCompression(compression).build();
    testTraceExport(otlpGrpcTraceExporter);
}
Also used : OtlpGrpcSpanExporter(io.opentelemetry.exporter.otlp.trace.OtlpGrpcSpanExporter) OtlpHttpSpanExporter(io.opentelemetry.exporter.otlp.http.trace.OtlpHttpSpanExporter) SpanExporter(io.opentelemetry.sdk.trace.export.SpanExporter) ValueSource(org.junit.jupiter.params.provider.ValueSource) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 7 with SpanExporter

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

the class AutoConfiguredOpenTelemetrySdkTest method builder_addSpanExporterCustomizer.

@Test
void builder_addSpanExporterCustomizer() {
    Mockito.lenient().when(spanExporter2.shutdown()).thenReturn(CompletableResultCode.ofSuccess());
    SdkTracerProvider sdkTracerProvider = builder.addSpanExporterCustomizer((previous, config) -> {
        assertThat(previous).isSameAs(SpanExporter.composite());
        return spanExporter1;
    }).addSpanExporterCustomizer((previous, config) -> {
        assertThat(previous).isSameAs(spanExporter1);
        return spanExporter2;
    }).build().getOpenTelemetrySdk().getSdkTracerProvider();
    assertThat(sdkTracerProvider).extracting("sharedState").extracting("activeSpanProcessor").extracting("worker").extracting("spanExporter").isEqualTo(spanExporter2);
}
Also used : ArgumentMatchers.any(org.mockito.ArgumentMatchers.any) Sampler(io.opentelemetry.sdk.trace.samplers.Sampler) BeforeEach(org.junit.jupiter.api.BeforeEach) LogProcessor(io.opentelemetry.sdk.logs.LogProcessor) SpanId(io.opentelemetry.api.trace.SpanId) W3CTraceContextPropagator(io.opentelemetry.api.trace.propagation.W3CTraceContextPropagator) OpenTelemetrySdk(io.opentelemetry.sdk.OpenTelemetrySdk) Resource(io.opentelemetry.sdk.resources.Resource) Mock(org.mockito.Mock) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) HashMap(java.util.HashMap) Supplier(java.util.function.Supplier) ResourceAttributes(io.opentelemetry.semconv.resource.attributes.ResourceAttributes) TextMapPropagator(io.opentelemetry.context.propagation.TextMapPropagator) MetricReader(io.opentelemetry.sdk.metrics.export.MetricReader) SimpleSpanProcessor(io.opentelemetry.sdk.trace.export.SimpleSpanProcessor) ExtendWith(org.junit.jupiter.api.extension.ExtendWith) Map(java.util.Map) ContextKey(io.opentelemetry.context.ContextKey) Context(io.opentelemetry.context.Context) IdGenerator(io.opentelemetry.sdk.trace.IdGenerator) MockitoExtension(org.mockito.junit.jupiter.MockitoExtension) Span(io.opentelemetry.api.trace.Span) SdkLogEmitterProvider(io.opentelemetry.sdk.logs.SdkLogEmitterProvider) OpenTelemetry(io.opentelemetry.api.OpenTelemetry) SpanExporter(io.opentelemetry.sdk.trace.export.SpanExporter) Mockito.when(org.mockito.Mockito.when) SdkTracerProvider(io.opentelemetry.sdk.trace.SdkTracerProvider) Mockito.verify(org.mockito.Mockito.verify) GlobalOpenTelemetry(io.opentelemetry.api.GlobalOpenTelemetry) TimeUnit(java.util.concurrent.TimeUnit) Test(org.junit.jupiter.api.Test) SdkMeterProvider(io.opentelemetry.sdk.metrics.SdkMeterProvider) Mockito(org.mockito.Mockito) List(java.util.List) InMemorySpanExporter(io.opentelemetry.sdk.testing.exporter.InMemorySpanExporter) AttributeKey.stringKey(io.opentelemetry.api.common.AttributeKey.stringKey) TextMapGetter(io.opentelemetry.context.propagation.TextMapGetter) MetricReaderFactory(io.opentelemetry.sdk.metrics.export.MetricReaderFactory) TraceId(io.opentelemetry.api.trace.TraceId) SpanData(io.opentelemetry.sdk.trace.data.SpanData) Collections(java.util.Collections) CompletableResultCode(io.opentelemetry.sdk.common.CompletableResultCode) SdkTracerProvider(io.opentelemetry.sdk.trace.SdkTracerProvider) Test(org.junit.jupiter.api.Test)

Example 8 with SpanExporter

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

the class SpanExporterConfiguration method configureOtlp.

// Visible for testing
static SpanExporter configureOtlp(ConfigProperties config, MeterProvider meterProvider) {
    String protocol = OtlpConfigUtil.getOtlpProtocol(DATA_TYPE_TRACES, config);
    if (protocol.equals(PROTOCOL_HTTP_PROTOBUF)) {
        ClasspathUtil.checkClassExists("io.opentelemetry.exporter.otlp.http.trace.OtlpHttpSpanExporter", "OTLP HTTP Trace Exporter", "opentelemetry-exporter-otlp-http-trace");
        OtlpHttpSpanExporterBuilder builder = OtlpHttpSpanExporter.builder();
        OtlpConfigUtil.configureOtlpExporterBuilder(DATA_TYPE_TRACES, config, builder::setEndpoint, builder::addHeader, builder::setCompression, builder::setTimeout, builder::setTrustedCertificates, retryPolicy -> RetryUtil.setRetryPolicyOnDelegate(builder, retryPolicy));
        builder.setMeterProvider(meterProvider);
        return builder.build();
    } else if (protocol.equals(PROTOCOL_GRPC)) {
        ClasspathUtil.checkClassExists("io.opentelemetry.exporter.otlp.trace.OtlpGrpcSpanExporter", "OTLP gRPC Trace Exporter", "opentelemetry-exporter-otlp");
        OtlpGrpcSpanExporterBuilder builder = OtlpGrpcSpanExporter.builder();
        OtlpConfigUtil.configureOtlpExporterBuilder(DATA_TYPE_TRACES, config, builder::setEndpoint, builder::addHeader, builder::setCompression, builder::setTimeout, builder::setTrustedCertificates, retryPolicy -> RetryUtil.setRetryPolicyOnDelegate(builder, retryPolicy));
        builder.setMeterProvider(meterProvider);
        return builder.build();
    } else {
        throw new ConfigurationException("Unsupported OTLP traces protocol: " + protocol);
    }
}
Also used : ConfigProperties(io.opentelemetry.sdk.autoconfigure.spi.ConfigProperties) BiFunction(java.util.function.BiFunction) OtlpHttpSpanExporter(io.opentelemetry.exporter.otlp.http.trace.OtlpHttpSpanExporter) Function(java.util.function.Function) PROTOCOL_GRPC(io.opentelemetry.sdk.autoconfigure.OtlpConfigUtil.PROTOCOL_GRPC) Collectors.toMap(java.util.stream.Collectors.toMap) PROTOCOL_HTTP_PROTOBUF(io.opentelemetry.sdk.autoconfigure.OtlpConfigUtil.PROTOCOL_HTTP_PROTOBUF) Duration(java.time.Duration) Map(java.util.Map) OtlpGrpcSpanExporterBuilder(io.opentelemetry.exporter.otlp.trace.OtlpGrpcSpanExporterBuilder) ZipkinSpanExporter(io.opentelemetry.exporter.zipkin.ZipkinSpanExporter) OtlpGrpcSpanExporter(io.opentelemetry.exporter.otlp.trace.OtlpGrpcSpanExporter) DATA_TYPE_TRACES(io.opentelemetry.sdk.autoconfigure.OtlpConfigUtil.DATA_TYPE_TRACES) JaegerGrpcSpanExporterBuilder(io.opentelemetry.exporter.jaeger.JaegerGrpcSpanExporterBuilder) ConfigurableSpanExporterProvider(io.opentelemetry.sdk.autoconfigure.spi.traces.ConfigurableSpanExporterProvider) SpanExporter(io.opentelemetry.sdk.trace.export.SpanExporter) Set(java.util.Set) ConfigurationException(io.opentelemetry.sdk.autoconfigure.spi.ConfigurationException) OtlpHttpSpanExporterBuilder(io.opentelemetry.exporter.otlp.http.trace.OtlpHttpSpanExporterBuilder) RetryUtil(io.opentelemetry.exporter.internal.retry.RetryUtil) LoggingSpanExporter(io.opentelemetry.exporter.logging.LoggingSpanExporter) ZipkinSpanExporterBuilder(io.opentelemetry.exporter.zipkin.ZipkinSpanExporterBuilder) JaegerGrpcSpanExporter(io.opentelemetry.exporter.jaeger.JaegerGrpcSpanExporter) MeterProvider(io.opentelemetry.api.metrics.MeterProvider) Collections(java.util.Collections) OtlpGrpcSpanExporterBuilder(io.opentelemetry.exporter.otlp.trace.OtlpGrpcSpanExporterBuilder) ConfigurationException(io.opentelemetry.sdk.autoconfigure.spi.ConfigurationException) OtlpHttpSpanExporterBuilder(io.opentelemetry.exporter.otlp.http.trace.OtlpHttpSpanExporterBuilder)

Example 9 with SpanExporter

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

the class SpanExporterConfiguration method configureSpanExporters.

// Visible for testing
static Map<String, SpanExporter> configureSpanExporters(ConfigProperties config, ClassLoader serviceClassLoader, MeterProvider meterProvider, BiFunction<? super SpanExporter, ConfigProperties, ? extends SpanExporter> spanExporterCustomizer) {
    Set<String> exporterNames = DefaultConfigProperties.getSet(config, "otel.traces.exporter");
    if (exporterNames.contains(EXPORTER_NONE)) {
        if (exporterNames.size() > 1) {
            throw new ConfigurationException("otel.traces.exporter contains " + EXPORTER_NONE + " along with other exporters");
        }
        SpanExporter noop = SpanExporter.composite();
        SpanExporter customized = spanExporterCustomizer.apply(noop, config);
        if (customized == noop) {
            return Collections.emptyMap();
        }
        return Collections.singletonMap(EXPORTER_NONE, customized);
    }
    if (exporterNames.isEmpty()) {
        exporterNames = Collections.singleton("otlp");
    }
    NamedSpiManager<SpanExporter> spiExportersManager = SpiUtil.loadConfigurable(ConfigurableSpanExporterProvider.class, ConfigurableSpanExporterProvider::getName, ConfigurableSpanExporterProvider::createExporter, config, serviceClassLoader);
    return exporterNames.stream().collect(toMap(Function.identity(), exporterName -> spanExporterCustomizer.apply(configureExporter(exporterName, config, spiExportersManager, meterProvider), config)));
}
Also used : ConfigProperties(io.opentelemetry.sdk.autoconfigure.spi.ConfigProperties) BiFunction(java.util.function.BiFunction) OtlpHttpSpanExporter(io.opentelemetry.exporter.otlp.http.trace.OtlpHttpSpanExporter) Function(java.util.function.Function) PROTOCOL_GRPC(io.opentelemetry.sdk.autoconfigure.OtlpConfigUtil.PROTOCOL_GRPC) Collectors.toMap(java.util.stream.Collectors.toMap) PROTOCOL_HTTP_PROTOBUF(io.opentelemetry.sdk.autoconfigure.OtlpConfigUtil.PROTOCOL_HTTP_PROTOBUF) Duration(java.time.Duration) Map(java.util.Map) OtlpGrpcSpanExporterBuilder(io.opentelemetry.exporter.otlp.trace.OtlpGrpcSpanExporterBuilder) ZipkinSpanExporter(io.opentelemetry.exporter.zipkin.ZipkinSpanExporter) OtlpGrpcSpanExporter(io.opentelemetry.exporter.otlp.trace.OtlpGrpcSpanExporter) DATA_TYPE_TRACES(io.opentelemetry.sdk.autoconfigure.OtlpConfigUtil.DATA_TYPE_TRACES) JaegerGrpcSpanExporterBuilder(io.opentelemetry.exporter.jaeger.JaegerGrpcSpanExporterBuilder) ConfigurableSpanExporterProvider(io.opentelemetry.sdk.autoconfigure.spi.traces.ConfigurableSpanExporterProvider) SpanExporter(io.opentelemetry.sdk.trace.export.SpanExporter) Set(java.util.Set) ConfigurationException(io.opentelemetry.sdk.autoconfigure.spi.ConfigurationException) OtlpHttpSpanExporterBuilder(io.opentelemetry.exporter.otlp.http.trace.OtlpHttpSpanExporterBuilder) RetryUtil(io.opentelemetry.exporter.internal.retry.RetryUtil) LoggingSpanExporter(io.opentelemetry.exporter.logging.LoggingSpanExporter) ZipkinSpanExporterBuilder(io.opentelemetry.exporter.zipkin.ZipkinSpanExporterBuilder) JaegerGrpcSpanExporter(io.opentelemetry.exporter.jaeger.JaegerGrpcSpanExporter) MeterProvider(io.opentelemetry.api.metrics.MeterProvider) Collections(java.util.Collections) ConfigurableSpanExporterProvider(io.opentelemetry.sdk.autoconfigure.spi.traces.ConfigurableSpanExporterProvider) OtlpHttpSpanExporter(io.opentelemetry.exporter.otlp.http.trace.OtlpHttpSpanExporter) ZipkinSpanExporter(io.opentelemetry.exporter.zipkin.ZipkinSpanExporter) OtlpGrpcSpanExporter(io.opentelemetry.exporter.otlp.trace.OtlpGrpcSpanExporter) SpanExporter(io.opentelemetry.sdk.trace.export.SpanExporter) LoggingSpanExporter(io.opentelemetry.exporter.logging.LoggingSpanExporter) JaegerGrpcSpanExporter(io.opentelemetry.exporter.jaeger.JaegerGrpcSpanExporter) ConfigurationException(io.opentelemetry.sdk.autoconfigure.spi.ConfigurationException)

Example 10 with SpanExporter

use of io.opentelemetry.sdk.trace.export.SpanExporter 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)

Aggregations

SpanExporter (io.opentelemetry.sdk.trace.export.SpanExporter)22 Test (org.junit.jupiter.api.Test)16 OtlpGrpcSpanExporter (io.opentelemetry.exporter.otlp.trace.OtlpGrpcSpanExporter)9 ConfigProperties (io.opentelemetry.sdk.autoconfigure.spi.ConfigProperties)9 HashMap (java.util.HashMap)9 LoggingSpanExporter (io.opentelemetry.exporter.logging.LoggingSpanExporter)7 ZipkinSpanExporter (io.opentelemetry.exporter.zipkin.ZipkinSpanExporter)7 SimpleSpanProcessor (io.opentelemetry.sdk.trace.export.SimpleSpanProcessor)6 Collections (java.util.Collections)6 Map (java.util.Map)6 MeterProvider (io.opentelemetry.api.metrics.MeterProvider)4 OtlpHttpSpanExporter (io.opentelemetry.exporter.otlp.http.trace.OtlpHttpSpanExporter)4 ConfigurationException (io.opentelemetry.sdk.autoconfigure.spi.ConfigurationException)4 Assertions.assertThat (org.assertj.core.api.Assertions.assertThat)4 ImmutableMap (com.google.common.collect.ImmutableMap)2 GlobalOpenTelemetry (io.opentelemetry.api.GlobalOpenTelemetry)2 OpenTelemetry (io.opentelemetry.api.OpenTelemetry)2 AttributeKey.stringKey (io.opentelemetry.api.common.AttributeKey.stringKey)2 Span (io.opentelemetry.api.trace.Span)2 SpanId (io.opentelemetry.api.trace.SpanId)2